Unverified Commit bb978c06 by Adam Badura Committed by GitHub

Update build instructions to better use CMake (#1017)

Build instructions needlessly referred to make when CMake offers a command-line interface to abstract away from the specific build system. Furthermore, CMake offers command-line "tool mode" which performs basic filesystem operations. While the syntax is a bit more verbose than Linux commands it is platform-independent. Now the commands can be copy-pasted on both Linux and Windows and will just work. Finally, the Release build type is included in initial commands. A natural flow for a new-comer is to read and execute the commands and only then learn that one has to go back and redo them again this time with proper parameters. Now instead the parameters are only explained later but present already in the initial commands.
parent 5b72b6c2
...@@ -70,13 +70,13 @@ $ git clone https://github.com/google/googletest.git benchmark/googletest ...@@ -70,13 +70,13 @@ $ git clone https://github.com/google/googletest.git benchmark/googletest
# Go to the library root directory # Go to the library root directory
$ cd benchmark $ cd benchmark
# Make a build directory to place the build output. # Make a build directory to place the build output.
$ mkdir build && cd build $ cmake -E make_directory "build"
# Generate a Makefile with cmake. # Generate build system files with cmake.
# Use cmake -G <generator> to generate a different file type. $ cmake -E chdir "build" cmake -DCMAKE_BUILD_TYPE=Release ../
$ cmake ../ # or, starting with CMake 3.13, use a simpler form:
# cmake -DCMAKE_BUILD_TYPE=Release -S . -B "build"
# Build the library. # Build the library.
# Use make -j<number_of_parallel_jobs> to speed up the build process, e.g. make -j8 . $ cmake --build "build" --config Release --parallel
$ make
``` ```
This builds the `benchmark` and `benchmark_main` libraries and tests. This builds the `benchmark` and `benchmark_main` libraries and tests.
On a unix system, the build directory should now look something like this: On a unix system, the build directory should now look something like this:
...@@ -94,13 +94,13 @@ On a unix system, the build directory should now look something like this: ...@@ -94,13 +94,13 @@ On a unix system, the build directory should now look something like this:
Next, you can run the tests to check the build. Next, you can run the tests to check the build.
```bash ```bash
$ make test $ cmake --build "build" --config Release --target test
``` ```
If you want to install the library globally, also run: If you want to install the library globally, also run:
``` ```
sudo make install sudo cmake --build "build" --config Release --target install
``` ```
Note that Google Benchmark requires Google Test to build and run the tests. This Note that Google Benchmark requires Google Test to build and run the tests. This
...@@ -117,17 +117,14 @@ to `CMAKE_ARGS`. ...@@ -117,17 +117,14 @@ to `CMAKE_ARGS`.
### Debug vs Release ### Debug vs Release
By default, benchmark builds as a debug library. You will see a warning in the By default, benchmark builds as a debug library. You will see a warning in the
output when this is the case. To build it as a release library instead, use: output when this is the case. To build it as a release library instead, add
`-DCMAKE_BUILD_TYPE=Release` when generating the build system files, as shown
``` above. The use of `--config Release` in build commands is needed to properly
cmake -DCMAKE_BUILD_TYPE=Release support multi-configuration tools (like Visual Studio for example) and can be
``` skipped for other build systems (like Makefile).
To enable link-time optimisation, use To enable link-time optimisation, also add `-DBENCHMARK_ENABLE_LTO=true` when
generating the build system files.
```
cmake -DCMAKE_BUILD_TYPE=Release -DBENCHMARK_ENABLE_LTO=true
```
If you are using gcc, you might need to set `GCC_AR` and `GCC_RANLIB` cmake If you are using gcc, you might need to set `GCC_AR` and `GCC_RANLIB` cmake
cache variables, if autodetection fails. cache variables, if autodetection fails.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment