mirror of
https://github.com/isar/libmdbx.git
synced 2024-12-30 03:14:14 +08:00
mdbx-cmake: sync cmake-compiler module with erthink upstream.
Change-Id: I4eeeb2bc2800bfb44c915533843c59438733ff4b
This commit is contained in:
parent
ed6863851e
commit
d752de0ee0
@ -17,9 +17,9 @@ cmake_minimum_required(VERSION 3.8.2)
|
||||
cmake_policy(PUSH)
|
||||
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! "
|
||||
"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()
|
||||
|
||||
if(NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED))
|
||||
@ -214,6 +214,15 @@ else()
|
||||
check_compiler_flag("-Ominimal" CC_HAS_OMINIMAL)
|
||||
check_compiler_flag("-ffunction-sections -fdata-sections" CC_HAS_SECTIONS)
|
||||
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()
|
||||
|
||||
# Check for LTO support by GCC
|
||||
@ -276,7 +285,7 @@ if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG})
|
||||
endif()
|
||||
|
||||
# check for LTO by MSVC
|
||||
if(MSVC)
|
||||
if(MSVC AND NOT CMAKE_COMPILER_IS_CLANG)
|
||||
if(NOT MSVC_VERSION LESS 1600)
|
||||
set(MSVC_LTO_AVAILABLE TRUE)
|
||||
message(STATUS "Link-Time Optimization by MSVC is available")
|
||||
@ -290,25 +299,37 @@ endif()
|
||||
if(CMAKE_COMPILER_IS_CLANG)
|
||||
if(NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 3.5)
|
||||
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_libdir)
|
||||
if(clang_probe_result EQUAL 0)
|
||||
string(REGEX MATCH "^(.*programs: =)([^:]*:)*([^:]+/llvm[-.0-9]+/bin[^:]*)(:[^:]*)*(\n.+)$" clang_bindir_valid ${clang_search_dirs})
|
||||
if(clang_bindir_valid)
|
||||
string(REGEX REPLACE "^(.*programs: =)([^:]*:)*([^:]+/llvm[-.0-9]+/bin[^:]*)(:[^:]*)*(\n.+)$" "\\3" clang_bindir ${clang_search_dirs})
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "WINDOWS")
|
||||
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)
|
||||
if(clang_libdir)
|
||||
message(STATUS "Found CLANG/LLVM directories: ${clang_bindir}, ${clang_libdir}")
|
||||
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).")
|
||||
endif()
|
||||
|
||||
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()
|
||||
if(NOT CMAKE_CLANG_AR AND clang_bindir)
|
||||
find_program(CMAKE_CLANG_AR NAMES llvm-ar ar PATHS ${clang_bindir} NO_DEFAULT_PATH)
|
||||
@ -346,7 +367,7 @@ if(CMAKE_COMPILER_IS_CLANG)
|
||||
unset(clang_search_dirs)
|
||||
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))
|
||||
set(CLANG_LTO_AVAILABLE TRUE)
|
||||
message(STATUS "Link-Time Optimization by CLANG/LLVM is available")
|
||||
@ -437,6 +458,12 @@ macro(setup_compile_flags)
|
||||
add_compile_flags("CXX" "-fcxx-exceptions -frtti")
|
||||
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
|
||||
# without an initialiser is called a ’tentative definition’. The
|
||||
# language permits multiple tentative definitions in the single
|
||||
@ -564,7 +591,7 @@ macro(setup_compile_flags)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MSVC AND LTO_ENABLED)
|
||||
if(MSVC AND NOT CMAKE_COMPILER_IS_CLANG AND LTO_ENABLED)
|
||||
add_compile_flags("C;CXX" "/GL")
|
||||
foreach(linkmode IN ITEMS EXE SHARED STATIC MODULE)
|
||||
set(${linkmode}_LINKER_FLAGS "${${linkmode}_LINKER_FLAGS} /LTCG")
|
||||
@ -617,10 +644,12 @@ macro(setup_compile_flags)
|
||||
set(CLANG_LTO_FLAG "-flto=thin")
|
||||
endif()
|
||||
add_compile_flags("C;CXX" ${CLANG_LTO_FLAG})
|
||||
if(NOT MSVC)
|
||||
set(EXE_LINKER_FLAGS "${EXE_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm -fwhole-program")
|
||||
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()
|
||||
|
||||
# LY: push C/CXX flags into the cache
|
||||
set(CMAKE_CXX_FLAGS ${CXX_FLAGS} CACHE STRING "Flags used by the C++ compiler during all build types" FORCE)
|
||||
|
Loading…
x
Reference in New Issue
Block a user