diff options
author | Gennadiy Civil <misterg@google.com> | 2019-07-18 19:27:51 (GMT) |
---|---|---|
committer | Gennadiy Civil <misterg@google.com> | 2019-07-18 19:27:51 (GMT) |
commit | b77e5c76252bac322bb82c5b444f050bd0d92451 (patch) | |
tree | 13e73f0759e2bbd3014c6940433c97455387e563 /googletest/docs/pkgconfig.md | |
parent | a743249a5534eb57d3f5b4b0bb6d51b8dd2d5c68 (diff) | |
download | googletest-b77e5c76252bac322bb82c5b444f050bd0d92451.zip googletest-b77e5c76252bac322bb82c5b444f050bd0d92451.tar.gz googletest-b77e5c76252bac322bb82c5b444f050bd0d92451.tar.bz2 |
Manual docs tweaks still in preparation for including docs with code pushes
Diffstat (limited to 'googletest/docs/pkgconfig.md')
-rw-r--r-- | googletest/docs/pkgconfig.md | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/googletest/docs/pkgconfig.md b/googletest/docs/pkgconfig.md index 5ad1f01..b775873 100644 --- a/googletest/docs/pkgconfig.md +++ b/googletest/docs/pkgconfig.md @@ -1,25 +1,24 @@ -## Using GoogleTest from various build systems ## +## Using GoogleTest from various build systems GoogleTest comes with pkg-config files that can be used to determine all necessary flags for compiling and linking to GoogleTest (and GoogleMock). Pkg-config is a standardised plain-text format containing - * the includedir (-I) path - * necessary macro (-D) definitions - * further required flags (-pthread) - * the library (-L) path - * the library (-l) to link to +* the includedir (-I) path +* necessary macro (-D) definitions +* further required flags (-pthread) +* the library (-L) path +* the library (-l) to link to -All current build systems support pkg-config in one way or another. For -all examples here we assume you want to compile the sample +All current build systems support pkg-config in one way or another. For all +examples here we assume you want to compile the sample `samples/sample3_unittest.cc`. - -### CMake ### +### CMake Using `pkg-config` in CMake is fairly easy: -``` cmake +```cmake cmake_minimum_required(VERSION 3.0) cmake_policy(SET CMP0048 NEW) @@ -43,11 +42,10 @@ that all libraries have been compiled with threading enabled. In addition, GoogleTest might also require `-pthread` in the compiling step, and as such splitting the pkg-config `Cflags` variable into include dirs and macros for `target_compile_definitions()` might still miss this). The same recommendation -goes for using `_LDFLAGS` over the more commonplace `_LIBRARIES`, which -happens to discard `-L` flags and `-pthread`. - +goes for using `_LDFLAGS` over the more commonplace `_LIBRARIES`, which happens +to discard `-L` flags and `-pthread`. -### Autotools ### +### Autotools Finding GoogleTest in Autoconf and using it from Automake is also fairly easy: @@ -77,8 +75,7 @@ testapp_CXXFLAGS = $(GTEST_CFLAGS) testapp_LDADD = $(GTEST_LIBS) ``` - -### Meson ### +### Meson Meson natively uses pkgconfig to query dependencies: @@ -96,13 +93,12 @@ testapp = executable( test('first_and_only_test', testapp) ``` +### Plain Makefiles -### Plain Makefiles ### +Since `pkg-config` is a small Unix command-line utility, it can be used in +handwritten `Makefile`s too: -Since `pkg-config` is a small Unix command-line utility, it can be used -in handwritten `Makefile`s too: - -``` Makefile +```Makefile GTEST_CFLAGS = `pkg-config --cflags gtest_main` GTEST_LIBS = `pkg-config --libs gtest_main` @@ -120,12 +116,11 @@ testapp.o: samples/sample3_unittest.cc $(CXX) $(CPPFLAGS) $(CXXFLAGS) $< -c -o $@ $(GTEST_CFLAGS) ``` - -### Help! pkg-config can't find GoogleTest! ### +### Help! pkg-config can't find GoogleTest! Let's say you have a `CMakeLists.txt` along the lines of the one in this -tutorial and you try to run `cmake`. It is very possible that you get a -failure along the lines of: +tutorial and you try to run `cmake`. It is very possible that you get a failure +along the lines of: ``` -- Checking for one of the modules 'gtest_main' @@ -135,9 +130,9 @@ CMake Error at /usr/share/cmake/Modules/FindPkgConfig.cmake:640 (message): These failures are common if you installed GoogleTest yourself and have not sourced it from a distro or other package manager. If so, you need to tell -pkg-config where it can find the `.pc` files containing the information. -Say you installed GoogleTest to `/usr/local`, then it might be that the -`.pc` files are installed under `/usr/local/lib64/pkgconfig`. If you set +pkg-config where it can find the `.pc` files containing the information. Say you +installed GoogleTest to `/usr/local`, then it might be that the `.pc` files are +installed under `/usr/local/lib64/pkgconfig`. If you set ``` export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig |