I have multiple versions of llvm installed on my Unix machine, I am building a CMake project that requires LLVM50 and lower but setting the CMake LLVM_CONFIG path it finds LLVM60.
Is there a way to nudge CMake in finding the right LLVM version.
You didn't write how these versions are accessible to your commandline (e.g. is Clang 3.9 executed as clang-3.9
or do you have to export its bin
directory in the $PATH
environment variable?)
Once the desired LLVM/Clang version is in my $PATH
, what I usually do is to use the llvm-config
for the specific version I'm interested in to pass cmake
variable values (especially LLVM_DIR
), e.g.
cmake \
-GNinja \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DLLVM_DIR="$(llvm-config --cmakedir)" \
-DCMAKE_BUILD_TYPE=Debug \
[...]
If the --cmakedir
option is not available in the LLVM version that you want, use something like $(llvm-config --prefix)/share/llvm/cmake/)
instead (or wherever the cmake dir with the definitions is).
Also, adjust CMAKE_C_COMPILER
and CMAKE_CXX_COMPILER
to the correct executable name as mentioned earlier.