RPM does not include <exportname>-<config>.cmake, results in IMPORTED_LOCATION not set for imported target

I have a project where I export targets to make them findable via find_package(ADH-APIS CONFIG).

This all works fine if done via:

$ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/adh-apis
$ cmake --build build
$ cmake --install build

All expected files are there and a dependent project can use them without issue:

-- Installing: /tmp/adh-apis/share/cmake/ADH-APIS/ADH-APISTargets.cmake
-- Installing: /tmp/adh-apis/share/cmake/ADH-APIS/ADH-APISTargets-release.cmake
-- Installing: /tmp/adh-apis/share/cmake/ADH-APIS/ADH-APISConfig.cmake
-- Installing: /tmp/adh-apis/share/cmake/ADH-APIS/ADH-APISConfigVersion.cmake

However, when building an RPM, the share/cmake/ADH-APIS/ADH-APISTargets-release.cmake is not included in the rpm, which results in the mentioned error:

$ rpm -qlp ADH-APIS-2.1.0-Linux.rpm | grep ADH-APIS

Any idea how to fix this issue?

I found that when running

$ cmake --build build --target package

the file is included, but not when running cpack manually in the build directory like this:

$ cd build
$ cpack -G RPM -C CPackConfig.cmake

Can you provide a minimal project that reproduces your problem? It may be something about your system which causes RPM to behave differently, so having a minimal project that someone else can run on a different system may help to confirm that.

Thanks for your reply. I sat down and created the minimal example:

The issue is as described above: the package works when creating it via cmake --build build --target package but fails due to not including the fibTargets-release.cmake when build using cd build; cpack -G RPM -C CPackConfig.cmake

Ok, done, I forgot to add the part with manually invoking cpack…

Here is a log of the CI that shows it failing when using cpack:

and here succeeding with using cmake --build build --target package:

Thanks, that allowed me to track down the problem. You are invoking cpack incorrectly. The -C option expects a configuration name like Debug, Release, etc., not the name of a cpack configuration file. You don’t actually need to specify the file anyway, it will use CPackConfig.cmake by default. If you did need to specify a different file for some reason, the --config option is what you would use for that. It is unfortunate that the term “configuration” has multiple meanings here, but it is hard to avoid.

1 Like

Oh wow, -C is not an alias for --config.

Thanks a lot!