Skip to content

Conversation

@mwoehlke
Copy link
Member

@mwoehlke mwoehlke commented Dec 9, 2025

Add an attribute to allow components to specify that a requirement should only be considered at compile-time. This is the opposite of the already existing link_requires attribute.

In particular, this allows CPS to support CMake's COMPILE_ONLY generator expression. Several likely use-cases have been cited.

@dcbaker
Copy link
Collaborator

dcbaker commented Dec 9, 2025

This would be, for example, with something like something used with C's #embed?

@mathstuf
Copy link

mathstuf commented Dec 9, 2025

It is intended to model how a project is used by, say, systemd where it will build with the headers, but dlopen the libraries before actual usage at runtime. Other places it is used:

  • Python extensions should not link to libpython but instead expect the symbols to be provided by the interpreter loading the extension;
  • glad loading rendering backends at runtime;
  • Derelict D library projects which provide D bindings from headers, but defers loading the library to runtime;
  • wi4mpi which determines the MPI to use at runtime.

@mwoehlke-kitware
Copy link
Member

@dcbaker, maybe, but I'm not sure how; that would usually be present in a source file, not a public header.

The example I ran into is VTK, which exports a compile-only dependency on X11 (which is loaded dynamically). @mathstuf or @nickelpro might be able to give better information, but as I understand it, the likely use-case is that SomeLibrary's API exposes data types of SomeDependency, but doesn't link to SomeDependency because it is dynamically loaded at run-time instead. Something about Python was also cited; I think following that model (except in that case, it would be Python dynamically loading the library rather than the library dynamically loading Python).

@dcbaker
Copy link
Collaborator

dcbaker commented Dec 9, 2025

Ah, that makes sense. Thanks! (and this has a +1 from me)

Add an attribute to allow components to specify that a requirement should
only be considered at compile-time. This is the opposite of the already
existing `link_requires` attribute.
@mwoehlke mwoehlke merged commit c82e471 into cps-org:master Dec 23, 2025
6 checks passed
@mwoehlke mwoehlke deleted the compile_requires branch December 23, 2025 16:39
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.

4 participants