Skip to content

Make svector installable, and consumable from meson - #98

Merged
martinus merged 1 commit into
mainfrom
cmake-install
Aug 5, 2026
Merged

Make svector installable, and consumable from meson#98
martinus merged 1 commit into
mainfrom
cmake-install

Conversation

@martinus

@martinus martinus commented Aug 5, 2026

Copy link
Copy Markdown
Owner

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_subdirectory subset. Neither build system had a single install(), export set, package config or version file, so:

  • find_package(svector) did not work after an install
  • a distribution had no install rule to call
  • meson users could not consume this at all — no declare_dependency, no override_dependency

There was a fossil of the abandoned attempt as well: CMakeLists.txt referenced $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> without ever including GNUInstallDirs, 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 because PROJECT_IS_TOP_LEVEL needs 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(), 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, matching the header's own semver comment. ARCH_INDEPENDENT is 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-config file is installed too — the issue listed it as optional, but it is what non-CMake and distribution consumers actually reach for.

Meson

declare_dependency plus meson.override_dependency means a parent project's dependency('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

result
cmake --install to a prefix header, svectorConfig.cmake, svectorConfigVersion.cmake, svectorTargets.cmake, svector.pc
find_package(svector 1 REQUIRED) from a separate project configures, builds, runs
find_package(svector 2.0 REQUIRED) refused
find_package(svector 99 REQUIRED) refused
existing add_subdirectory path unchanged, still works
pkg-config --modversion svector 1.3.0, correct -I
meson as a subproject of another project builds and runs
meson install header at include/ankerl/svector.h
meson test suite unchanged, green

CI

The cmake-consumer job now 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 installed, 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 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

#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>
@martinus
martinus merged commit 56e8724 into main Aug 5, 2026
13 checks passed
@martinus
martinus deleted the cmake-install branch August 5, 2026 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make svector installable: CMake install/export rules and find_package support

1 participant