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:
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:
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 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 ![]()