Trying to build executables in try_compile leads to issues because we
might not be able to link executables for the target we're trying to
build the runtimes for. For example, when trying to build libc++ as a
static archive for some embedded targets, it might not make sense to
try and link a conventional executable for that target inside try_compile.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
For many tests, it makes sense to just do the static library test - that is if they are limited to something that is compile time only. For link time tests, this doesn't work (e.g. testing if librt is needed). Perhaps we should make this conditional on NOT BUILD_SHARED_LIBS? This would be the default behaviour with LLVM, but still would let you opt out were you to build a shared library.
FYI I've been looking into this recently and the direction I'm thinking about is providing custom functions for checking flags, for example runtime_check_c_compiler_flag, runtime_check_cxx_compiler_flag and runtime_check_linker_compiler_flag, where only the first two would set CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY but the last one would need a different solution like using -nostarfiles -nodefaultlibs together with a custom source file.