Building and packing LLVM clang 3.4 with cmake

I started learning cmake about 2 weeks ago and sort of. So far I have managed to create and package (with the packaging format in my native system) libc++abi , libc++ , llvm 3.4 all with cmake ( libc++abi with my cmake setting) for RHEL 6.x, Fedora 20+ and Ubuntu 12.04 LTS +.

I would like to create a C ++ build environment that

  • Relieves us of our dependency on GNU GCC and libstdc++ completely (therefore, we don’t want LLVM RPM / DEB from these aforementioned distributions or LLVM Debian / Ubuntu nightly packages download site)
  • Allows us to fully learn C ++ 11 and C ++ 1y . In other words, we can at any time try to solve the problem of bloodletting LLVM / clang, while keeping all of our build systems clean with package management systems.

However, I fell into the trap of trying to build clang 3.4 with cmake , on the build host running Ubuntu 12.04 LTS 64bit, with pure clang 3.3 that I created without any dependency on GNU libstdc++ , along with libc++ 3.3 and libc++abi . The later two have no libstdc++ dependency. I also built this path.

I know the Clang - Getting Started webpage well and have used it successfully. But this is exactly what I do not want to use. They are also incorrect: CMakeLists.txt of clang 3.4 clearly states the following:

  1 # If we are not building as a part of LLVM, build Clang as an 2 # standalone project, using LLVM as an external library: 3 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) 4 project(Clang) 5 cmake_minimum_required(VERSION 2.8) 6 7 set(CLANG_PATH_TO_LLVM_SOURCE "" CACHE PATH 8 "Path to LLVM source code. Not necessary if using an installed LLVM.") 9 set(CLANG_PATH_TO_LLVM_BUILD "" CACHE PATH 10 "Path to the directory where LLVM was built or installed.") 

See lines 1 and 2. But I did not find any LLVM documentation regarding how to set CLANG_PATH_TO_LLVM_BUILD . I tried the following:

 cmake -DCLANG_PATH_TO_LLVM_BUILD="../../llvm-3.4/build" .. 

and got the following errors:

 $ clang3.4/_tars/clang-3.4/build$ cmake -DCLANG_PATH_TO_LLVM_BUILD="../../llvm-3.4/build" .. -- The C compiler identification is Clang 3.3.0 -- The CXX compiler identification is Clang 3.3.0 -- Check for working C compiler: /usr/bin/clang -- Check for working C compiler: /usr/bin/clang -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/clang++ -- Check for working CXX compiler: /usr/bin/clang++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done CMake Error at CMakeLists.txt:39 (include): include could not find load file: AddLLVM CMake Error at CMakeLists.txt:40 (include): include could not find load file: TableGen -- Performing Test C_SUPPORTS_FLAG -- Performing Test C_SUPPORTS_FLAG - Success -- Performing Test CXX_SUPPORTS_FLAG -- Performing Test CXX_SUPPORTS_FLAG - Success -- Building with -fPIC -- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG -- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG - Success -- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.7.8") -- Clang version: 3.4 -- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG -- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG - Success CMake Error at utils/TableGen/CMakeLists.txt:3 (add_tablegen): Unknown CMake command "add_tablegen". -- Configuring incomplete, errors occurred! 

But this is not so! LLVM + compiler-rt was installed on the build host using our own DEB . AND,

 $ llvm/clang3.4/_tars/clang-3.4/build$ ls /usr/share/llvm/cmake AddLLVM.cmake ChooseMSVCCRT.cmake linux_issue.cmake LLVMConfigVersion.cmake pkg.cmake AddLLVMDefinitions.cmake GetSVN.cmake LLVM-Config.cmake LLVMParseArguments.cmake TableGen.cmake arch.cmake HandleLLVMOptions.cmake LLVMConfig.cmake LLVMProcessSources.cmake 

So, all the necessary cmake modules are - right in the system!

I would appreciate a hint on how to get clang 3.4 to build using cmake with LLVM 3.4 + compiler-rt 3.4 already installed.

Update

I decided to do the following:

 $ llvm/clang3.4/_tars/clang-3.4/build$ cmake -DCLANG_PATH_TO_LLVM_BUILD="/usr" .. -- Building with -fPIC -- Clang version: 3.4 -- Found Subversion: /usr/bin/svn (found version "1.6.17") -- Configuring done -- Generating done -- Build files have been written to: ../llvm/clang3.4/_tars/clang-3.4/build ../llvm/clang3.4/_tars/clang-3.4/build$ make -j 2 Scanning dependencies of target ClangDriverOptions Scanning dependencies of target clang-tblgen [ 0%] Building Options.inc... [ 0%] ../llvm/clang3.4/_tars/clang-3.4/include/clang/Driver/Options.td:15:9: error: Could not find include file 'llvm/Option/OptParser.td' include "llvm/Option/OptParser.td" ^ .../llvm/clang3.4/_tars/clang-3.4/include/clang/Driver/Options.td:15:9: Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangASTNodesEmitter.cpp.o error: Unexpected input at top level include "llvm/Option/OptParser.td" ^ make[2]: *** [include/clang/Driver/Options.inc.tmp] Error 1 make[1]: *** [include/clang/Driver/CMakeFiles/ClangDriverOptions.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... [ 0%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangAttrEmitter.cpp.o [ 0%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangCommentCommandInfoEmitter.cpp.o [ 0%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangCommentHTMLNamedCharacterReferenceEmitter.cpp.o [ 1%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangCommentHTMLTagsEmitter.cpp.o [ 1%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangDiagnosticsEmitter.cpp.o [ 1%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangSACheckersEmitter.cpp.o [ 1%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/NeonEmitter.cpp.o [ 1%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/TableGen.cpp.o Linking CXX executable ../llvm/clang3.4/_tars/llvm-3.4/build/bin/clang-tblgen [ 1%] Built target clang-tblgen make: *** [all] Error 2 

This is better. Looks like clang 3.4 default CMakeLists.txt is not even QA-ed x- (Yikes x - (

+6
source share
2 answers

I decided to strengthen this, as any self-respecting engineer would do :) I just looked at the following two files and added the full path to the include violation, and then this.

  • Options.td
  • CC1AsOptions.td

Now I can create all the necessary core LLVM projects without the libstdc++ dependency, all related to libc++ and libc++abi . Hooray:

So, I confirmed that

  • Some of the instructions in Getting Started: Creating and Running Clang are misleading, for example. 7 .
  • All major LLVM projects (except compiler-rt AFAIK) can be built using cmake . There is no need to combine them together in the LLVM source tree for construction. You can definitely build almost all of them separately on Linux, in contrast to what this "official" documentation might seem:>

The LLVM team must truly think through and minimize the apparent cyclic dependency between all projects. Bootstrapping LLVM / clang on different Linux distributions (especially older ones, such as RHEL 5.x) without GNU libstdc++ dependency is too tedious - says firsthand. They can be made (I did it :), but this is not for the faint of heart.

+4
source

I think this project does what you are trying to do:

https://github.com/rsmmr/install-clang

I used it on FC16 +, but ran into reboot problems on RHEL5.x.

+2
source

All Articles