diff --git a/Build.md b/Build.md index bfd552a..73eb501 100644 --- a/Build.md +++ b/Build.md @@ -79,47 +79,54 @@ If using Windows the automatically downloaded LLVM binaries are 64-bit; you shou ## Link against clang+llvm libraries compiled from source -MaskRay's config (building trunk LLVM at `~/Dev/llvm/release/`): +* `include/llvm/Config/config.h` +* `include/clang/Config/config.h` +* `lib/libclangIndex.so` +* `lib/libLLVM{Support,...}.so` or `lib/libLLVM{Support,...}.a` or `lib/libLLVM.so` + +MaskRay's config (building trunk LLVM at `~/llvm/Release/`): ``` -cd ~/Dev +cd git clone https://git.llvm.org/git/llvm.git cd llvm/tools git clone https://git.llvm.org/git/clang.git -cd ~/Dev -# create a build directory named `release/` -cmake -H. -Brelease -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_SHARED_LIBS=ON -DLLVM_ENABLE_LLD=ON -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_GO_TESTS=OFF -DLLVM_INCLUDE_DOCS=OFF -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_USE_SPLIT_DWARF=On -DLLVM_OPTIMIZED_TABLEGEN=On +cd ~/llvm +# create a build directory named `Release/` +cmake -H. -BRelease -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_SHARED_LIBS=ON -DLLVM_ENABLE_LLD=ON -DLLVM_TARGETS_TO_BUILD=X86 +ninja -C Release clangIndex clangTooling ``` -Remove `LLVM_ENABLE_LLD` if don't have lld (a much faster linker than bfd/gold) installed -Remove `BUILD_SHARED_LIBS` if you want to build static libraries (`libclangDriver.a` `libLLVMSupport.a`, note `libclang.so` is still a shared object) +* Remove `LLVM_ENABLE_LLD` if you don't have lld (a much faster linker than bfd/gold) installed +* Remove `BUILD_SHARED_LIBS` if you want to build static libraries (`libclangIndex.a`) instead -Then build ccls: +Then build ccls with `-DSYSTEM_CLANG` and `-DCMAKE_PREFIX_PATH`: ```zsh -cmake -H. -Brelease -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DSYSTEM_CLANG=On -DCMAKE_PREFIX_PATH="$HOME/Dev/llvm/release;$HOME/Dev/llvm/release/tools/clang;$HOME/Dev/llvm;$HOME/Dev/llvm/tools/clang" -cmake --build release +cd ~/ccls +cmake -H. -BRelease -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld -DSYSTEM_CLANG=On -DCMAKE_PREFIX_PATH="$HOME/llvm/Release;$HOME/llvm/Release/tools/clang;$HOME/llvm;$HOME/llvm/tools/clang" +ninja -C Release ``` -There are 4 directories specified in `CMAKE_PREFIX_PATH`: +`-DCMAKE_PREFIX_PATH=` is a `;`-separated list where you can find: -* `Dev/llvm`: llvm source -* `Dev/llvm/tools/clang`: clang source (`git clone https://git.llvm.org/git/clang.git`) -* `Dev/llvm/release`: build directory. `include/` contains some generated llvm header files -* `Dev/llvm/release/tools/clang`: part of the build directory. `include/` contains some generated clang header files +* `llvm`: llvm source +* `llvm/tools/clang`: clang source (`git clone https://git.llvm.org/git/clang.git`) +* `llvm/Release`: build directory. `include/` contains generated llvm header files, e.g. `include/llvm/Config/config.h` +* `llvm/Release/tools/clang`: build directory. `include/` contains generated clang header files, e.g. `include/clang/Config/config.h` The cmake build system is expected to find these files: ``` # generated clang+llvm header files -~/Dev/llvm/release/include/llvm/Config/config.h -~/Dev/llvm/release/tools/clang/include/clang/Config/config.h -# libclang -~/Dev/llvm/release/lib/libclang.so +~/llvm/Release/include/llvm/Config/config.h +~/llvm/Release/tools/clang/include/clang/Config/config.h +# libclangIndex.so +~/llvm/Release/lib/libclangIndex.so # -resource-dir -~/Dev/llvm/release/lib/clang/7.0.0 +~/llvm/release/lib/clang/7.0.0 # clang+llvm libraries -~/Dev/llvm/release/lib/libclangDriver.so -~/Dev/llvm/release/lib/libLLVMSupport.so +~/llvm/release/lib/libclangDriver.so +~/llvm/release/lib/libLLVMSupport.so ... ```