r/cpp • • Sep 24 '26

Why we should standardise on CPS

To enable any collaboration in the industry, some "social contract" must be signed by all of us.

One of the rules of this contract is binary packaging, to put it simply, if you are a library author you need to either have clean definition on what package you expect to consume or have a "scriptless" implementation like imgui.

If the library exports a pkgconf package, but its dependency exports something else your build will not work. Why should it, what you do makes no sense.

Currently I'm literally forced to package every single dependency I have, which is fine in principle as you want to own your dependencies for security and licensing reasons... But I CAN'T UPSTREAM MY CHANGES which is not fine.

The current situation is a disease, please do remember my talk when you try to build a library like dawn or SDL and it vendors dozens of libraries to create a giant shared library after a long slow build.

0 Upvotes

70 comments sorted by

View all comments

0

u/ABlockInTheChain Oct 20 '26

CPS might be great someday but it isn't even usable yet.

It sounds ideal as a solution for transitive dependencies. My current clunky-but-working solution is to consolidate all dependencies into a mylib-find-dependencies.cmake. I run that script to configure mylib but also install it alongside the cmake target files and set up some hackery such that find_package(mylib CONFIG) will execute mylib-find-dependencies.cmake.

Inconvenient to set up initially but reliable and low maintenance afterward.

The first thing that happened when I added install(PACKAGE_INFO ... to mylib is a string of errors about things I can't fix and shouldn't need to care about:

CMake Error in CMakeLists.txt:
  Target "mylib" references target "Qt6::Core", which
  comes from the "Qt6Core" package, but does not belong to the package's
  canonical namespace ("Qt6Core::").  This is not allowed.

...

CMake Error in CMakeLists.txt:
  Target "mylib" references target "Boost::headers",
  which comes from the "boost_headers" package, but does not belong to the
  package's canonical namespace ("boost_headers::").  This is not allowed.

That's great. CPS clearly isn't ready to use yet so I guess I'll check back in a year or two.

0

u/not_a_novel_account cmake dev Oct 20 '26

The thing you're trying to do here will never work with install(PACKAGE_INFO) by design, so it really has no bearing on the readiness of CPS.

There is a very good argument to be made that CPS has deficiencies relative to its goals, but a technology cannot be deficient in something it is designed not to do.

1

u/ABlockInTheChain Oct 20 '26

CMake has shown a consistent trend in recent years of loudly announcing new technologies then declaring NOTABUG/WONTFIX when people actually try to use them and notice what has been delivered does not match what was advertised.

1

u/not_a_novel_account cmake dev Oct 20 '26

PACKAGE_INFO was never advertised to do what you're trying to do here. This will always been the realm of CMakeConfig packages.

1

u/ABlockInTheChain Oct 20 '26

Then document this restriction.

The PACKAGE_INFO form generates and installs a Common Package Specification file which describes installed targets such that they can be consumed by another project. Target installations are associated with the export <export-name> using the EXPORT option of the install(TARGETS) signature documented above. Unlike install(EXPORT), this information is not expressed in CMake code, and can be consumed by tools other than CMake. When imported into another CMake project, the imported targets will be prefixed with <package-name>::. By default, the generated file will be called <package-name>[-<appendix-name>].cps. If LOWER_CASE_FILE is given, the package name as it appears on disk (in both the file name and install destination) will be first converted to lower case.

Nowhere in this description does it mention that it only works for targets that have no dependencies, or possibly only for dependencies that were discovered via perfectly-formatted cps files.

Then in the project blog posts make sure to mention, "Actually if you have any dependencies at all you can't use CPS until all your dependencies also use CPS. We created an unsolvable bootstrapping paradox. Sorry."

1

u/not_a_novel_account cmake dev Oct 20 '26

That's not what's happening here, CPS requires package name and namespace to match.

CMake will bridge the CMakeConfig-CPS divide where that is true. It isn't for your upstream dependencies. If you think that can be better expressed in the docs somewhere, MRs welcome.

But ya, failing to point out everything that fails is not a claim that Qt is useable with PACKAGE_INFO.

1

u/ABlockInTheChain Oct 20 '26

It could just be a single sentence: "All targets included in and referenced by the installed set must conform to Common Package Specification naming rules, including targets discovered via find_package."

1

u/not_a_novel_account cmake dev Oct 20 '26

Agreed, give it a shot.

1

u/ABlockInTheChain Oct 20 '26

What a perfect example of how CMake has earned its reputation.

"Yes, our documentation is incomplete. No, we are not going to fix it. I dare you to contribute a fix and see what happens to the MR."

1

u/not_a_novel_account cmake dev Oct 20 '26

The dark and menacing act of encouraging developers to make the trivial improvements they personally want to see in the open source tools that they use.

→ More replies

0

u/TheRavagerSw Oct 20 '26

I packaged like 110 repositories. I assure if you it works if you use it right