as a clang newbie, I used the „Getting Started“ (http://clang.llvm.org/get_started.html) documentation and I could build everything nicely using cmake. I was also able to create a LLVM.xcodeproj file. But that project is huge.
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“.
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".
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 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).