0

I'm using the following variables. It seems cmake do use clang but ar/ranlib is not properly set.

//cmake version 3.18.2

SET(CMAKE_AR           ${tools}/bin/llvm-ar)
SET(CMAKE_RANLIB       ${tools}/bin/llvm-ranlib)
SET(CMAKE_C_COMPILER   ${tools}/bin/clang)
SET(CMAKE_CXX_COMPILER ${tools}/bin/clang++)

My attempt at an reprex:

checkout llvm-project 7fa503ef

$ mkdir clang1
# build clang here

$ cd <...>/llvm-project
$ cat ./my-toolchain.cmake

SET(CMAKE_SYSTEM_NAME Linux)
set(tools ./clang1)
SET(CMAKE_AR           ${tools}/bin/llvm-ar)
SET(CMAKE_RANLIB       ${tools}/bin/llvm-ranlib)
SET(CMAKE_C_COMPILER   ${tools}/bin/clang)
SET(CMAKE_CXX_COMPILER ${tools}/bin/clang++)


$ mkdir clang2; cd clang2
$ cmake -DCMAKE_TOOLCHAIN_FILE=../my-toolchain.cmake -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles" ../llvm
$ cat ./lib/Demangle/CMakeFiles/LLVMDemangle.dir/link.txt

Tried this from @Tsyvarev

SET(CMAKE_AR           ${tools}/bin/llvm-ar CACHE FILEPATH "ar")
SET(CMAKE_RANLIB       ${tools}/bin/llvm-ranlib CACHE FILEPATH "ranlib")

https://cmake.org/cmake/help/v3.18/command/set.html

Still getting -- Wrong!

/usr/bin/ar
/usr/bin/ranlib

I'm sorry. The trick did work!

zjk
  • 2,043
  • 3
  • 28
  • 45
  • "It seems cmake do use clang but ar/ranlib is not properly set." - How do you detect that CMake doesn't use the archiver? Where do you put the code you show? Please, prepare [mcve]. – Tsyvarev Jan 26 '21 at 09:08
  • I looked at the `link.txt` file. Seems `/usr/bin/ar` is being used. – zjk Jan 26 '21 at 09:26
  • 1
    Variables `CMAKE_AR` and `CMAKE_RANLIB` has an effect only when they are defined as CACHE'd. See the duplicate question for more info. – Tsyvarev Jan 26 '21 at 09:45
  • I'm still getting `/usr/bin/ar`. By the way is it okay to use the `/usr/bin/ar` instead of `llvm-ar` with custom clang? – zjk Jan 26 '21 at 10:09
  • 1
    Have you tried clean reconfigure, with empty build directory or at least without `CMakeCache.txt` file in it? Also, using *relative* path for `tools` variable, which is used for compiler/archiver/etc., is a wrong way. All path-like variables in CMake should be set to **absolute** paths. – Tsyvarev Jan 26 '21 at 10:23
  • It works now! Not sure what I did wrong previously though. – zjk Jan 26 '21 at 10:25

0 Answers0