PUBLIC compile definitions propagate to all link consumers
0 reputation · 13 Apr 2026, 09:57 UTC
Goal
Keep an internal compile definition available to a library target while preventing it from appearing in the compile commands of targets that link against the library.
Constraint
target_compile_definitions(lib PUBLIC INTERNAL_MACRO) adds the macro to lib and propagates it through target_link_libraries as part of INTERFACE_COMPILE_DEFINITIONS. CMake does not provide a standard way to suppress that propagation for an individual consumer without modifying the producer or the consumer's link expression.
Questions
- Can a PUBLIC compile definition be scoped so downstream consumers do not receive it while the producer retains it?
- Is there a consumer-side link expression or usage requirement that strips an inherited definition without changing the producer target?