Rework Build.md and Install.md contributed by madscientist

Fangrui Song 2019-01-06 11:26:15 +08:00
parent 6eadcd596a
commit f951e6d451
4 changed files with 62 additions and 68 deletions

@ -9,12 +9,13 @@ Otherwise, you'll need to build **ccls** from source. You will need:
* Clang 5 or higher. * Clang 5 or higher.
* GCC 7.2 or higher (`optional,string_view` require libstdc++7 or higher) * GCC 7.2 or higher (`optional,string_view` require libstdc++7 or higher)
* MSVC 2017 or higher (included with VS2017 Build Tools) * MSVC 2017 or higher (included with VS2017 Build Tools)
* On GNU/Linux, either GNU make or Ninja (optional on other systems) * On POSIX systems, either GNU make or Ninja (optional on other systems)
The simplest/quickest build with all defaults (only for POSIX systems) is: The simplest/quickest build with all defaults (only for POSIX systems) is:
```sh ```sh
git clone --depth=1 --recursive https://github.com/MaskRay/ccls git clone --depth=1 --recursive https://github.com/MaskRay/ccls
cd ccls
cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release
cmake --build Release cmake --build Release
``` ```
@ -81,8 +82,7 @@ for your system, as well as methods of obtaining and locating Clang+LLVM.
## Choosing Clang+LLVM ## Choosing Clang+LLVM
**ccls** requires `libLLVM` to implement its code parsing. There are many **ccls** requires LLVM and Clang. There are many ways they can be obtained.
ways it can be obtained.
* `-DSYSTEM_CLANG=(ON|OFF)` * `-DSYSTEM_CLANG=(ON|OFF)`
@ -99,9 +99,16 @@ system you will need to install `libclang-*-dev` and `llvm-*-dev` packages (or
equivalent) in order to have the correct libraries. If they are installed equivalent) in order to have the correct libraries. If they are installed
into the standard locations for our system, CMake will locate them. into the standard locations for our system, CMake will locate them.
```sh Use `-DSYSTEM_CLANG=ON`.
cmake -DSYSTEM_CLANG=ON
``` * `-DCMAKE_PREFIX_PATH=<path>`
CMake searches the paths in `CMAKE_PREFIX_PATH` for `include` and `lib`
subdirectories containing the required Clang headers and libraries, e.g.
`-DSYSTEM_CLANG=ON -DCMAKE_PREFIX_PATH=/usr/local/llvm70`
You may add multiple directories for `include` and `lib` separated by a `;`.
### Alternate Clang+LLVM ### Alternate Clang+LLVM
@ -110,13 +117,7 @@ it for you, or if you want to build Clang+LLVM from source, or if CMake can't
find your installation of Clang+LLVM for any other reason, set the find your installation of Clang+LLVM for any other reason, set the
`CMAKE_PREFIX_PATH` CMake variable to point to the correct location: `CMAKE_PREFIX_PATH` CMake variable to point to the correct location:
* `-DCMAKE_PREFIX_PATH=<clang-install-path>` Similar as System Clang+LLVM, `-DSYSTEM_CLANG=ON -DCMAKE_PREFIX_PATH=clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04`
CMake searches the paths in `CMAKE_PREFIX_PATH` for `include` and `lib`
subdirectories containing the required Clang headers and libraries.
You may add multiple directories for `include` and `lib` separated by a `;`,
e.g.: `-DCMAKE_PREFIX_PATH="$HOME/Dev/llvm/release;$HOME/Dev/llvm/tools/clang"`
## GNU/Linux ## GNU/Linux

10
Home.md

@ -1,18 +1,22 @@
**ccls** is a stand-alone server implementing the [Language Server **ccls** is a stand-alone server implementing the [Language Server
Protocol](https://langserver.org/) for C, C++, and Objective-C languages. It Protocol](https://langserver.org/) for C, C++, and Objective-C languages. It
can be used with [any editor](Editor-Configuration.md) which provides an LSP can be used with [any editor](Editor-Configuration) which provides an LSP
client implementation. It originates from [cquery](https://github.com/cquery-project/cquery). client implementation. It originates from [cquery](https://github.com/cquery-project/cquery).
The language client (editor plugin) opens an instance of **ccls** for each The language client (editor plugin) opens an instance of **ccls** for each
project. **ccls** runs in the background, indexing the source code in the project. **ccls** runs in the background, indexing the source code in the
project and responding to requests from editors. project and responding to requests from editors.
**ccls** uses the Clang+LLVM `libLLVM` library to parse your source code, so **ccls** uses the Clang+LLVM C++ libraries to parse your source code, so
it will recognize all language features supported by Clang. it will recognize all language features supported by Clang.
## [[Build]] ## [[Build]]
First you must build **ccls**. You may (optionally) install it. First you must build **ccls**
## [[Install]]
You may (optionally) install **ccls**.
## [[Editor Configuration]] ## [[Editor Configuration]]

@ -1,69 +1,57 @@
## Shell script wrapper
If you're using **ccls** for your own personal use and don't want to bother If you're using **ccls** for your own personal use and don't want to bother
installing it, you don't have to. You will need to configure your editor to installing it, you don't have to. Consider putting a small shell script wrapper `ccls`
locate the `ccls` binary where it's built by CMake. on your `PATH` to customize command line options.
If you'd like to install **ccls** into a separate location and clean up the
build environment you can do so.
## CMake install
The CMake install rule will copy the **ccls** binary into the install prefix
location set via `-DCMAKE_INSTALL_PREFIX=<dir>`. By default `<dir>` will be
`/usr/local`: note you may need to run the install with elevated privileges to
write to this directory.
After building you can run:
```sh
sudo cmake --build . --config Release --target install
```
(`sudo` is not necessary if you have write permissions to the installation
directory). This will install **ccls** as `<dir>/bin/ccls` and also install
the LLVM shared libraries (you do not need these unless you've set
`-DUSE_SHARED_LLVM=ON` however).
If you have `<dir>/bin` on your `PATH` then **ccls** should be found.
## Shell Script Wrapper
An alternative to installing `ccls` is to use a small shell script wrapper and
put that on your `PATH`. This allows you to customize the invocation of
`ccls`. It's especially useful for implementing relocatable installs, or for
use with [[Editor Configuration]]s that don't make it easy to configure the
server's startup.
If you build in `$HOME/src/ccls/obj` using Ninja for example then you might
create a shell script wrapper `ccls` like this:
```sh ```sh
#!/bin/sh #!/bin/sh
exec "$HOME/src/ccls/obj/ccls" "$@" exec "$HOME/src/ccls/Release/ccls" "$@"
``` ```
(be sure to make the script executable!) You might want to add other options (be sure to make the script executable!) You might want to
such as `--log-file=/tmp/ccls.out` to force logging. You may also want to add
a `--init` option to set the resource directory as below. If you built `ccls`
using shared libraries you might need to set `LD_LIBRARY_PATH` here before
exec'ing `ccls`. And there are [[Debugging]] environment variables that might
be useful to set as well.
## Clang Resource Directory * add other options such as `--log-file=/tmp/ccls.out` to force logging. `-v=1` and `-init=` are other useful options. See [[Customization]].
* set `LD_LIBRARY_PATH` if CMake fails to set `DT_RUNPATH` for the built `ccls` executable.
* set [[Debugging]] environment variables that might be useful.
The Clang+LLVM shared library requires Clang system header files to be ## CMake install
available otherwise indexing will fail silently. Clang searches for these
headers in its _resource directory_. The `ccls` binary will be hard-coded to If you'd like to install **ccls** into a separate location, read on.
search for the resource directory where it was found by CMake during the build.
The CMake install rule will copy the **ccls** binary into the install prefix
location set via `-DCMAKE_INSTALL_PREFIX=<prefix>` (default: `/usr/local`). After
building you can run:
```sh
cmake --build Release --target install
# cmake --build . --config Release --target install
```
This will install **ccls** as `<prefix>/bin/ccls` (and also install the LLVM
shared libraries if `-DUSE_SHARED_LLVM=ON`).
If you have `<prefix>/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.
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 If you downloaded Clang+LLVM as part of the build and you want to install
**ccls** and delete the build directory, you need to copy the contents of the **ccls** and delete the build directory, you need to copy the contents of the
resource directory; for example something like: resource directory; for example something like:
```sh ```sh
sudo mkdir -p /usr/local/clang sudo mkdir -p /usr/local/clang/7.0.0
sudo cp -a clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04/lib/clang/7.0.0/include /usr/local/clang 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 Then you must configure `ccls` to locate this directory by adding an option
such as `--init='{"clang": {"resourceDir": "/usr/local/clang"}}'` (see such as `--init='{"clang": {"resourceDir": "/usr/local/clang/7.0.0"}}'` (see
[`resourceDir`](Customization#clangresourcedir) for more information). [`clang.resourceDir`](Customization#clangresourcedir) for more information).

@ -1,5 +1,6 @@
[[Home]] [[Home]]
* [[Build]] * [[Build]]
* [[Install]]
* [[Editor Configuration]] * [[Editor Configuration]]
- [[Atom]] - [[Atom]]
- Emacs - Emacs