# CMake 4.1.2 not propagating include directories to target when linking with PUBLIC (compile\_commands.json)

**URL:** https://discourse.cmake.org/t/cmake-4-1-2-not-propagating-include-directories-to-target-when-linking-with-public-compile-commands-json/15432
**Category:** Code
**Tags:** os:linux
**Created:** [January 5, 2026, 2:38am UTC](https://discourse.cmake.org/t/cmake-4-1-2-not-propagating-include-directories-to-target-when-linking-with-public-compile-commands-json/15432 "2026-01-05T02:38:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![edog](https://discourse.cmake.org/user_avatar/discourse.cmake.org/edog/32/5830_2.png) [@edog](https://discourse.cmake.org/u/edog)
#### Post date: [January 5, 2026, 2:38am UTC](https://discourse.cmake.org/t/cmake-4-1-2-not-propagating-include-directories-to-target-when-linking-with-public-compile-commands-json/15432/1 "2026-01-05T02:38:17Z")

</div>

For some context I’ve tried this both on WSL2 on windows and an Ubuntu 24 Server VM running on a home server so its a reproducible issue

I’m using nix to pull cmake, glog, gcc, and other dependencies

CMake 4.1.2

GCC 15.2.0

Here is my main CMakeLists.txt:

```auto
cmake_minimum_required(VERSION 4.1.2)
project(Nexus VERSION 0.1)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

configure_file(config/config.h.in config/config.h)

# Dependencies
add_subdirectory(third-party)
find_package(glog REQUIRED)
get_target_property(GLOG_INC glog::glog INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(GLOG_SYS glog::glog INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
get_target_property(GLOG_COMPILE_DEFS glog::glog INTERFACE_COMPILE_DEFINITIONS)
get_target_property(GLOG_LINK_LIBS glog::glog INTERFACE_LINK_LIBRARIES)

message(STATUS "GLOG_INC = ${GLOG_INC}")
message(STATUS "GLOG_SYS = ${GLOG_SYS}")
message(STATUS "GLOG_COMPILE_DEFS = ${GLOG_COMPILE_DEFS}")
message(STATUS "GLOG_LINK_LIBS = ${GLOG_LINK_LIBS}")

# ImGui
file(GLOB IMGUI_SDL_SOURCES third-party/imgui/src/backends/imgui_impl_sdl*3.cpp)

# MAIN BUILD STUFF
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

file(GLOB_RECURSE SOURCES "src/**/*.cpp")
# message(STATUS "Found sources: ${SOURCES}")

add_library(nexus ${SOURCES} src/node/Node.h)
target_include_directories(nexus PUBLIC src)
target_include_directories(nexus PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")

target_include_directories(nexus PUBLIC "${PROJECT_BINARY_DIR}/config")
target_link_libraries(nexus PUBLIC glog::glog)

add_executable(gui runner.cpp)
target_link_libraries(gui PUBLIC nexus)

enable_testing()
add_subdirectory(tests)

```

Build output:

```auto
build-debug
-- GLOG_INC = /nix/store/hdjbh9hf60bzfqx4xslxq0bl097rn97c-glog-0.7.1/include
-- GLOG_SYS = GLOG_SYS-NOTFOUND
-- GLOG_COMPILE_DEFS = GLOG_USE_GLOG_EXPORT;GLOG_USE_GFLAGS
-- GLOG_LINK_LIBS = gflags
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: /home/eryk/projects/nexus/build
[35%] Built target nexus
[47%] Built target gui
[82%] Built target ImGui
[100%] Built target test_collection

```

This links builds and runs fine but the glog include library is not propagated to either the nexus target or the gui target. I made sure the module pulled by nix sets INTERFACE\_INCLUDE\_DIRECTORIES correctly. glog target seems fine, and my gui target is pretty simple. Yet the include libraries are not included in compile\_commands.json so my LSP is not happy and complains about correct code.

I went down a rabbit hole thinking Nix was messing something up but it looks like the library it pulls is fine. This used to work when I was using cmake 3.28 and gcc 13.3 (although admittedly I was not using nix at that point and was building from source). It’s still possible something is wrong with my setup or nix but my best guess is target\_link\_libraries is not propagating the include directories like [this page](https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_INCLUDE_DIRECTORIES.html) in docs seems to imply it should.

Would appreciate any help here. I’m at a loss for how to do this without annoying workaround pulling the include directories for any dependencies manually.

I’m also fairly new to using straight cmake like this so I may be making a dumb mistake. Please and thank you 🙏

---

<div class="post-metadata">

### Author: ![rayandrew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rayandrew/32/5992_2.png) [@rayandrew](https://discourse.cmake.org/u/rayandrew)
#### Post date: [January 23, 2026, 7:25am UTC](https://discourse.cmake.org/t/cmake-4-1-2-not-propagating-include-directories-to-target-when-linking-with-public-compile-commands-json/15432/2 "2026-01-23T07:25:43Z")

</div>

I ran into the same issue and I think I got the solution to fix it.

It seems Nix wraps compilers (gcc/clang) and adds library paths to implicit search paths.  
CMake detects these and populates `CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES`.  
And for some reason, CMake somehow omits implicit includes from compile commands (which kinda makes sense since the compiler already knows about them).

Few solutions:

- Export implicit includes as `-isystem`

```cmake
if(CMAKE_EXPORT_COMPILE_COMMANDS)
   set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()

```

- Force all includes to be explicit:  
`set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "")`

Hope this helps!

---

<div class="post-metadata">

### Author: ![edog](https://discourse.cmake.org/user_avatar/discourse.cmake.org/edog/32/5830_2.png) [@edog](https://discourse.cmake.org/u/edog)
#### Post date: [February 10, 2026, 7:33am UTC](https://discourse.cmake.org/t/cmake-4-1-2-not-propagating-include-directories-to-target-when-linking-with-public-compile-commands-json/15432/3 "2026-02-10T07:33:34Z")

</div>

Thank you! That worked, you’re a lifesaver
