1gRPC C++ - Building from source 2=========================== 3 4# Pre-requisites 5 6## Linux 7 8```sh 9 $ [sudo] apt-get install build-essential autoconf libtool pkg-config 10``` 11 12If you plan to build from source and run tests, install the following as well: 13```sh 14 $ [sudo] apt-get install libgflags-dev libgtest-dev 15 $ [sudo] apt-get install clang libc++-dev 16``` 17 18## MacOS 19 20On a Mac, you will first need to 21install Xcode or 22[Command Line Tools for Xcode](https://developer.apple.com/download/more/) 23and then run the following command from a terminal: 24 25```sh 26 $ [sudo] xcode-select --install 27``` 28 29To build gRPC from source, you may need to install the following 30packages from [Homebrew](https://brew.sh): 31 32```sh 33 $ brew install autoconf automake libtool shtool 34``` 35 36If you plan to build from source and run tests, install the following as well: 37```sh 38 $ brew install gflags 39``` 40 41*Tip*: when building, 42you *may* want to explicitly set the `LIBTOOL` and `LIBTOOLIZE` 43environment variables when running `make` to ensure the version 44installed by `brew` is being used: 45 46```sh 47 $ LIBTOOL=glibtool LIBTOOLIZE=glibtoolize make 48``` 49 50## Windows 51 52To prepare for cmake + Microsoft Visual C++ compiler build 53- Install Visual Studio 2015 or 2017 (Visual C++ compiler will be used). 54- Install [Git](https://git-scm.com/). 55- Install [CMake](https://cmake.org/download/). 56- Install [Active State Perl](https://www.activestate.com/activeperl/) (`choco install activeperl`) - *required by boringssl* 57- Install [Go](https://golang.org/dl/) (`choco install golang`) - *required by boringssl* 58- Install [yasm](http://yasm.tortall.net/) and add it to `PATH` (`choco install yasm`) - *required by boringssl* 59- (Optional) Install [Ninja](https://ninja-build.org/) (`choco install ninja`) 60 61## Protoc 62 63By default gRPC uses [protocol buffers](https://github.com/google/protobuf), 64you will need the `protoc` compiler to generate stub server and client code. 65 66If you compile gRPC from source, as described below, the Makefile will 67automatically try compiling the `protoc` in third_party if you cloned the 68repository recursively and it detects that you do not already have 'protoc' compiler 69installed. 70 71If 'protoc' compiler has not been installed, following commands can be used for installation. 72 73```sh 74$ cd grpc/third_party/protobuf 75$ sudo make install # 'make' should have been run by core grpc 76``` 77 78# Clone the repository (including submodules) 79 80Before building, you need to clone the gRPC github repository and download submodules containing source code 81for gRPC's dependencies (that's done by the `submodule` command or `--recursive` flag). The following commands will clone the gRPC 82repository at the latest stable version. 83 84## Unix 85 86```sh 87 $ git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc 88 $ cd grpc 89 $ git submodule update --init 90 ``` 91 92## Windows 93 94``` 95> @rem You can also do just "git clone --recursive -b THE_BRANCH_YOU_WANT https://github.com/grpc/grpc" 96> powershell git clone --recursive -b ((New-Object System.Net.WebClient).DownloadString(\"https://grpc.io/release\").Trim()) https://github.com/grpc/grpc 97> cd grpc 98> @rem To update submodules at later time, run "git submodule update --init" 99``` 100 101# Build from source 102 103In the C++ world, there's no "standard" build system that would work for in all supported use cases and on all supported platforms. 104Therefore, gRPC supports several major build systems, which should satisfy most users. 105 106Note that this section only covers the build of gRPC itself, not the installation. See the [How to use](https://github.com/grpc/grpc/tree/master/src/cpp#to-start-using-grpc-c) instructions 107for guidance on how to add gRPC as a dependency to a C++ application (there are several ways and system wide installation is often not the best choice). 108 109## make (on UNIX systems) 110 111From the grpc repository root 112```sh 113 $ make 114``` 115 116## bazel 117 118See [Installing Bazel](https://docs.bazel.build/versions/master/install.html) for instructions how to install bazel on your system. 119 120From the grpc repository root 121``` 122$ bazel build :all 123``` 124 125## cmake: Windows, Using Visual Studio 2015 or 2017 (can only build with OPENSSL_NO_ASM). 126When using the "Visual Studio" generator, 127cmake will generate a solution (`grpc.sln`) that contains a VS project for 128every target defined in `CMakeLists.txt` (+ few extra convenience projects 129added automatically by cmake). After opening the solution with Visual Studio 130you will be able to browse and build the code. 131``` 132> @rem Run from grpc directory after cloning the repo with --recursive or updating submodules. 133> md .build 134> cd .build 135> cmake .. -G "Visual Studio 14 2015" 136> cmake --build . --config Release 137``` 138 139## cmake: Windows, Using Ninja (faster build, supports boringssl's assembly optimizations). 140Please note that when using Ninja, you will still need Visual C++ (part of Visual Studio) 141installed to be able to compile the C/C++ sources. 142``` 143> @rem Run from grpc directory after cloning the repo with --recursive or updating submodules. 144> md .build 145> cd .build 146> call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x64 147> cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release 148> cmake --build . 149``` 150