Using Xcode to compile clang, still possible ?


as a clang newbie, I used the „Getting Started“ ( documentation and I could build everything nicely using cmake. I was also able to create a LLVM.xcodeproj file. But that project is huge.

Judging from an older blog entry (, it should also be possible to just create a clang.xcodeproj file, which would be much preferable to me, but I can’t get it to work.

I set this environment variables to get llvm-config to be found

export PATH

But then I get

walitza:clang nat$ cmake -DCLANG_PATH_TO_LLVM_SOURCE=../llvm -DCLANG_PATH_TO_LLVM_BUILD=../build -DCMAKE_BUILD_TYPE=Debug ../llvm/tools/clang
-- Found LLVM_CONFIG as /Volumes/Source/srcM/clang-test/build/bin/llvm-config
-- Building with -fPIC
-- Clang version: 3.6.0
CMake Error at /Volumes/Source/srcM/clang-test/build/share/llvm/cmake/AddLLVM.cmake:438 (add_executable):
  add_executable cannot create target "clang-tblgen" because an imported
  target with the same name already exists.
Call Stack (most recent call first):
  /Volumes/Source/srcM/clang-test/build/share/llvm/cmake/AddLLVM.cmake:501 (add_llvm_executable)
  /Volumes/Source/srcM/clang-test/build/share/llvm/cmake/TableGen.cmake:76 (add_llvm_utility)
  utils/TableGen/CMakeLists.txt:3 (add_tablegen)

CMake Error at /Volumes/Source/srcM/clang-test/build/share/llvm/cmake/LLVM-Config.cmake:49 (target_link_libraries):
  Cannot specify link libraries for target "clang-tblgen" which is not built
  by this project.
Call Stack (most recent call first):
  /Volumes/Source/srcM/clang-test/build/share/llvm/cmake/LLVM-Config.cmake:34 (explicit_llvm_config)
  /Volumes/Source/srcM/clang-test/build/share/llvm/cmake/AddLLVM.cmake:455 (llvm_config)
  /Volumes/Source/srcM/clang-test/build/share/llvm/cmake/AddLLVM.cmake:501 (add_llvm_executable)
  /Volumes/Source/srcM/clang-test/build/share/llvm/cmake/TableGen.cmake:76 (add_llvm_utility)
  utils/TableGen/CMakeLists.txt:3 (add_tablegen)

-- Configuring incomplete, errors occurred!
See also "/Volumes/Source/srcM/clang-test/clang/CMakeFiles/CMakeOutput.log".
See also "/Volumes/Source/srcM/clang-test/clang/CMakeFiles/CMakeError.log“.

Doesn’t that work anymore ?


It looks like you are trying to use the so-called “standalone” clang build, but you checked out clang into llvm/tools/clang. You only need to put clang sources in llvm/tools/clang if you want it to be part of the LLVM build. If you move the sources out to somewhere alongside the llvm sources, the standalone build will probably work. I did this with VS a few weeks ago.

Also, you probably want to delete your initial llvm build directory before retrying, because it will probably contain variables defined by clang’s cmake that shouldn’t be there.

Thanks, that was very helpful and it got me further along the way.

Unfortunately I am also a cmake newbie as well...

I moved llvm/tools/clang away and built llvm again. Then I tried to build clang separately in its own build directory thusly:

nat@kempe:build(^) $ cmake -DCLANG_PATH_TO_LLVM_SOURCE=../../clang-test/llvm -DCLANG_PATH_TO_LLVM_BUILD=../../clang-test/build -DCMAKE_BUILD_TYPE=Debug ../clang
-- Found LLVM_CONFIG as /Volumes/Source/srcM/clang-test/build/bin/llvm-config
CMake Error at /Volumes/Source/srcM/clang-test/build/share/llvm/cmake/HandleLLVMOptions.cmake:38 (message):
  Host Clang must be able to find libstdc++4.7 or newer!
Call Stack (most recent call first):
  CMakeLists.txt:96 (include)

-- Configuring incomplete, errors occurred!
See also "/Volumes/Source/srcM/mulle-clang/build/CMakeFiles/CMakeOutput.log".
See also "/Volumes/Source/srcM/mulle-clang/build/CMakeFiles/CMakeError.log".

On a hunch ( I edited - in the llvm build directory "./../clang-test/build/" - the "CMakeCache.txt" file for LLVM_ENABLE_LIBCXX:BOOL=ON and cmaked/build all of llvm.

But the same error persists, probably because I don't understand how cmake works.


Are you sure those cmake variables are ok? If I move clang out of source and try to configure using cmake gui I can’t see any variables with CLANG_ prefix?

I am not sure at all, I am just parroting what I gleaned from that blog entry I mentioned in my first posting.

But when I just do

cmake ../clang

the error message is the same. (I have to build llvm anyway it seems, because otherwise I don't get llvm-config.)


I did this a number of times on windows and linux and I don’t remember using those variables. What happens if you remove them? I think you’ll need to specify build type and path to llvm-config…

Ok, having experimented a bit, llvm-config seems to provide the compiler flags needed for the clang build. So specifying those additional CLANG_ variables is maybe superflous, but maybe not. The Xcode installation itself unfortunately does not seem to provide a llvm-config (I couldn't find any).

nat@kempe:build(^) $ ../../clang-test/build/bin/llvm-config --cxxflags
-I/Volumes/Source/srcM/clang-test/llvm/include -I/Volumes/Source/srcM/clang-test/build/include -stdlib=libc++ -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -std=c++11 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS


So for anyone trying the same, the solution for me was this:

mkdir build-llvm
cd build-llvm
cmake -G "Unix Makefiles" -DLLVM_ENABLE_CXX1Y:BOOL=OFF ../llvm
cd ..

PATH=`pwd`/build-llvm/bin:$PATH ; export PATH

mkdir build-clang
cd build-clang
cmake -G "Xcode" ../clang