Make svector installable, and consumable from meson - #98
Merged
Conversation
#31 asked in 2022 for nlohmann/json style CMake integration and was closed four days later with "Should work now". What shipped was the add_subdirectory subset: no install rule, no export set, no package config, no version file, in either build system. So find_package(svector) did not work, a distribution had nothing to call, and meson users could not consume this at all. There was a fossil of the abandoned attempt too. CMakeLists.txt referenced $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> without ever including GNUInstallDirs, so that expanded to nothing. It was harmless only because nothing installed or exported. CMake now defines the target unconditionally and installs when svector is the project being built. It used to define the target only when included, so configuring this repository on its own produced literally nothing -- which is what the reporter of #48 ran into and reasonably read as the project being broken. A parent that pulled us in with add_subdirectory still gets no install rules of ours, and CMake still never builds the tests. The package version comes from project(), which lint-version.py already keeps in step with the ANKERL_SVECTOR_VERSION_* macros, so a package cannot claim a version the header does not. Compatibility is SameMajorVersion, which is what the header's own semver comment promises. A pkg-config file is installed for the consumers that use neither build system, which is most of what a distribution packages. On the meson side, declare_dependency plus override_dependency means a parent's dependency('svector') resolves through a wrap, and the test suite and header install are now skipped when we are a subproject rather than imposed on whoever included us. The cmake-consumer CI job covers both paths: add_subdirectory, then an install followed by find_package against the prefix, plus pkg-config. It also asserts that find_package refuses a version that is not there, because the happy path passing says nothing about whether the version is checked at all. It asks for major version 1 rather than an exact one so it needs no editing per release. Closes #89. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Closes #89.
What was missing
#31 asked in 2022 for nlohmann/json style CMake integration and was closed four days later with "Should work now". What shipped was the
add_subdirectorysubset. Neither build system had a singleinstall(), export set, package config or version file, so:find_package(svector)did not work after an installdeclare_dependency, nooverride_dependencyThere was a fossil of the abandoned attempt as well:
CMakeLists.txtreferenced$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>without ever includingGNUInstallDirs, so it expanded to nothing. Harmless only because nothing installed or exported.CMake
The target is now defined unconditionally. It used to exist only when svector was pulled in with
add_subdirectory, which meant configuring this repository on its own produced literally nothing — precisely what the reporter of #48 hit and reasonably read as the project being broken. Install rules are gated on being top level instead, spelled by hand becausePROJECT_IS_TOP_LEVELneeds CMake 3.21 and the floor here is 3.12. A parent that included us still gets none of our install rules, and CMake still never builds the tests.The package version comes from
project(), whichlint-version.pyalready keeps in step with theANKERL_SVECTOR_VERSION_*macros, so a package cannot claim a version the header does not. Compatibility isSameMajorVersion, matching the header's own semver comment.ARCH_INDEPENDENTis added only when CMake is new enough for it, since for a header-only library a differing word size is not a real incompatibility.A
pkg-configfile is installed too — the issue listed it as optional, but it is what non-CMake and distribution consumers actually reach for.Meson
declare_dependencyplusmeson.override_dependencymeans a parent project'sdependency('svector')resolves through a wrap. The test suite and the header install are now skipped when we are a subproject, rather than imposed on whoever included us.Verified locally
cmake --installto a prefixsvectorConfig.cmake,svectorConfigVersion.cmake,svectorTargets.cmake,svector.pcfind_package(svector 1 REQUIRED)from a separate projectfind_package(svector 2.0 REQUIRED)find_package(svector 99 REQUIRED)add_subdirectorypathpkg-config --modversion svector1.3.0, correct-Imeson installinclude/ankerl/svector.hCI
The
cmake-consumerjob now covers both paths:add_subdirectory, then an install followed byfind_packageagainst the prefix, plus pkg-config. It also asserts thatfind_packagerefuses a version that is not installed, because the happy path passing says nothing about whether the version is checked at all. It asks for major version1rather than an exact version, so it needs no editing at each release.Note
This is not a step toward moving the build to CMake. Meson stays the development build system — it carries the sanitizer and hardening configurations, the wrap dependencies, the benchmark separation, the 32 bit leg and the libFuzzer target, none of which have cheap CMake equivalents. This only makes the library consumable by people who do not care what it is built with.
Worth a separate nudge once this lands: ConanCenter still ships
svector/1.0.3, three releases behind.🤖 Generated with Claude Code