cmake: make the installed package consumable - #19
Open
petlenz wants to merge 2 commits into
Open
Conversation
added 2 commits
August 23, 2026 00:58
Two defects, both invisible to every in-tree build because those use
BUILD_INTERFACE, which was always correct.
1. include(GNUInstallDirs) sat 18 lines AFTER the $<INSTALL_INTERFACE:
${CMAKE_INSTALL_INCLUDEDIR}> that depends on it. ${} expands when the line
is read, so the variable was empty and the generator expression collapsed to
$<INSTALL_INTERFACE:>. The exported target carried no include directory at
all: consumers could find the package and not compile against it. An empty
INSTALL_INTERFACE is legal, so nothing warned.
The install(FILES ... DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/...) call is
after the include, which is why the headers landed correctly and only the
export was wrong.
2. install(FILES) flattened the tree: include/numsim-core/property_graph/*.h
was installed beside the top-level headers, so
#include <numsim-core/property_graph/property_traits.h> could not resolve.
It also only installed the files listed in ${PROJECT_NAME}_HEADER -- 13 of
the 23 headers present. install(DIRECTORY ... FILES_MATCHING PATTERN "*.h")
installs all 23 and preserves the structure.
Verified end to end: an external project that calls
find_package(numsim-core) and includes a property_graph header now configures,
compiles and runs. Before, it failed at configure on the missing include
directory and then, past that, on the missing subdirectory.
Fixes #18.
install(DIRECTORY) replaced the only use of ${PROJECT_NAME}_HEADER, leaving it
set and referenced nowhere. Removing it is the point of the change: a
hand-maintained list of headers that must be edited whenever a file is added is
exactly what silently installed 13 of 23.
Member
Author
|
Critical review. One finding, fixed in the branch.
What I checked and could not break:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #18 — and a second defect found while verifying the first.
Both were invisible to every in-tree build, because those use
BUILD_INTERFACE, which was always correct.1. The exported target had no include directory
include(GNUInstallDirs)sat 18 lines after the$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>that depends on it.${}expands when the line is read, so the variable was empty and the generator expression collapsed to$<INSTALL_INTERFACE:>:Consumers could find the package and not compile against it. An empty
INSTALL_INTERFACEis legal, so nothing warned. Theinstall(FILES ... DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/...)call is after the include, which is why the headers landed correctly and only the export was wrong.2. Headers installed flattened, and most were not installed at all
install(FILES)puts everything in one directory, soinclude/numsim-core/property_graph/*.hlanded beside the top-level headers and#include <numsim-core/property_graph/property_traits.h>could not resolve. It also installed only the files listed in${PROJECT_NAME}_HEADER— 13 of the 23 headers in the tree.install(DIRECTORY ... FILES_MATCHING PATTERN "*.h")installs all of them and preserves the structure. It also stops the list going stale: a new header no longer has to be added in two places.Verified end to end
A three-line external project that calls
find_package(numsim-core)and includes aproperty_graphheader now configures, compiles and runs. Before this it failed at configure on the missing include directory, and past that on the missing subdirectory.Checked against the downstream case too: numsim-materials had its own separate packaging defect (its generated Config re-found none of its dependencies). With that fixed and these two, a consumer builds against an installed numsim-materials for the first time.
Worth considering separately
Neither project's CI runs
installor builds a consumer against the result, which is why all of this sat behind permanently green builds. A CI step that installs and compiles a three-line consumer would have caught every one of these.