mirror of
https://github.com/isar/libmdbx.git
synced 2024-12-29 09:28:49 +08:00
mdbx-cmake: update/sync compiler module (clang LTO, exceptions for MSVC).
Change-Id: Ic132d4cb4095a141436599047b80f8a0b8ac4f6b
This commit is contained in:
parent
e008f3132d
commit
cda94ee61d
@ -64,11 +64,11 @@ endmacro(check_compiler_flag)
|
||||
|
||||
# We support building with Clang and gcc. First check
|
||||
# what we're using for build.
|
||||
if(CMAKE_C_COMPILER_LOADED AND CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
if(CMAKE_C_COMPILER_LOADED AND CMAKE_C_COMPILER_ID MATCHES ".*[Cc][Ll][Aa][Nn][Gg].*")
|
||||
set(CMAKE_COMPILER_IS_CLANG ON)
|
||||
set(CMAKE_COMPILER_IS_GNUCC OFF)
|
||||
endif()
|
||||
if(CMAKE_CXX_COMPILER_LOADED AND CMAKE_CXx_COMPILER_ID STREQUAL "Clang")
|
||||
if(CMAKE_CXX_COMPILER_LOADED AND CMAKE_CXX_COMPILER_ID MATCHES ".*[Cc][Ll][Aa][Nn][Gg].*")
|
||||
set(CMAKE_COMPILER_IS_CLANG ON)
|
||||
set(CMAKE_COMPILER_IS_GNUCXX OFF)
|
||||
endif()
|
||||
@ -161,37 +161,47 @@ if(NOT DEFINED IOS)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED CMAKE_TARGET_BITNESS)
|
||||
if (CMAKE_SIZEOF_VOID_P LESS 4)
|
||||
set(CMAKE_TARGET_BITNESS 16)
|
||||
elseif (CMAKE_SIZEOF_VOID_P LESS 8)
|
||||
set(CMAKE_TARGET_BITNESS 32)
|
||||
else()
|
||||
set(CMAKE_TARGET_BITNESS 64)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_ELBRUSC OR CMAKE_SYSTEM_PROCESSOR MATCHES "e2k.*|E2K.*|elbrus.*|ELBRUS.*")
|
||||
set(E2K TRUE)
|
||||
set(CMAKE_SYSTEM_ARCH "Elbrus")
|
||||
elseif((MSVC64 OR MINGW64) AND CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
elseif((MSVC64 OR MINGW64) AND CMAKE_TARGET_BITNESS EQUAL 64)
|
||||
set(X86_64 TRUE)
|
||||
set(CMAKE_SYSTEM_ARCH "x86_64")
|
||||
elseif(MINGW OR (MSVC AND NOT CMAKE_CROSSCOMPILING))
|
||||
set(X86_32 TRUE)
|
||||
set(CMAKE_SYSTEM_ARCH "x86")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*" AND CMAKE_TARGET_BITNESS EQUAL 64)
|
||||
set(X86_64 TRUE)
|
||||
set(CMAKE_SYSTEM_ARCH "x86_64")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*")
|
||||
set(X86_32 TRUE)
|
||||
set(CMAKE_SYSTEM_ARCH "x86")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*|ARM64.*)" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*|ARM64.*)" AND CMAKE_TARGET_BITNESS EQUAL 64)
|
||||
set(AARCH64 TRUE)
|
||||
set(CMAKE_SYSTEM_ARCH "ARM64")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)")
|
||||
set(ARM32 TRUE)
|
||||
set(CMAKE_SYSTEM_ARCH "ARM")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le.*" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le.*" AND CMAKE_TARGET_BITNESS EQUAL 64)
|
||||
set(PPC64LE TRUE)
|
||||
set(CMAKE_SYSTEM_ARCH "PPC64LE")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64.*" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64.*" AND CMAKE_TARGET_BITNESS EQUAL 64)
|
||||
set(PPC64 TRUE)
|
||||
set(CMAKE_SYSTEM_ARCH "PPC64")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc).*")
|
||||
set(PPC32 TRUE)
|
||||
set(CMAKE_SYSTEM_ARCH "PPC")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(mips|MIPS)64.*" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(mips|MIPS)64.*" AND CMAKE_TARGET_BITNESS EQUAL 64)
|
||||
set(MIPS64 TRUE)
|
||||
set(CMAKE_SYSTEM_ARCH "MIPS64")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(mips|MIPS).*")
|
||||
@ -228,10 +238,17 @@ else()
|
||||
|
||||
# Check for an omp support
|
||||
set(CMAKE_REQUIRED_FLAGS "-fopenmp -Werror")
|
||||
check_c_source_compiles("int main(void) {
|
||||
#pragma omp parallel
|
||||
return 0;
|
||||
}" HAVE_OPENMP)
|
||||
if(CMAKE_CXX_COMPILER_LOADED)
|
||||
check_cxx_source_compiles("int main(void) {
|
||||
#pragma omp parallel
|
||||
return 0;
|
||||
}" HAVE_OPENMP)
|
||||
else()
|
||||
check_c_source_compiles("int main(void) {
|
||||
#pragma omp parallel
|
||||
return 0;
|
||||
}" HAVE_OPENMP)
|
||||
endif()
|
||||
set(CMAKE_REQUIRED_FLAGS "")
|
||||
endif()
|
||||
|
||||
@ -352,7 +369,7 @@ if(CMAKE_COMPILER_IS_CLANG)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_CLANG_LD AND clang_bindirs)
|
||||
find_program(CMAKE_CLANG_LD NAMES lld-link ld.lld ld64.lld lld-link llvm-link link llvm-ld ld PATHS ${clang_bindirs} NO_DEFAULT_PATH)
|
||||
find_program(CMAKE_CLANG_LD NAMES lld-link ld.lld "ld${CMAKE_TARGET_BITNESS}.lld" lld llvm-link llvm-ld PATHS ${clang_bindirs} NO_DEFAULT_PATH)
|
||||
endif()
|
||||
if(NOT CMAKE_CLANG_AR AND clang_bindirs)
|
||||
find_program(CMAKE_CLANG_AR NAMES llvm-ar ar PATHS ${clang_bindirs} NO_DEFAULT_PATH)
|
||||
@ -371,14 +388,21 @@ if(CMAKE_COMPILER_IS_CLANG)
|
||||
if(NOT CLANG_LTO_PLUGIN AND clang_libdirs)
|
||||
find_file(CLANG_LTO_PLUGIN ${clang_lto_plugin_name} PATHS ${clang_libdirs} NO_DEFAULT_PATH)
|
||||
endif()
|
||||
|
||||
if(CLANG_LTO_PLUGIN)
|
||||
message(STATUS "Found CLANG/LLVM's plugin for LTO: ${CLANG_LTO_PLUGIN}")
|
||||
else()
|
||||
message(STATUS "Could NOT find CLANG/LLVM's plugin (${clang_lto_plugin_name}) for LTO.")
|
||||
endif()
|
||||
|
||||
if(CMAKE_CLANG_LD AND CMAKE_CLANG_AR AND CMAKE_CLANG_NM AND CMAKE_CLANG_RANLIB)
|
||||
message(STATUS "Found CLANG/LLVM's binutils for LTO: ${CMAKE_CLANG_AR}, ${CMAKE_CLANG_RANLIB}")
|
||||
if(CMAKE_CLANG_LD)
|
||||
message(STATUS "Found CLANG/LLVM's linker for LTO: ${CMAKE_CLANG_LD}")
|
||||
else()
|
||||
message(STATUS "Could NOT find CLANG/LLVM's linker (lld, llvm-ld, llvm-link) for LTO.")
|
||||
endif()
|
||||
|
||||
if(CMAKE_CLANG_AR AND CMAKE_CLANG_RANLIB AND CMAKE_CLANG_NM)
|
||||
message(STATUS "Found CLANG/LLVM's binutils for LTO: ${CMAKE_CLANG_AR}, ${CMAKE_CLANG_RANLIB}, ${CMAKE_CLANG_NM}")
|
||||
else()
|
||||
message(STATUS "Could NOT find CLANG/LLVM's binutils (ar, ranlib, nm) for LTO.")
|
||||
endif()
|
||||
@ -390,12 +414,19 @@ if(CMAKE_COMPILER_IS_CLANG)
|
||||
unset(clang_search_dirs)
|
||||
endif()
|
||||
|
||||
if((CLANG_LTO_PLUGIN AND CMAKE_LD_GOLD) OR
|
||||
(CMAKE_CLANG_LD AND CMAKE_CLANG_AR AND CMAKE_CLANG_NM AND CMAKE_CLANG_RANLIB))
|
||||
if (CMAKE_CLANG_AR AND CMAKE_CLANG_NM AND CMAKE_CLANG_RANLIB
|
||||
AND ((CLANG_LTO_PLUGIN AND CMAKE_LD_GOLD)
|
||||
OR (CMAKE_CLANG_LD
|
||||
AND NOT (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux"
|
||||
AND CMAKE_SYSTEM_NAME STREQUAL "Linux"))
|
||||
OR APPLE))
|
||||
set(CLANG_LTO_AVAILABLE TRUE)
|
||||
message(STATUS "Link-Time Optimization by CLANG/LLVM is available")
|
||||
elseif(CMAKE_TOOLCHAIN_FILE AND NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 7.0)
|
||||
set(CLANG_LTO_AVAILABLE TRUE)
|
||||
if(NOT CMAKE_CLANG_LD)
|
||||
set(CMAKE_CLANG_LD ${CMAKE_LINKER})
|
||||
endif()
|
||||
if(NOT CMAKE_CLANG_AR)
|
||||
set(CMAKE_CLANG_AR ${CMAKE_AR})
|
||||
endif()
|
||||
@ -454,9 +485,6 @@ endif()
|
||||
macro(setup_compile_flags)
|
||||
# save initial C/CXX flags
|
||||
if(NOT INITIAL_CMAKE_FLAGS_SAVED)
|
||||
if(MSVC)
|
||||
string(REGEX REPLACE "^(.*)(/EHsc)( *)(.*)$" "\\1/EHs\\3\\4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
endif()
|
||||
set(INITIAL_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} CACHE STRING "Initial CMake's flags" FORCE)
|
||||
set(INITIAL_CMAKE_C_FLAGS ${CMAKE_C_FLAGS} CACHE STRING "Initial CMake's flags" FORCE)
|
||||
set(INITIAL_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} CACHE STRING "Initial CMake's flags" FORCE)
|
||||
@ -480,6 +508,22 @@ macro(setup_compile_flags)
|
||||
if(CC_HAS_FCXX_EXCEPTIONS)
|
||||
add_compile_flags("CXX" "-fcxx-exceptions -frtti")
|
||||
endif()
|
||||
if(MSVC)
|
||||
# checks for /EHa or /clr options exists,
|
||||
# i.e. is enabled structured async WinNT exceptions
|
||||
string(REGEX MATCH "^(.* )*[-/]EHc*a( .*)*$" msvc_async_eh_enabled "${CXX_FLAGS}" "${C_FLAGS}")
|
||||
string(REGEX MATCH "^(.* )*[-/]clr( .*)*$" msvc_clr_enabled "${CXX_FLAGS}" "${C_FLAGS}")
|
||||
# remote any /EH? options
|
||||
string(REGEX REPLACE "( *[-/]-*EH[csa]+ *)+" "" CXX_FLAGS "${CXX_FLAGS}")
|
||||
string(REGEX REPLACE "( *[-/]-*EH[csa]+ *)+" "" C_FLAGS "${C_FLAGS}")
|
||||
if (msvc_clr_enabled STREQUAL "")
|
||||
if(NOT msvc_async_eh_enabled STREQUAL "")
|
||||
add_compile_flags("C;CXX" "/EHa")
|
||||
else()
|
||||
add_compile_flags("C;CXX" "/EHsc")
|
||||
endif()
|
||||
endif()
|
||||
endif(MSVC)
|
||||
|
||||
if(CC_HAS_WNO_ATTRIBUTES AND CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG}
|
||||
AND CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 9)
|
||||
|
Loading…
x
Reference in New Issue
Block a user