What this thread does
Do first: classify each target_include_directories requirement as PUBLIC when both the target and its consumers need it, PRIVATE for the target alone, or INTERFACE for consumers alone.
Short answer
As of October 2026, CMake 4.4.5 was available for download (Kitware announcement, October 29). Compile requirements travel through target dependencies; merely creating two targets does not connect them. Give consumers the library target with target_link_libraries (reference).
Choose / don't choose
PUBLIC: choose for include paths or definitions needed to compile public headers and the library implementation; don't publish internal-only switches.PRIVATE: choose for the target'sINCLUDE_DIRECTORIES; don't use it for an include path required by a consumer's public-header includes (include scope, definition scope).INTERFACE: choose for a header-onlyadd_library(... INTERFACE)target with no compiled implementation; don't attachPUBLICorPRIVATEcompile requirements to that interface library (buildsystem).
Not for: compiler discovery failures on macOS; see mac-invalid-active-developer-path-git-clang-stop-working-after-update.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
target_include_directories | PUBLIC populates INCLUDE_DIRECTORIES and INTERFACE_INCLUDE_DIRECTORIES; explicit scope required | CMake 4.4.5 | include scope |
target_compile_definitions | PRIVATE and PUBLIC populate COMPILE_DEFINITIONS; PUBLIC and INTERFACE populate INTERFACE_COMPILE_DEFINITIONS | CMake 4.4.5 | definitions |
add_library | INTERFACE for a header-only library; attach compile requirements with INTERFACE | CMake 4.4.5 | interface libraries |
target_link_libraries | Consumer links the producer target; PRIVATE consumes its interface locally, PUBLIC also passes the dependency onward | CMake 4.4.5 | link scope |
CMAKE_DEBUG_TARGET_PROPERTIES | Debuggable properties include INCLUDE_DIRECTORIES and COMPILE_DEFINITIONS | CMake 4.4.5 | property origins |
Order of operations
1. Define the producer with add_library and consumer with add_executable before modifying those targets; the named target must already exist and must not be an alias (include, link). 2. Attach the producer's include/definition requirements with the scopes above. A clear declaration order is producer, its requirements, consumer, then dependency; requirement attachment need not precede the dependency declaration as a separate CMake lifecycle rule. 3. Connect the consumer with target_link_libraries(consumer PRIVATE producer). Libraries and targets following PRIVATE are linked to, but are not made part of the link interface. Link a library target to propagate its usage requirements (link).
Known failures and fixes
| Error or symptom | Cause | Fix | Source |
|---|---|---|---|
| Downstream missing header; compiler wording varies | PRIVATE and PUBLIC populate INCLUDE_DIRECTORIES; PUBLIC and INTERFACE populate INTERFACE_INCLUDE_DIRECTORIES | Enable CMAKE_DEBUG_TARGET_PROPERTIES for the relevant include property, trace consumer → producer in target_link_libraries, and expose the required path with PUBLIC (or INTERFACE on a header-only target). Inspect the consumer compile invocation for the propagated path | scope, propagation |
| Implementation macro leaks into consumer compilation | PUBLIC and INTERFACE populate INTERFACE_COMPILE_DEFINITIONS | Move the implementation-only definition to PRIVATE; keep a definition public only if consumers need it to interpret the API | definitions |
Cannot specify include directories for target | The named target does not exist yet, or its name is wrong | Define the target first and use its actual target name before attaching include requirements | Azmuth, April 8, 2023, stable command |
The two symptom rows are diagnostic deductions from the documented property rules, not literal compiler diagnostics. Sirish Kumar Bethala's scope question records the same three-way distinction; the current command references determine the settings above.
Missing
- No universal missing-header error text: compiler, header name and include spelling determine the diagnostic.
Checked
2026-11-12; CMake 4.4.5; Kitware release announcement, stable include/definition/link references, buildsystem manual Bethala's dated scope question and Azmuth's target-order report read. No configure or compile commands executed.
Started from a post by @Kitware, packaged by the editor. Original post