From 1515c2cd16911e1297c57fb69d4bb4921a40b8ab Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 20 Jun 2024 21:56:56 +1100 Subject: [PATCH] [cmake] switch to CMake's native check_compiler_flag, delete LLVMCheckCompilerLinkerFlag.cmake now that CMake baseline has moved past 3.19; see https://cmake.org/cmake/help/latest/module/CheckCompilerFlag.html --- .../Modules/LLVMCheckCompilerLinkerFlag.cmake | 35 ------------------- compiler-rt/cmake/config-ix.cmake | 18 +++++----- libcxx/cmake/config-ix.cmake | 6 ++-- libunwind/cmake/config-ix.cmake | 8 ++--- offload/CMakeLists.txt | 4 +-- openmp/runtime/cmake/config-ix.cmake | 18 +++++----- runtimes/CMakeLists.txt | 6 ++-- 7 files changed, 30 insertions(+), 65 deletions(-) delete mode 100644 cmake/Modules/LLVMCheckCompilerLinkerFlag.cmake diff --git a/cmake/Modules/LLVMCheckCompilerLinkerFlag.cmake b/cmake/Modules/LLVMCheckCompilerLinkerFlag.cmake deleted file mode 100644 index f61ec0585f9a45..00000000000000 --- a/cmake/Modules/LLVMCheckCompilerLinkerFlag.cmake +++ /dev/null @@ -1,35 +0,0 @@ -include(CMakePushCheckState) - -include(CheckCompilerFlag OPTIONAL) - -if(NOT COMMAND check_compiler_flag) - include(CheckCCompilerFlag) - include(CheckCXXCompilerFlag) -endif() - -function(llvm_check_compiler_linker_flag lang flag out_var) - # If testing a flag with check_c_compiler_flag, it gets added to the compile - # command only, but not to the linker command in that test. If the flag - # is vital for linking to succeed, the test would fail even if it would - # have succeeded if it was included on both commands. - # - # Therefore, try adding the flag to CMAKE_REQUIRED_FLAGS, which gets - # added to both compiling and linking commands in the tests. - - cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}") - if(COMMAND check_compiler_flag) - check_compiler_flag("${lang}" "" ${out_var}) - else() - # Until the minimum CMAKE version is 3.19 - # cmake builtin compatible, except we assume lang is C or CXX - if("${lang}" STREQUAL "C") - check_c_compiler_flag("" ${out_var}) - elseif("${lang}" STREQUAL "CXX") - check_cxx_compiler_flag("" ${out_var}) - else() - message(FATAL_ERROR "\"${lang}\" is not C or CXX") - endif() - endif() - cmake_pop_check_state() -endfunction() diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index 75e4d3677703ad..e90e95438c0690 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -5,7 +5,7 @@ include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) include(CheckIncludeFiles) include(CheckLibraryExists) -include(LLVMCheckCompilerLinkerFlag) +include(CheckCompilerFlag) include(CheckSymbolExists) include(TestBigEndian) @@ -15,8 +15,8 @@ include(TestBigEndian) # in tree version of runtimes, we'd be linking against the just-built # libunwind (and the compiler implicit -lunwind wouldn't succeed as the newly # built libunwind isn't installed yet). For those cases, it'd be good to -# link with --uwnindlib=none. Check if that option works. -llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_NONE_FLAG) +# link with --unwindlib=none. Check if that option works. +check_compiler_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_NONE_FLAG) check_library_exists(c fopen "" COMPILER_RT_HAS_LIBC) if (COMPILER_RT_USE_BUILTINS_LIBRARY) @@ -190,12 +190,12 @@ check_library_exists(c++ __cxa_throw "" COMPILER_RT_HAS_LIBCXX) check_library_exists(stdc++ __cxa_throw "" COMPILER_RT_HAS_LIBSTDCXX) # Linker flags. -llvm_check_compiler_linker_flag(C "-Wl,-z,text" COMPILER_RT_HAS_Z_TEXT) -llvm_check_compiler_linker_flag(C "-fuse-ld=lld" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG) +check_compiler_flag(C "-Wl,-z,text" COMPILER_RT_HAS_Z_TEXT) +check_compiler_flag(C "-fuse-ld=lld" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG) if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD) set(VERS_COMPAT_OPTION "-Wl,-z,gnu-version-script-compat") - llvm_check_compiler_linker_flag(C "${VERS_COMPAT_OPTION}" COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT) + check_compiler_flag(C "${VERS_COMPAT_OPTION}" COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT) endif() set(DUMMY_VERS ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/dummy.vers) @@ -206,10 +206,10 @@ if(COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT) # -z gnu-version-script-compat. string(APPEND VERS_OPTION " ${VERS_COMPAT_OPTION}") endif() -llvm_check_compiler_linker_flag(C "${VERS_OPTION}" COMPILER_RT_HAS_VERSION_SCRIPT) +check_compiler_flag(C "${VERS_OPTION}" COMPILER_RT_HAS_VERSION_SCRIPT) if(ANDROID) - llvm_check_compiler_linker_flag(C "-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL) + check_compiler_flag(C "-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL) check_library_exists(log __android_log_write "" COMPILER_RT_HAS_LIBLOG) endif() @@ -481,7 +481,7 @@ if(APPLE) -lc++ -lc++abi) - llvm_check_compiler_linker_flag(C "-fapplication-extension" COMPILER_RT_HAS_APP_EXTENSION) + check_compiler_flag(C "-fapplication-extension" COMPILER_RT_HAS_APP_EXTENSION) if(COMPILER_RT_HAS_APP_EXTENSION) list(APPEND DARWIN_COMMON_LINK_FLAGS "-fapplication-extension") endif() diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake index 7406fba482e69d..a214c17dacdbb5 100644 --- a/libcxx/cmake/config-ix.cmake +++ b/libcxx/cmake/config-ix.cmake @@ -1,7 +1,7 @@ include(CMakePushCheckState) include(CheckLibraryExists) include(CheckSymbolExists) -include(LLVMCheckCompilerLinkerFlag) +include(CheckCompilerFlag) include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) include(CheckCSourceCompiles) @@ -12,8 +12,8 @@ include(CheckCSourceCompiles) # LIBCXXABI_USE_LLVM_UNWINDER set, we'd be linking against the just-built # libunwind (and the compiler implicit -lunwind wouldn't succeed as the newly # built libunwind isn't installed yet). For those cases, it'd be good to -# link with --uwnindlib=none. Check if that option works. -llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG) +# link with --unwindlib=none. Check if that option works. +check_compiler_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG) if (NOT LIBCXX_USE_COMPILER_RT) if(WIN32 AND NOT MINGW) diff --git a/libunwind/cmake/config-ix.cmake b/libunwind/cmake/config-ix.cmake index 126c872f0d4895..77bdd5eb5aaf88 100644 --- a/libunwind/cmake/config-ix.cmake +++ b/libunwind/cmake/config-ix.cmake @@ -2,14 +2,14 @@ include(CMakePushCheckState) include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) include(CheckLibraryExists) -include(LLVMCheckCompilerLinkerFlag) +include(CheckCompilerFlag) include(CheckSymbolExists) include(CheckCSourceCompiles) # The compiler driver may be implicitly trying to link against libunwind, which # might not work if libunwind doesn't exist yet. Try to check if # --unwindlib=none is supported, and use that if possible. -llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG) +check_compiler_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG) if (HAIKU) check_library_exists(root fopen "" LIBUNWIND_HAS_ROOT_LIB) @@ -35,11 +35,11 @@ endif() # required for the link to go through. We remove sanitizers from the # configuration checks to avoid spurious link errors. -llvm_check_compiler_linker_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG) +check_compiler_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG) if (CXX_SUPPORTS_NOSTDLIBXX_FLAG) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++") else() - llvm_check_compiler_linker_flag(C "-nodefaultlibs" C_SUPPORTS_NODEFAULTLIBS_FLAG) + check_compiler_flag(C "-nodefaultlibs" C_SUPPORTS_NODEFAULTLIBS_FLAG) if (C_SUPPORTS_NODEFAULTLIBS_FLAG) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs") endif() diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt index ead2aed414ffe7..800a34ccb194a5 100644 --- a/offload/CMakeLists.txt +++ b/offload/CMakeLists.txt @@ -294,9 +294,9 @@ endif() if(OPENMP_STANDALONE_BUILD OR TARGET omp) # Check LIBOMP_HAVE_VERSION_SCRIPT_FLAG - include(LLVMCheckCompilerLinkerFlag) + include(CheckCompilerFlag) if(NOT APPLE) - llvm_check_compiler_linker_flag(C "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/../openmp/runtime/src/exports_test_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG) + check_compiler_flag(C "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/../openmp/runtime/src/exports_test_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG) endif() endif() diff --git a/openmp/runtime/cmake/config-ix.cmake b/openmp/runtime/cmake/config-ix.cmake index 337fe2e5996486..ad389e76208ec8 100644 --- a/openmp/runtime/cmake/config-ix.cmake +++ b/openmp/runtime/cmake/config-ix.cmake @@ -8,6 +8,7 @@ #//===----------------------------------------------------------------------===// # +include(CheckCompilerFlag) include(CheckCCompilerFlag) include(CheckCSourceCompiles) include(CheckCXXSourceCompiles) @@ -17,7 +18,6 @@ include(CheckLibraryExists) include(CheckIncludeFiles) include(CheckSymbolExists) include(LibompCheckFortranFlag) -include(LLVMCheckCompilerLinkerFlag) # Check for versioned symbols function(libomp_check_version_symbols retval) @@ -128,13 +128,13 @@ check_symbol_exists(_aligned_malloc "malloc.h" LIBOMP_HAVE__ALIGNED_MALLOC) # Check linker flags if(WIN32) - llvm_check_compiler_linker_flag(C /SAFESEH LIBOMP_HAVE_SAFESEH_FLAG) + check_compiler_flag(C /SAFESEH LIBOMP_HAVE_SAFESEH_FLAG) elseif(NOT APPLE) - llvm_check_compiler_linker_flag(C -Wl,-x LIBOMP_HAVE_X_FLAG) - llvm_check_compiler_linker_flag(C -Wl,--as-needed LIBOMP_HAVE_AS_NEEDED_FLAG) - llvm_check_compiler_linker_flag(C "-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_test_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG) - llvm_check_compiler_linker_flag(C -static-libgcc LIBOMP_HAVE_STATIC_LIBGCC_FLAG) - llvm_check_compiler_linker_flag(C -Wl,-z,noexecstack LIBOMP_HAVE_Z_NOEXECSTACK_FLAG) + check_compiler_flag(C -Wl,-x LIBOMP_HAVE_X_FLAG) + check_compiler_flag(C -Wl,--as-needed LIBOMP_HAVE_AS_NEEDED_FLAG) + check_compiler_flag(C "-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_test_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG) + check_compiler_flag(C -static-libgcc LIBOMP_HAVE_STATIC_LIBGCC_FLAG) + check_compiler_flag(C -Wl,-z,noexecstack LIBOMP_HAVE_Z_NOEXECSTACK_FLAG) endif() # Check Intel(R) C Compiler specific flags @@ -145,8 +145,8 @@ if(CMAKE_C_COMPILER_ID STREQUAL "Intel" OR CMAKE_C_COMPILER_ID STREQUAL "IntelLL check_cxx_compiler_flag(-Qoption,cpp,--extended_float_types LIBOMP_HAVE_EXTENDED_FLOAT_TYPES_FLAG) check_cxx_compiler_flag(-falign-stack=maintain-16-byte LIBOMP_HAVE_FALIGN_STACK_FLAG) check_cxx_compiler_flag("-opt-streaming-stores never" LIBOMP_HAVE_OPT_STREAMING_STORES_FLAG) - llvm_check_compiler_linker_flag(C -static-intel LIBOMP_HAVE_STATIC_INTEL_FLAG) - llvm_check_compiler_linker_flag(C -no-intel-extensions LIBOMP_HAVE_NO_INTEL_EXTENSIONS_FLAG) + check_compiler_flag(C -static-intel LIBOMP_HAVE_STATIC_INTEL_FLAG) + check_compiler_flag(C -no-intel-extensions LIBOMP_HAVE_NO_INTEL_EXTENSIONS_FLAG) check_library_exists(irc_pic _intel_fast_memcpy "" LIBOMP_HAVE_IRC_PIC_LIBRARY) endif() diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt index 24f48511695915..da7650ce65da7b 100644 --- a/runtimes/CMakeLists.txt +++ b/runtimes/CMakeLists.txt @@ -79,7 +79,7 @@ set(LLVM_CMAKE_DIR ${LLVM_MAIN_SRC_DIR}/cmake/modules) set(LLVM_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../llvm) include(CheckLibraryExists) -include(LLVMCheckCompilerLinkerFlag) +include(CheckCompilerFlag) include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) @@ -114,7 +114,7 @@ filter_prefixed("${CMAKE_ASM_IMPLICIT_INCLUDE_DIRECTORIES}" ${LLVM_BINARY_DIR} C # Currently, we counteract this issue by adding -fno-sanitize=all flag in # the project specific code within */cmake/config-ix.cmake files but that's # brittle. We should ideally move this to runtimes/CMakeLists.txt. -llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG) +check_compiler_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG) if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG) set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --unwindlib=none") @@ -143,7 +143,7 @@ endif() # Check for -nostdlib++ first; if there's no C++ standard library yet, # all check_cxx_compiler_flag commands will fail until we add -nostdlib++ # (or -nodefaultlibs). -llvm_check_compiler_linker_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG) +check_compiler_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG) if (CXX_SUPPORTS_NOSTDLIBXX_FLAG) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++") endif()