diff options
author | Petr Hosek <phosek@google.com> | 2023-02-22 17:32:07 +0000 |
---|---|---|
committer | Petr Hosek <phosek@google.com> | 2023-02-22 17:32:07 +0000 |
commit | 24d144571dbffc6993d13fb7ca781248eed024de (patch) | |
tree | 85bbc61aaa94f8c7654711dad841a0eb5be26570 /cmake | |
parent | 944f429b210d0d94171dc5df3068d4f1e8fb5d80 (diff) | |
download | llvm-24d144571dbffc6993d13fb7ca781248eed024de.tar.gz |
Revert "[CMake] Unify llvm_check_linker_flag and llvm_check_compiler_linker_flag"
This reverts commit efae3174f09560353fb0f3d528bcbffe060d5438 since
it broke the standalone Flang build.
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/Modules/LLVMCheckCompilerLinkerFlag.cmake | 35 | ||||
-rw-r--r-- | cmake/Modules/LLVMCheckLinkerFlag.cmake | 28 |
2 files changed, 35 insertions, 28 deletions
diff --git a/cmake/Modules/LLVMCheckCompilerLinkerFlag.cmake b/cmake/Modules/LLVMCheckCompilerLinkerFlag.cmake new file mode 100644 index 000000000000..f61ec0585f9a --- /dev/null +++ b/cmake/Modules/LLVMCheckCompilerLinkerFlag.cmake @@ -0,0 +1,35 @@ +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/cmake/Modules/LLVMCheckLinkerFlag.cmake b/cmake/Modules/LLVMCheckLinkerFlag.cmake deleted file mode 100644 index e09bbc66f2d2..000000000000 --- a/cmake/Modules/LLVMCheckLinkerFlag.cmake +++ /dev/null @@ -1,28 +0,0 @@ -include(CheckLinkerFlag OPTIONAL) - -if (COMMAND check_linker_flag) - macro(llvm_check_linker_flag) - check_linker_flag(${ARGN}) - endmacro() -else() - # Until the minimum CMAKE version is 3.18 - - include(CheckCXXCompilerFlag) - - # cmake builtin compatible, except we assume lang is C or CXX - function(llvm_check_linker_flag lang flag out_var) - cmake_policy(PUSH) - cmake_policy(SET CMP0056 NEW) - set(_CMAKE_EXE_LINKER_FLAGS_SAVE ${CMAKE_EXE_LINKER_FLAGS}) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}") - 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() - set(CMAKE_EXE_LINKER_FLAGS ${_CMAKE_EXE_LINKER_FLAGS_SAVE}) - cmake_policy(POP) - endfunction() -endif() |