Previously it wasn't possible to configure a standalone compiler-rt
build if the LLVMConfig.cmake file isn't present in a shipped
toolchain.
This patch adds a fallback behaviour for when LLVMConfig.cmake is not
available in the toolchain being used for configure. The fallback
behaviour mocks out the bare minimum required to make a configure
succeed when the host is Darwin. Support for other platforms could
be added in future patches.
The new code path is taken either in one of the following cases:
- llvm-config is not available.
- llvm-config is available but it provides an invalid path for the CMake files.
The motivation here is to be able to generate the compiler-rt lit test
suites for an arbitrary LLVM toolchain and then run the tests against
it.
The invocation to do this looks something like.
CC=/path/to/cc \ CXX=/path/to/c++ \ cmake \ -G Ninja \ -DLLVM_CONFIG_PATH=/path/to/llvm-config \ -DCOMPILER_RT_INCLUDE_TESTS=ON \ /path/to/llvm-project/compiler-rt # Note we don't compile compiler-rt in this workflow. bin/llvm-lit -v test/path/to/generated/test_suite
A possible alternative approach is to configure the
cmake/modules/LLVMConfig.cmake.in file in the LLVM source tree
and then include it. This approach was not taken because it is more
complicated.
An interesting side benefit of this patch is that it is now
possible to configure on Darwin without llvm-config being available
by configuring with -DLLVM_CONFIG_PATH="". This moves us a step
closer to a world where no LLVM build artefacts are required to
build compiler-rt.
rdar://76016632
Is there a reason this is guarded by COMPILER_RT_DEFAULT_TARGET_ONLY? Until now we have been cross-compiling compiler-rt without this setting and relied on CMAKE_C_COMPILER_TARGET being used instead of the host triple (which is the default triple for our cross-compilers).
For now I can change our build scripts to set COMPILER_RT_DEFAULT_TARGET_ONLY when cross-compiling, but shouldn't it also work without COMPILER_RT_DEFAULT_TARGET_ONLY set?