How to use mainline clang/llvm with CMake

Dear all, I am not sure whether this is a right place to ask basic questions about usage of CLang/LLVM, but also not sure if there is any other mailing list for such.

Kindly point me to such a list in such case.

I had built mainline CLang/LLVM on OSX and tried to use it with CMake. I had override following variables in CMake:

CMAKE_CXX_COMPILER=${LLVM_INSTALL_PATH}/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/bin/clang++

CMAKE_CXX_STANDARD_LIBRARIES=${LLVM_INSTALL_PATH}/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib

CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES=${LLVM_INSTALL_PATH}/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/include/c++/v1

Though the compilation works, the link stage fails, as I couldn’t set the path to newly built LLVM libcxx/libcxxabi.

Could some one please tell what is the correct way to use mainline LLVM in CMake?

Thanks.

Rakur.

PS:
Complete verbose compile logs are available at https://pastebin.com/p3U2EQ1h

Im adding excerpt of compile/link commands and output logs below in this mail too.

It produces the following compilation command:

/Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/bin/clang++ -isystem /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/include/c++/v1 -g -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -std=c++17 -o CMakeFiles/seq_vector.dir/seq_vector.cpp.o -c /Users/user/workspace/github/clang_build/manual/llvm-project/example/seq_vector.cpp

Verbose compile command:

"/Users/user/workspace/github/clang_build/manual/llvm-project/install/Toolchains/LLVM12.0.0git.xctoolchain/usr/bin/clang-12" -cc1 -triple x86_64-apple-macosx10.15.0 -Wundef-prefix=TARGET_OS -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all --mrelax-relocations -disable-free -main-file-name seq_vector.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fno-rounding-math -munwind-tables -target-sdk-version=10.15.6 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=lldb -target-linker-version 609 -v -resource-dir /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib/clang/12.0.0 -isystem /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/include/c++/v1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -stdlib=libc++ -internal-isystem /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/bin/…/include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/local/include -internal-isystem /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib/clang/12.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /Users/user/workspace/github/clang_build/manual/llvm-project/example/_build/cmake/Debug -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcolor-diagnostics -o CMakeFiles/seq_vector.dir/seq_vector.cpp.o -x c++ /Users/user/workspace/github/clang_build/manual/llvm-project/example/seq_vector.cpp

But unfortunately, the link stage fails:

/Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/bin/clang++ -g -v -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/seq_vector.dir/seq_vector.cpp.o -o seq_vector /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib

Verbose link command:

“/usr/bin/ld” -demangle -lto_library /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch x86_64 -platform_version macos 10.15.0 10.15.6 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o seq_vector -search_paths_first -headerpad_max_install_names CMakeFiles/seq_vector.dir/seq_vector.cpp.o /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib -lc++ -lSystem /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.osx.a

Error:

ld: can’t map file, errno=22 file ‘/Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib’ for architecture x86_64

Dear all, I had managed to find answers to my question.

The following is my CMakeLists.txt

‐‐‐‐‐‐‐ CMakeLists.txt ‐‐‐‐‐‐‐