From: Matthias Maier Date: Thu, 6 Feb 2020 16:59:44 +0000 (-0600) Subject: CMake: Simplify configuration logic X-Git-Tag: v9.2.0-rc1~549^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=88663305eada1ca0d2502f0ff946e08acc95e503;p=dealii.git CMake: Simplify configuration logic --- diff --git a/cmake/checks/check_02_compiler_features.cmake b/cmake/checks/check_02_compiler_features.cmake index ce3e92cebb..60820cfa80 100644 --- a/cmake/checks/check_02_compiler_features.cmake +++ b/cmake/checks/check_02_compiler_features.cmake @@ -448,73 +448,56 @@ RESET_CMAKE_REQUIRED() # ICC also emits a warning but passes for unsupported linkers # unless we turn diagnostic warnings into errors. # -# Wolfgang Bangerth, Matthias Maier, Daniel Arndt, 2015, 2018 +# We also test linker support with "-shared -fPIC". This catches an +# incompatibility where LLD refuses to produce a shared object from an +# object file compiled by the Intel Compiler: # -IF(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Wno-unused-command-line-argument") - ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "Intel") - ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-diag-error warn") - ENDIF() - ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror") - ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-fuse-ld=lld") - CHECK_CXX_SOURCE_COMPILES( - " - int main() { return 0; } - " - DEAL_II_COMPILER_LLD_LINKS_EXEC) - RESET_CMAKE_REQUIRED() - -# It is observed that LLD refuses to produce a shared object from an object -# file compiled by Intel Compiler, throwing error message saying # ld.lld: error: can't create dynamic relocation R_X86_64_64 against symbol: # __gxx_personality_v0 in readonly segment; recompile object files with -fPIC # or pass '-Wl,-z,notext' to allow text relocations in the output +# # even if we actually had -fPIC option present. If we add -Wl,-z,notext, it # will link, but the produced libdeal_II.so is faulty and will crash randomly. # -# Therefore here adds a check on whether LLD could produce a .so from the -# object file compiled by the specified C++ compiler. -# -# - Binrui Dong, 2019 +# Wolfgang Bangerth, Matthias Maier, Daniel Arndt, Binrui Dong, 2015, 2018-2020 +# + +IF(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang") ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Wno-unused-command-line-argument") ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "Intel") ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-diag-error warn") ENDIF() ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror") - ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-fuse-ld=lld") ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-shared") ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-fPIC") + + # + # Check for ld.lld and ld.gold support: + # + ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-fuse-ld=lld") CHECK_CXX_SOURCE_COMPILES( " #include void foo() { std::cout << \"Hello, world!\" << std::endl; } " - DEAL_II_COMPILER_LLD_LINKS_SO) - RESET_CMAKE_REQUIRED() + DEAL_II_COMPILER_HAS_FUSE_LD_LLD) - IF(DEAL_II_COMPILER_LLD_LINKS_EXEC AND DEAL_II_COMPILER_LLD_LINKS_SO) - set(DEAL_II_COMPILER_HAS_FUSE_LD_LLD 1) - ENDIF() - - IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Wno-unused-command-line-argument") - ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "Intel") - ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-diag-error warn") - ENDIF() - ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror") + STRIP_FLAG(CMAKE_REQUIRED_FLAGS "-fuse-ld=lld") ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-fuse-ld=gold") CHECK_CXX_SOURCE_COMPILES( " - int main() { return 0; } + #include + void foo() { std::cout << \"Hello, world!\" << std::endl; } " DEAL_II_COMPILER_HAS_FUSE_LD_GOLD) - RESET_CMAKE_REQUIRED() IF(DEAL_II_COMPILER_HAS_FUSE_LD_LLD) ADD_FLAGS(DEAL_II_LINKER_FLAGS "-fuse-ld=lld") ELSEIF(DEAL_II_COMPILER_HAS_FUSE_LD_GOLD) ADD_FLAGS(DEAL_II_LINKER_FLAGS "-fuse-ld=gold") ENDIF() + + RESET_CMAKE_REQUIRED() ENDIF()