mirror of
https://github.com/isar/libmdbx.git
synced 2024-12-30 03:04:12 +08:00
mdbx-cmake: sync cmake-compiler module with erthink upstream.
Change-Id: I4eeeb2bc2800bfb44c915533843c59438733ff4b
This commit is contained in:
parent
ed6863851e
commit
d752de0ee0
@ -17,12 +17,12 @@ cmake_minimum_required(VERSION 3.8.2)
|
|||||||
cmake_policy(PUSH)
|
cmake_policy(PUSH)
|
||||||
cmake_policy(VERSION 3.8.2)
|
cmake_policy(VERSION 3.8.2)
|
||||||
|
|
||||||
if (CMAKE_VERSION MATCHES ".*MSVC.*")
|
if(CMAKE_VERSION MATCHES ".*MSVC.*" AND CMAKE_VERSION VERSION_LESS 3.16)
|
||||||
message(FATAL_ERROR "CMake from MSVC kit is unfit! "
|
message(FATAL_ERROR "CMake from MSVC kit is unfit! "
|
||||||
"Please use the original CMake from https://cmake.org/download/")
|
"Please use MSVC2019 with modern CMake the original CMake from https://cmake.org/download/")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED))
|
if(NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED))
|
||||||
message(FATAL_ERROR "This module required C or C++ to be enabled")
|
message(FATAL_ERROR "This module required C or C++ to be enabled")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -214,6 +214,15 @@ else()
|
|||||||
check_compiler_flag("-Ominimal" CC_HAS_OMINIMAL)
|
check_compiler_flag("-Ominimal" CC_HAS_OMINIMAL)
|
||||||
check_compiler_flag("-ffunction-sections -fdata-sections" CC_HAS_SECTIONS)
|
check_compiler_flag("-ffunction-sections -fdata-sections" CC_HAS_SECTIONS)
|
||||||
check_compiler_flag("-ffast-math" CC_HAS_FASTMATH)
|
check_compiler_flag("-ffast-math" CC_HAS_FASTMATH)
|
||||||
|
check_compiler_flag("-Wno-attributes" CC_HAS_WNO_ATTRIBUTES)
|
||||||
|
|
||||||
|
# Check for an omp support
|
||||||
|
set(CMAKE_REQUIRED_FLAGS "-fopenmp -Werror")
|
||||||
|
check_cxx_source_compiles("int main(void) {
|
||||||
|
#pragma omp parallel
|
||||||
|
return 0;
|
||||||
|
}" HAVE_OPENMP)
|
||||||
|
set(CMAKE_REQUIRED_FLAGS "")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Check for LTO support by GCC
|
# Check for LTO support by GCC
|
||||||
@ -276,7 +285,7 @@ if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG})
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# check for LTO by MSVC
|
# check for LTO by MSVC
|
||||||
if(MSVC)
|
if(MSVC AND NOT CMAKE_COMPILER_IS_CLANG)
|
||||||
if(NOT MSVC_VERSION LESS 1600)
|
if(NOT MSVC_VERSION LESS 1600)
|
||||||
set(MSVC_LTO_AVAILABLE TRUE)
|
set(MSVC_LTO_AVAILABLE TRUE)
|
||||||
message(STATUS "Link-Time Optimization by MSVC is available")
|
message(STATUS "Link-Time Optimization by MSVC is available")
|
||||||
@ -290,25 +299,37 @@ endif()
|
|||||||
if(CMAKE_COMPILER_IS_CLANG)
|
if(CMAKE_COMPILER_IS_CLANG)
|
||||||
if(NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 3.5)
|
if(NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 3.5)
|
||||||
execute_process(COMMAND ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} -print-search-dirs
|
execute_process(COMMAND ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} -print-search-dirs
|
||||||
OUTPUT_VARIABLE clang_search_dirs)
|
OUTPUT_VARIABLE clang_search_dirs RESULT_VARIABLE clang_probe_result ERROR_QUIET)
|
||||||
|
|
||||||
unset(clang_bindir)
|
unset(clang_bindir)
|
||||||
unset(clang_libdir)
|
unset(clang_libdir)
|
||||||
string(REGEX MATCH "^(.*programs: =)([^:]*:)*([^:]+/llvm[-.0-9]+/bin[^:]*)(:[^:]*)*(\n.+)$" clang_bindir_valid ${clang_search_dirs})
|
if(clang_probe_result EQUAL 0)
|
||||||
if(clang_bindir_valid)
|
string(REGEX MATCH "^(.*programs: =)([^:]*:)*([^:]+/llvm[-.0-9]+/bin[^:]*)(:[^:]*)*(\n.+)$" clang_bindir_valid ${clang_search_dirs})
|
||||||
string(REGEX REPLACE "^(.*programs: =)([^:]*:)*([^:]+/llvm[-.0-9]+/bin[^:]*)(:[^:]*)*(\n.+)$" "\\3" clang_bindir ${clang_search_dirs})
|
if(clang_bindir_valid)
|
||||||
get_filename_component(clang_libdir "${clang_bindir}/../lib" REALPATH)
|
string(REGEX REPLACE "^(.*programs: =)([^:]*:)*([^:]+/llvm[-.0-9]+/bin[^:]*)(:[^:]*)*(\n.+)$" "\\3" clang_bindir ${clang_search_dirs})
|
||||||
if(clang_libdir)
|
if(CMAKE_SYSTEM_NAME STREQUAL "WINDOWS")
|
||||||
message(STATUS "Found CLANG/LLVM directories: ${clang_bindir}, ${clang_libdir}")
|
set(clang_libdir ${clang_bindir})
|
||||||
|
else()
|
||||||
|
get_filename_component(clang_libdir "${clang_bindir}/../lib" REALPATH)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
get_filename_component(clang_bindir ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} DIRECTORY)
|
||||||
|
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
|
||||||
|
set(clang_libdir ${clang_bindir})
|
||||||
|
else()
|
||||||
|
get_filename_component(clang_libdir "${clang_bindir}/../lib" REALPATH)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT (clang_bindir AND clang_libdir))
|
if(clang_bindir AND clang_libdir)
|
||||||
|
message(STATUS "Found CLANG/LLVM directories: ${clang_bindir}, ${clang_libdir}")
|
||||||
|
else()
|
||||||
message(STATUS "Could NOT find CLANG/LLVM directories (bin and/or lib).")
|
message(STATUS "Could NOT find CLANG/LLVM directories (bin and/or lib).")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT CMAKE_CLANG_LD AND clang_bindir)
|
if(NOT CMAKE_CLANG_LD AND clang_bindir)
|
||||||
find_program(CMAKE_CLANG_LD NAMES llvm-link link llvm-ld ld PATHS ${clang_bindir} NO_DEFAULT_PATH)
|
find_program(CMAKE_CLANG_LD NAMES lld-link ld.lld ld64.lld lld-link llvm-link link llvm-ld ld PATHS ${clang_bindir} NO_DEFAULT_PATH)
|
||||||
endif()
|
endif()
|
||||||
if(NOT CMAKE_CLANG_AR AND clang_bindir)
|
if(NOT CMAKE_CLANG_AR AND clang_bindir)
|
||||||
find_program(CMAKE_CLANG_AR NAMES llvm-ar ar PATHS ${clang_bindir} NO_DEFAULT_PATH)
|
find_program(CMAKE_CLANG_AR NAMES llvm-ar ar PATHS ${clang_bindir} NO_DEFAULT_PATH)
|
||||||
@ -346,19 +367,19 @@ if(CMAKE_COMPILER_IS_CLANG)
|
|||||||
unset(clang_search_dirs)
|
unset(clang_search_dirs)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if((CLANG_LTO_PLUGIN AND CMAKE_LD_GOLD) AND
|
if((CLANG_LTO_PLUGIN AND CMAKE_LD_GOLD) OR
|
||||||
(CMAKE_CLANG_LD AND CMAKE_CLANG_AR AND CMAKE_CLANG_NM AND CMAKE_CLANG_RANLIB))
|
(CMAKE_CLANG_LD AND CMAKE_CLANG_AR AND CMAKE_CLANG_NM AND CMAKE_CLANG_RANLIB))
|
||||||
set(CLANG_LTO_AVAILABLE TRUE)
|
set(CLANG_LTO_AVAILABLE TRUE)
|
||||||
message(STATUS "Link-Time Optimization by CLANG/LLVM is available")
|
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)
|
elseif(CMAKE_TOOLCHAIN_FILE AND NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 7.0)
|
||||||
set(CLANG_LTO_AVAILABLE TRUE)
|
set(CLANG_LTO_AVAILABLE TRUE)
|
||||||
if (NOT CMAKE_CLANG_AR)
|
if(NOT CMAKE_CLANG_AR)
|
||||||
set(CMAKE_CLANG_AR ${CMAKE_AR})
|
set(CMAKE_CLANG_AR ${CMAKE_AR})
|
||||||
endif()
|
endif()
|
||||||
if (NOT CMAKE_CLANG_NM)
|
if(NOT CMAKE_CLANG_NM)
|
||||||
set(CMAKE_CLANG_NM ${CMAKE_NM})
|
set(CMAKE_CLANG_NM ${CMAKE_NM})
|
||||||
endif()
|
endif()
|
||||||
if (NOT CMAKE_CLANG_RANLIB)
|
if(NOT CMAKE_CLANG_RANLIB)
|
||||||
set(CMAKE_CLANG_RANLIB ${CMAKE_RANLIB})
|
set(CMAKE_CLANG_RANLIB ${CMAKE_RANLIB})
|
||||||
endif()
|
endif()
|
||||||
message(STATUS "Assume Link-Time Optimization by CLANG/LLVM is available via ${CMAKE_TOOLCHAIN_FILE}")
|
message(STATUS "Assume Link-Time Optimization by CLANG/LLVM is available via ${CMAKE_TOOLCHAIN_FILE}")
|
||||||
@ -437,6 +458,12 @@ macro(setup_compile_flags)
|
|||||||
add_compile_flags("CXX" "-fcxx-exceptions -frtti")
|
add_compile_flags("CXX" "-fcxx-exceptions -frtti")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(CC_HAS_WNO_ATTRIBUTES AND CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG}
|
||||||
|
AND CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 9)
|
||||||
|
# GCC < 9.x generates false-positive warnings for optimization attributes
|
||||||
|
add_compile_flags("C;CXX" "-Wno-attributes")
|
||||||
|
endif()
|
||||||
|
|
||||||
# In C a global variable without a storage specifier (static/extern) and
|
# In C a global variable without a storage specifier (static/extern) and
|
||||||
# without an initialiser is called a ’tentative definition’. The
|
# without an initialiser is called a ’tentative definition’. The
|
||||||
# language permits multiple tentative definitions in the single
|
# language permits multiple tentative definitions in the single
|
||||||
@ -482,7 +509,7 @@ macro(setup_compile_flags)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
if (MSVC_VERSION LESS 1900)
|
if(MSVC_VERSION LESS 1900)
|
||||||
message(FATAL_ERROR "At least \"Microsoft C/C++ Compiler\" version 19.0.24234.1 (Visual Studio 2015 Update 3) is required.")
|
message(FATAL_ERROR "At least \"Microsoft C/C++ Compiler\" version 19.0.24234.1 (Visual Studio 2015 Update 3) is required.")
|
||||||
endif()
|
endif()
|
||||||
add_compile_flags("CXX" "/Zc:__cplusplus")
|
add_compile_flags("CXX" "/Zc:__cplusplus")
|
||||||
@ -514,11 +541,11 @@ macro(setup_compile_flags)
|
|||||||
if(MSVC)
|
if(MSVC)
|
||||||
add_compile_flags("C;CXX" "/WX")
|
add_compile_flags("C;CXX" "/WX")
|
||||||
elseif(CMAKE_COMPILER_IS_CLANG)
|
elseif(CMAKE_COMPILER_IS_CLANG)
|
||||||
if (NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 6)
|
if(NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 6)
|
||||||
add_compile_flags("C;CXX" "-Werror")
|
add_compile_flags("C;CXX" "-Werror")
|
||||||
endif()
|
endif()
|
||||||
elseif(CMAKE_COMPILER_IS_GNUCC)
|
elseif(CMAKE_COMPILER_IS_GNUCC)
|
||||||
if (NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 6)
|
if(NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 6)
|
||||||
add_compile_flags("C;CXX" "-Werror")
|
add_compile_flags("C;CXX" "-Werror")
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
@ -526,7 +553,7 @@ macro(setup_compile_flags)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ENABLE_ASAN)
|
if(ENABLE_ASAN)
|
||||||
add_compile_flags("C;CXX" -fsanitize=address)
|
add_compile_flags("C;CXX" -fsanitize=address)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -564,7 +591,7 @@ macro(setup_compile_flags)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(MSVC AND LTO_ENABLED)
|
if(MSVC AND NOT CMAKE_COMPILER_IS_CLANG AND LTO_ENABLED)
|
||||||
add_compile_flags("C;CXX" "/GL")
|
add_compile_flags("C;CXX" "/GL")
|
||||||
foreach(linkmode IN ITEMS EXE SHARED STATIC MODULE)
|
foreach(linkmode IN ITEMS EXE SHARED STATIC MODULE)
|
||||||
set(${linkmode}_LINKER_FLAGS "${${linkmode}_LINKER_FLAGS} /LTCG")
|
set(${linkmode}_LINKER_FLAGS "${${linkmode}_LINKER_FLAGS} /LTCG")
|
||||||
@ -617,9 +644,11 @@ macro(setup_compile_flags)
|
|||||||
set(CLANG_LTO_FLAG "-flto=thin")
|
set(CLANG_LTO_FLAG "-flto=thin")
|
||||||
endif()
|
endif()
|
||||||
add_compile_flags("C;CXX" ${CLANG_LTO_FLAG})
|
add_compile_flags("C;CXX" ${CLANG_LTO_FLAG})
|
||||||
set(EXE_LINKER_FLAGS "${EXE_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm -fwhole-program")
|
if(NOT MSVC)
|
||||||
set(SHARED_LINKER_FLAGS "${SHARED_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm")
|
set(EXE_LINKER_FLAGS "${EXE_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm -fwhole-program")
|
||||||
set(MODULE_LINKER_FLAGS "${MODULE_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm")
|
set(SHARED_LINKER_FLAGS "${SHARED_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm")
|
||||||
|
set(MODULE_LINKER_FLAGS "${MODULE_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# LY: push C/CXX flags into the cache
|
# LY: push C/CXX flags into the cache
|
||||||
@ -640,11 +669,11 @@ endmacro(setup_compile_flags)
|
|||||||
# determine library for for std::filesystem
|
# determine library for for std::filesystem
|
||||||
set(LIBCXX_FILESYSTEM "")
|
set(LIBCXX_FILESYSTEM "")
|
||||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
|
||||||
set(LIBCXX_FILESYSTEM "stdc++fs")
|
set(LIBCXX_FILESYSTEM "stdc++fs")
|
||||||
endif()
|
endif()
|
||||||
elseif (CMAKE_COMPILER_IS_CLANG)
|
elseif(CMAKE_COMPILER_IS_CLANG)
|
||||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
|
||||||
set(LIBCXX_FILESYSTEM "c++experimental")
|
set(LIBCXX_FILESYSTEM "c++experimental")
|
||||||
else()
|
else()
|
||||||
set(LIBCXX_FILESYSTEM "stdc++fs")
|
set(LIBCXX_FILESYSTEM "stdc++fs")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user