Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
4360e426
Commit
4360e426
authored
Oct 07, 2019
by
Gennadiy Civil
Browse files
Merge pull request #2491 from SoapGentoo:fix-GNUInstallDirs-pkg-config
PiperOrigin-RevId: 273342665
parents
76a560c8
b96832a4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
12 deletions
+86
-12
googlemock/cmake/gmock.pc.in
googlemock/cmake/gmock.pc.in
+2
-3
googlemock/cmake/gmock_main.pc.in
googlemock/cmake/gmock_main.pc.in
+2
-3
googletest/cmake/gtest.pc.in
googletest/cmake/gtest.pc.in
+2
-3
googletest/cmake/gtest_main.pc.in
googletest/cmake/gtest_main.pc.in
+2
-3
googletest/docs/pkgconfig.md
googletest/docs/pkgconfig.md
+78
-0
No files found.
googlemock/cmake/gmock.pc.in
View file @
4360e426
prefix=${pcfiledir}/../..
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: gmock
Name: gmock
Description: GoogleMock (without main() function)
Description: GoogleMock (without main() function)
...
...
googlemock/cmake/gmock_main.pc.in
View file @
4360e426
prefix=${pcfiledir}/../..
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: gmock_main
Name: gmock_main
Description: GoogleMock (with main() function)
Description: GoogleMock (with main() function)
...
...
googletest/cmake/gtest.pc.in
View file @
4360e426
prefix=${pcfiledir}/../..
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: gtest
Name: gtest
Description: GoogleTest (without main() function)
Description: GoogleTest (without main() function)
...
...
googletest/cmake/gtest_main.pc.in
View file @
4360e426
prefix=${pcfiledir}/../..
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: gtest_main
Name: gtest_main
Description: GoogleTest (with main() function)
Description: GoogleTest (with main() function)
...
...
googletest/docs/pkgconfig.md
View file @
4360e426
...
@@ -139,3 +139,81 @@ export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
...
@@ -139,3 +139,81 @@ export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
```
```
pkg-config will also try to look in
`PKG_CONFIG_PATH`
to find
`gtest_main.pc`
.
pkg-config will also try to look in
`PKG_CONFIG_PATH`
to find
`gtest_main.pc`
.
### Using pkg-config in a cross-compilation setting
Pkg-config can be used in a cross-compilation setting too. To do this, let's
assume the final prefix of the cross-compiled installation will be
`/usr`
, and
your sysroot is
`/home/MYUSER/sysroot`
. Configure and install GTest using
```
mkdir build && cmake -DCMAKE_INSTALL_PREFIX=/usr ..
```
Install into the sysroot using
`DESTDIR`
:
```
make -j install DESTDIR=/home/MYUSER/sysroot
```
Before we continue, it is recommended to
**always**
define the following two
variables for pkg-config in a cross-compilation setting:
```
export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=yes
export PKG_CONFIG_ALLOW_SYSTEM_LIBS=yes
```
otherwise
`pkg-config`
will filter
`-I`
and
`-L`
flags against standard prefixes
such as
`/usr`
(see https://bugs.freedesktop.org/show_bug.cgi?id=28264#c3 for
reasons why this stripping needs to occur usually).
If you look at the generated pkg-config file, it will look something like
```
libdir=/usr/lib64
includedir=/usr/include
Name: gtest
Description: GoogleTest (without main() function)
Version: 1.10.0
URL: https://github.com/google/googletest
Libs: -L${libdir} -lgtest -lpthread
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -lpthread
```
Notice that the sysroot is not included in
`libdir`
and
`includedir`
! If you try
to run
`pkg-config`
with the correct
`PKG_CONFIG_LIBDIR=/home/MYUSER/sysroot/usr/lib64/pkgconfig`
against this
`.pc`
file, you will get
```
$ pkg-config --cflags gtest
-DGTEST_HAS_PTHREAD=1 -lpthread -I/usr/include
$ pkg-config --libs gtest
-L/usr/lib64 -lgtest -lpthread
```
which is obviously wrong and points to the
`CBUILD`
and not
`CHOST`
root. In
order to use this in a cross-compilation setting, we need to tell pkg-config to
inject the actual sysroot into
`-I`
and
`-L`
variables. Let us now tell
pkg-config about the actual sysroot
```
export PKG_CONFIG_DIR=
export PKG_CONFIG_SYSROOT_DIR=/home/MYUSER/sysroot
export PKG_CONFIG_LIBDIR=${PKG_CONFIG_SYSROOT_DIR}/usr/lib64/pkgconfig
```
and running
`pkg-config`
again we get
```
$ pkg-config --cflags gtest
-DGTEST_HAS_PTHREAD=1 -lpthread -I/home/MYUSER/sysroot/usr/include
$ pkg-config --libs gtest
-L/home/MYUSER/sysroot/usr/lib64 -lgtest -lpthread
```
which contains the correct sysroot now. For a more comprehensive guide to also
including
`${CHOST}`
in build system calls, see the excellent tutorial by Diego
Elio Pettenò: https://autotools.io/pkgconfig/cross-compiling.html
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment