[cmake] Partially deduplicate `{llvm,compiler_rt}_check_linker_flag` for runtime...
authorJohn Ericson <John.Ericson@Obsidian.Systems>
Sat, 22 Jan 2022 00:21:19 +0000 (19:21 -0500)
committerJohn Ericson <John.Ericson@Obsidian.Systems>
Sat, 29 Jan 2022 06:07:24 +0000 (06:07 +0000)
commit7017e6c9cfd2de3122ce9528f338a97d61e96373
tree3a84f0278c3759ad68677236d84d16e30027a013
parent184f94a8a89c702b2fc317fd12852d4991693de8
[cmake] Partially deduplicate `{llvm,compiler_rt}_check_linker_flag` for runtime libs and llvm

We previously had a few varied definitions of this floating around.

I had tried to make the one installed with LLVM handle all the cases, and then made the others use it, but this ran into issues with `HandleOutOfTreeLLVM` not working for compiler-rt, and also `CMAKE_EXE_LINKER_FLAGS` not working right without `CMP0056` set to the new behavior.

 My compromise solution is this:

 - No not completely deduplicate: the runtime libs will instead use a version that still exists as part of the internal and not installed common shared CMake utilities. This avoids `HandleOutOfTreeLLVM` or a workaround for compiler-rt.

- Continue to use `CMAKE_REQUIRED_FLAGS`, which effects compilation and linking. Maybe this is unnecessary, but it's safer to leave that as a future change. Also means we can avoid `CMP0056` for now, to try out later, which is good incrementality too.

- Call it `llvm_check_compiler_linker_flag` since it, in fact is about both per its implementation (before and after this patch), so there is no name collision.

In the future, we might still enable CMP0056 and make compiler-rt work with HandleOutOfTreeLLVM, which case we delete `llvm_check_compiler_flag` and go back to the old way (as these are, in fact, linking related flags), but that I leave for someone else as future work.

The original issue was reported to me in https://reviews.llvm.org/D116521#3248117 as
D116521 made clang and LLVM use the common cmake utils.

Reviewed By: sebastian-ne, phosek, #libunwind, #libc, #libc_abi, ldionne

Differential Revision: https://reviews.llvm.org/D117537
cmake/Modules/CheckLinkerFlag.cmake [deleted file]
cmake/Modules/LLVMCheckCompilerLinkerFlag.cmake [new file with mode: 0644]
compiler-rt/cmake/config-ix.cmake
libcxx/cmake/config-ix.cmake
libunwind/cmake/config-ix.cmake
llvm/cmake/modules/LLVMCheckLinkerFlag.cmake
runtimes/CMakeLists.txt