Repository navigation
build: install a self-contained package (archive API in #101) - #104
Conversation
The install rule installed headers flat, omitted the headers block_store.h depends on, and linked lz4 through a BUILD_INTERFACE, so the exported target had no compression dependency. A downstream find_package(ctar) could neither compile nor link. Bundle the LZ4 and xxhash objects into libctar.a with an OBJECT library, install only the public include/ctar headers, expose the ctar::ctar target with cxx_std_23, fix the pkg-config library name and add -pthread, and move GNUInstallDirs ahead of the targets. Add ctar::VersionString() as a real library symbol. Add a consumer smoke test that installs to a private prefix, builds a tiny find_package(ctar) project, runs it, and checks that LZ4 symbols are inside libctar.a. Run it on Linux GCC/Clang and macOS in CI. Refs #83
blocksmith314
left a comment
There was a problem hiding this comment.
Review
The static-library bundling and CMake target mostly work, and the consumer smoke test passes. The installed package is not yet consumable/clean, though. I would not merge yet.
1. The public header exposes no archive API
include/ctar/ctar.h only includes <ctar/version.h>. api/ctar.h and src/core/block_store.h are deliberately not installed, so a downstream project cannot declare a BlockStore or call pack/unpack; the archive exports the symbols (nm shows ctar::BlockStore::PackPipeline), but the headers do not. The consumer test only calls VersionString(), so it proves the archive links, not that it is usable.
Either install a real public API (rewrite/install the headers preserving paths), or explicitly scope this package to version/CLI use and adjust the title/docs. A consumer test that performs an actual pack/unpack through the installed headers would catch this.
2. cmake --install installs gtest/gmock
With the default BUILD_TEST=ON, the install prefix contains:
include/gtest/*, include/gmock/*
libgtest.a, libgtest_main.a, libgmock.a, libgmock_main.a
lib/pkgconfig/gtest*.pc
That contradicts the PR's listed install tree and pollutes downstream packages. Set INSTALL_GTEST OFF before add_subdirectory/FetchContent_MakeAvailable (tests still use gmock), and make the consumer test assert that no test artifacts are installed.
3. ctar.pc is not relocatable
@prefix@ is expanded from CMAKE_INSTALL_PREFIX at configure time. Installing with cmake --install ... --prefix /tmp/ctar-prefix produces:
prefix=/usr/local
libdir=${exec_prefix}/lib
includedir=${prefix}/include
so pkg-config --cflags ctar returns -I/usr/local/include, not the installed prefix. Use a relocatable prefix, e.g.:
prefix=${pcfiledir}/../..
4. ctar.pc does not provide the required C++ standard
version.h uses std::format, but pkg-config --cflags ctar returns only -I.... A default C++17 consumer fails:
error: no member named 'format' in namespace 'std'
Add -std=c++23 to Cflags (consistent with the exported cxx_std_23 feature), or make the public header C++17-compatible.
Minor
- Document that
LZ4_*/XXH*symbols are now insidelibctar.aand can collide with a consumer's own lz4/xxhash (issue #83 called this out). cmake/ctar.pc.instill has no trailing newline.- The consumer test should also exercise
pkg-configand verify the package contains no gtest/gmock files.
Verified locally: Release ctest 201/201, CMake consumer smoke test passes, CI 5/5 green. The failures above are reproducible from the installed prefix.
- Keep googletest out of the install prefix: set INSTALL_GTEST OFF before the local add_subdirectory or FetchContent path, so the prefix no longer contains gtest/gmock headers, archives or .pc files.
- Make ctar.pc relocatable via ${pcfiledir} and add -std=c++23 to Cflags (the public version header uses std::format).
- Move the version header to include/ctar/version.h as the public single source of truth; src/core/version.h now forwards to it, and cmake/utils.cmake parses the public path.
- Extend the consumer smoke test: reject gtest/gmock in the prefix, verify pkg-config resolves the installed prefix, and compile/run a pkg-config consumer.
- Document that the public API is version-only until #101 and note the bundled LZ4/XXH symbol collision.
Refs #83
blocksmith314
left a comment
There was a problem hiding this comment.
Re-reviewed e215424.
The concrete packaging bugs from the last review are fixed:
INSTALL_GTEST OFFkeeps gtest/gmock out of the install prefix (verified: onlybin/ctar,include/ctar/{ctar.h,version.h},lib/libctar.a,lib/cmake/ctar/*,lib/pkgconfig/ctar.pc)ctar.pcnow derivesprefixfrom${pcfiledir}, socmake --install --prefix ...is relocatableCflagsincludes-std=c++23; the pkg-config consumer compiles, links and runsversion.his the single public source of truth; the internal header forwards to it- collision note and README scope note added
- the smoke test checks pollution, pkg-config and LZ4 symbols
Verified locally: Release ctest 201/201, scripts/consumer_smoke_test.sh passes (including pkg-config), CI 5/5 green.
One remaining scope blocker, not a code bug:
include/ctar/ctar.h still exposes only version information. The actual archive API (ctar::BlockStore, pack/unpack) is not declared by any installed header; nm shows the symbols, but a downstream cannot call them. The consumer test only calls VersionString(). README now honestly says the archive read API is tracked in #101, but the PR still says Closes #83 ("installed CMake package cannot be consumed") and the title/body claim a usable package.
Please choose one:
- Do not close #83 with this PR; re-scope it to packaging/version smoke test and point the archive API to #101, or
- Install a real public API header for the archive operations (or otherwise expose the supported API) before closing #83.
Once that scope is settled, the packaging mechanics look good from my side.
e215424 to
e160e97
Compare
Summary
Make
cmake --installproduce a package a downstream project can actually consume.libctar.a:lz4becomes an OBJECT library (lz4.c,lz4hc.c,xxhash.c;lz4frame.cdropped because nothing uses the frame API) whose objects are merged into the static archive. Consumers no longer need lz4 installed, and the exported target has no compression dependency.include/ctar/ctar.handinclude/ctar/version.h(the single source of truth for tool/format versions). Internalapi/,src/core/andsrc/utils/headers are no longer installed.src/core/version.hforwards to the public header for internal includes.ctar::ctar(install namelibctar.a),cxx_std_23propagated as a PUBLIC compile feature;ctar_cli_libis no longer exported.include(GNUInstallDirs)moved ahead of the targets;ctar.pcuses-lctar,Libs.private: -pthreadand a relocatableprefix=${pcfiledir}/...;Cflagscarries-std=c++23because the public header usesstd::format;ctarConfig.cmakekeeps onlyfind_dependency(Threads);INSTALL_GTEST OFFkeeps googletest out of the install prefix.ctar::VersionString()is defined in the library so a consumer test can prove it linked the archive, not just the headers.scripts/consumer_smoke_test.shinstalls to a private prefix, configures/buildstest/consumerwithfind_package(ctar CONFIG REQUIRED), runs it, compiles and runs a pkg-config consumer, verifies the pkg-config prefix resolves to the install prefix, asserts that no gtest/gmock files were installed, and checks withnmthatLZ4_*symbols are insidelibctar.a. The CI matrix runs it on Linux GCC, Linux Clang and macOS.<ctar/ctar.h>andctar::ctar.No archive-format change.
Scope
This PR delivers the packaging foundation and the version API only. The archive read API (
ctar::ArchiveReader, #101) will be added to the same installed header layout without changing it, and the consumer test will be extended then to perform a real pack/unpack through the installed headers. Installing the internalBlockStoreheaders was rejected on purpose: internal types are not the long-term public API.#83 therefore stays open: this PR fixes the packaging mechanics, and #101 closes it once the archive API is exposed through the installed headers.
Bundled
LZ4_*/XXH*symbols are part oflibctar.aand may collide with a consumer that links its own copies; this is documented in the README.Tests
ctest: 201/201 passedctest: 201/201 passedBUILD_TEST=ON) → install → consumer: passed, including the no-gtest/gmock assertion, the pkg-config relocation check, and the bundled-lz4 checkbin/ctar,include/ctar/{ctar.h,version.h},lib/libctar.a,lib/cmake/ctar/*,lib/pkgconfig/ctar.pcPerformance gate
d327f64→e215424), 10 unpack runs: +0.7% wall time / -1.4% peak RSS.Refs #83