user1610950
user1610950

Reputation: 1917

cmake and llvm-config config

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.

Upvotes: 2

Views: 4834

Answers (2)

ConsistentProgrammer
ConsistentProgrammer

Reputation: 1324

You can update your $PATH variable in Linux like:

export $PATH=<path_to_llvm_bin_folder>:$PATH

You can also place this in your .bashrc file, if you always use a specific version of llvm.

Upvotes: 1

compor
compor

Reputation: 2339

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.

Upvotes: 3

Related Questions