From fbd115776ac508f33511ad878f8562ba989b76f4 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 9 Mar 2019 22:42:59 -0800 Subject: [PATCH] Delete LLVM_ENABLE_RTTI and USE_SHARED_LLVM; they are unnecessary since https://github.com/MaskRay/ccls/pull/313 --- Build.md | 88 +++++++++++++++++------------------------------------- Install.md | 27 ++++++++--------- 2 files changed, 40 insertions(+), 75 deletions(-) diff --git a/Build.md b/Build.md index 1e796cd..7cd1f66 100644 --- a/Build.md +++ b/Build.md @@ -68,14 +68,6 @@ for your system, as well as methods of obtaining and locating Clang+LLVM. Set the install location. See [[Install]] for more details. -* `-DUSE_SHARED_LLVM=(ON|OFF)` - - Default: **OFF** - - Link against `libLLVM.so` instead of static LLVM libraries. This makes - linking faster and the executable significantly smaller but the **ccls** - binary will need access to `libLLVM.so` at runtime as well as link-time. - * `-DCLANG_USE_BUNDLED_LIBC++=(ON|OFF)` Default: **OFF** @@ -85,55 +77,45 @@ for your system, as well as methods of obtaining and locating Clang+LLVM. Linux due to conflict of libstdc++ (linked by clang+llvm libraries) and libc++. -* `-DLLVM_ENABLE_RTTI=(ON|OFF)` +* `-DCMAKE_PREFIX_PATH=` - Default: **OFF** - - Some system-supplied versions of `libLLVM` enable RTTI in which case - **ccls** must as well: use `-DLLVM_ENABLE_RTTI=ON`. See the system-specific - sections below. + Specify paths where CMake can locate Clang/LLVM headers and libraries. + CMake searches the paths in `CMAKE_PREFIX_PATH` for `include` and `lib`. ## Choosing Clang+LLVM -* `-DCMAKE_PREFIX_PATH=` - - CMake searches the paths in `CMAKE_PREFIX_PATH` for `include` and `lib` - subdirectories containing the required Clang headers and libraries, e.g. - - If you want to link against a version of Clang+LLVM already installed on your - system you will need to install packages (or equivalent) in order to have the - correct libraries. e.g. `-DCMAKE_PREFIX_PATH=/usr/local/llvm70` - -**ccls** requires LLVM and Clang. There are many ways they can be obtained. - ### System Clang+LLVM -If they are installed into the standard locations for our system, CMake will locate them. +If your system Clang+LLVM is sufficiently new, consider using them. If they +are installed into the standard locations for our system, `CMAKE_PREFIX_PATH` +is not required. -On Debian and its derivatives, you may install `libclang-*-dev` and `llvm-*-dev`. +A simple `cmake -GNinja -H. -BRelease` (remove `-GNinja` if you don't use +Ninja) works for at least the following distributions: - You may add multiple directories for `include` and `lib` separated by a `;`. +* Arch Linux +* Fedora Linux +* Gentoo Linux +* Void Linux -### Prebuilt binaries +### Prebuilt Clang+LLVM binaries Pick the one on https://releases.llvm.org/download.html that suits your system. Note, the Ubuntu 16.04 prebuit binaries are actually suitable for many non-Ubuntu distributions. -After unpacking, `-DCMAKE_PREFIX_PATH=/path/to/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04` +After unpacking, `cmake -GNinja -H. -BRelease -DCMAKE_PREFIX_PATH=/path/to/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04` The Windows prebuilt binaries lack C++ header files, thus they cannot be used. -## GNU/Linux +## System specific notes -* On GNU/Linux distributions with older versions of glibc (older than - 2013-04-25), such as Red Hat EL 6.x, append `-DCMAKE_CXX_FLAGS=-D__STDC_FORMAT_MACROS` +On GNU/Linux distributions with older versions of glibc (older than +2013-04-25), such as Red Hat EL 6.x, append `-DCMAKE_CXX_FLAGS=-D__STDC_FORMAT_MACROS` ### Arch Linux Arch User Repository: [aur/ccls-git](https://aur.archlinux.org/packages/ccls-git). -To build **ccls** on Arch Linux with system clang+llvm: `cmake -H. -BRelease -DUSE_SHARED_LLVM=on -DLLVM_ENABLE_RTTI=on` - `extra/clang` and `extra/llvm` provide `/usr/lib/{libclangAST.so,libLLVM*.a,libLLVM.so}`. `libclangAST.so` needs `libLLVM.so` and there would be a conflict if `libLLVM*.a` (instead of `libLLVM.so`) are linked. See https://bugs.archlinux.org/task/60512 @@ -141,13 +123,9 @@ To build **ccls** on Arch Linux with system clang+llvm: `cmake -H. -BRelease -DU ```sh apt install clang-7 libclang-7-dev -cmake -H. -BRelease -DCMAKE_PREFIX_PATH=/usr/lib/llvm-7 -DLLVM_ENABLE_RTTI=on +cmake -H. -BRelease -DCMAKE_PREFIX_PATH=/usr/lib/llvm-7 ``` -### Gentoo Linux - -To build **ccls** on Gentoo Linux with system Clang+LLVM: `cmake -H. -BRelease -DLLVM_ENABLE_RTTI=on` - ### Ubuntu To build from source you'll need `sudo apt install zlib1g-dev libncurses-dev` @@ -160,28 +138,19 @@ To build with system Clang+LLVM: `sudo apt install clang libclang-dev` cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_PREFIX_PATH=/usr/lib/llvm-7 \ -DLLVM_INCLUDE_DIR=/usr/lib/llvm-7/include \ - -DLLVM_BUILD_INCLUDE_DIR=/usr/include/llvm-7/ \ - -DLLVM_ENABLE_RTTI=on + -DLLVM_BUILD_INCLUDE_DIR=/usr/include/llvm-7/ ``` Notice that `LLVM_INCLUDE_DIR` points to /usr/lib, and `LLVM_BUILD_INCLUDE` points to /usr/include. Build as normal. You'll have a ccls library that will be compiled against the sytem-installed LLVM, and use the system clang resource directory as well. -### Void Linux - -To build **ccls** on Void Linux with system Clang+LLVM: `cmake -H. -BRelease -DLLVM_ENABLE_RTTI=on` - ### Red Hat / CentOS Older versions (6.x) use an older GNU libc which requires `-DCMAKE_CXX_FLAGS=-D__STDC_FORMAT_MACROS` -### Fedora - -(Tested on Fedora 29) To build **ccls** on Fedora with system Clang+LLVM: `cmake -H. -BRelease -DUSE_SHARED_LLVM=on -DLLVM_ENABLE_RTTI=on` - -## MacOS +### MacOS To install **ccls** with Homebrew use https://github.com/twlz0ne/homebrew-ccls @@ -191,8 +160,7 @@ of Xcode with a sufficiently-new Clang. To build using MacPorts Clang add CMake flags ```sh -DCMAKE_CXX_COMPILER=clang++-mp-6.0 --DCMAKE_PREFIX_PATH=/opt/local/libexec/llvm-6.0 -DLLVM_ENABLE_RTTI=on --DUSE_SHARED_LLVM=on` +-DCMAKE_PREFIX_PATH=/opt/local/libexec/llvm-6.0 ``` With clang < 8, to make header completion work, use a [shell script wrapper](Install#shell-script-wrapper): @@ -203,14 +171,14 @@ exec /path/to/ccls/Release/ccls -init='{"clang":{"extraArgs":["-isystem", "/Libr See https://github.com/MaskRay/ccls/issues/191#issuecomment-453809905 for details. -## FreeBSD +### FreeBSD * [devel/ccls](https://www.freshports.org/devel/ccls) -* With `devel/llvm70` add CMake flags `-DUSE_SHARED_LLVM=on -DCMAKE_PREFIX_PATH=/usr/local/llvm70` +* With `devel/llvm70` add CMake flags `-DCMAKE_PREFIX_PATH=/usr/local/llvm70` * To use the releases.llvm.org prebuilt archive and its libc++ add CMake flag `-DCLANG_USE_BUNDLED_LIBC++=on` -## GuixSD (0.16) +### GuixSD (0.16) ```sh guix package -i cmake clang gcc-toolchain @@ -218,7 +186,7 @@ cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/home/$USER/. cmake --build Release ``` -## Windows +### Windows The Windows archive on releases.llvm.org does not contain library headers. Since **ccls** uses Clang C++ APIs, it is not possible to build **ccls** with @@ -227,7 +195,7 @@ these releases. You must either: 1. Build clang+llvm by yourself 2. Get prebuilt LLVM+Clang from other sources, e.g. MSYS2. -### Build clang+llvm by yourself +#### Build clang+llvm by yourself ```sh git clone https://git.llvm.org/git/llvm.git @@ -243,7 +211,7 @@ cmake -H. -BRelease -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=cla ninja -C Release ``` -### MSYS2 +#### MSYS2 For 2, one possible way is use MSYS2, in MSYS2 MinGW 64-bit shell: @@ -255,7 +223,7 @@ ninja -C Release `-D__STDC_FORMAT_MACROS` is because otherwise `mingw-w64-headers/crt/inttypes.h` does not define `PRIu64`. -## Notes on compiling Clang+LLVM from source +## Compiling Clang+LLVM from source MaskRay's config (building trunk LLVM at `~/llvm/Release/`): diff --git a/Install.md b/Install.md index 8a96d79..929e2cc 100644 --- a/Install.md +++ b/Install.md @@ -28,30 +28,27 @@ cmake --build Release --target install # cmake --build . --config Release --target install ``` -This will install **ccls** as `/bin/ccls` (and also install the LLVM -shared libraries if `-DUSE_SHARED_LLVM=ON`). - -If you have `/bin` on your `PATH` then **ccls** should be found. +This will install **ccls** as `/bin/ccls`. If you have `/bin` on your `PATH` then **ccls** should be found. ## Clang resource directory Some header files such as `stddef.h stdint.h` are located in the `include/` -subdirectory of Clang resource directory. +subdirectory of Clang resource directory. The path is derived from `clang +-print-resource-dir` at CMake configure time. -The location of Clang resource directory is hard-coded in the `ccls` executable -(`-DDEFAULT_RESOURCE_DIRECTORY=` when building ccls). The absence of Clang -resource directory may lead to errors like `unknown type name 'size_t'` and -incomplete index results. - -If you downloaded Clang+LLVM as part of the build and you want to install +The location is hard-coded in the `ccls` executable +(`-DDEFAULT_RESOURCE_DIRECTORY=` when building ccls). If you want to install **ccls** and delete the build directory, you need to copy the contents of the -resource directory; for example something like: +resource directory before building ccls. + +Otherwise the absence of Clang resource directory may lead to errors like +`unknown type name 'size_t'`. ```sh sudo mkdir -p /usr/local/clang/7.0.0 sudo cp -a Release/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04/lib/clang/7.0.0/include /usr/local/clang/7.0.0/ ``` -Then you must configure `ccls` to locate this directory by adding an option -such as `--init='{"clang": {"resourceDir": "/usr/local/clang/7.0.0"}}'` (see -[`clang.resourceDir`](Customization#clangresourcedir) for more information). +Then you must set the initialization option +[`clang.resourceDir`](Customization#clangresourcedir): `--init='{"clang": +{"resourceDir": "/usr/local/clang/7.0.0"}}'`.