[Rpm-maint] [rpm-software-management/rpm] Build: Add include dirs to exported lib targets (PR #3222)
Frank Dana
notifications at github.com
Tue Jul 30 15:00:54 UTC 2024
Each library target's exported `INTERFACE_INCLUDE_DIRECTORIES` list, as written into the `rpm-targets.cmake` export file, is controlled by the `PUBLIC` arguments supplied to `target_include_directories()` for the library target.
* Directories scoped with the `$<BUILD_INTERFACE>` generator expression will be included in the export file written to the build dir by `export(TARGETS...)`
* Directories scoped with `$<INSTALL_INTERFACE>` will be included in the `rpm-targets.cmake` file installed into the `${CMAKE_INSTALL_LIBDIR}/cmake/rpm/` configuration directory.
Providing `PUBLIC` include directory paths for both the build and install contexts is important, because without them the exported CMake configuration is useless to library consumers.
(If the build is installed into `/usr/` or `/usr/local` it won't matter, because the include directories required are the default `/usr/include` or `/usr/local/include/` paths. But an install targeted elsewhere with a `CMAKE_INSTALL_PREFIX` path needs an `INTERFACE_INCLUDE_DIRECTORIES` property of
`${CMAKE_INSTALL_INCLUDEDIR}/include` to correctly locate its installed includes.)
## Example build
```console
$ cmake -B _build -S . -DCMAKE_INSTALL_PREFIX=/tmp/rpm \
-DENABLE_PYTHON=0 -DWITH_DBUS=0
$ cmake --build _build
$ cmake --install _build
```
### Without this change
#### In `_build/rpm-targets.cmake`
* The `rpm::librpm` target's `INTERFACE_INCLUDE_DIRECTORIES` contains only `/usr/include` (from the `${POPT_INCLUDE_DIRS}` variable).
* The other targets have no `INTERFACE_INCLUDE_DIRECTORIES` at all.
#### In `/tmp/rpm/lib64/cmake/rpm-targets.cmake`
* The `rpm::librpm` target's `INTERFACE_INCLUDE_DIRECTORIES` contains only `/usr/include`.
* The other targets have no `INTERFACE_INCLUDE_DIRECTORIES` at all.
### With this change
#### In `_build/rpm-targets.cmake`
* The `rpm::librpm` target's `INTERFACE_INCLUDE_DIRECTORIES` contains
both `/usr/include` and (the expansion of) `${CMAKE_SOURCE_DIR}/include`.
* The other targets also all have `INTERFACE_INCLUDE_DIRECTORIES` set to
the expansion of `${CMAKE_SOURCE_DIR}/include`.
#### In `/tmp/rpm/lib64/cmake/rpm-targets.cmake`
* The `rpm::librpm` target's `INTERFACE_INCLUDE_DIRECTORIES` contains
both `/usr/include` and `${_IMPORT_PREFIX}/include`, which corresponds
to `${CMAKE_INSTALL_PREFIX}/include` for the installed package.
* The other targets also all have `INTERFACE_INCLUDE_DIRECTORIES` set to
`${_IMPORT_PREFIX}/include`.
This means that the CMake `CONFIG`-mode exports now match the `rpm.pc` configuration provided by `pkg-config`. A downstream consumer's CMake build can use `find_package(rpm CONFIG)` to discover the `IMPORTED` `rpm::` targets from either the package build dir, or its installed path (even if directed to a non-standard location), and properly compile against the RPM libraries present in either of those locations.
You can view, comment on, or merge this pull request online at:
https://github.com/rpm-software-management/rpm/pull/3222
-- Commit Summary --
* Build: Add include dirs to exported lib targets
-- File Changes --
M build/CMakeLists.txt (6)
M lib/CMakeLists.txt (10)
M rpmio/CMakeLists.txt (6)
M sign/CMakeLists.txt (6)
-- Patch Links --
https://github.com/rpm-software-management/rpm/pull/3222.patch
https://github.com/rpm-software-management/rpm/pull/3222.diff
--
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/3222
You are receiving this because you are subscribed to this thread.
Message ID: <rpm-software-management/rpm/pull/3222 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20240730/c65e151a/attachment-0001.html>
More information about the Rpm-maint
mailing list