0

Below is a small sample of the way I'm building my project. I have a list of headers and a list of source files, and pass them to add_executable. Sometimes after several incremental builds, I'm changing the header file but the build isn't doing anything. The status shows that each target is checked but no changes are seen. If I do a small modification in the CPP file, then the build is executed.

What could be the cause of this?

list (APPEND ${PROJ_NAME}_SRC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/lua/lua_config.hpp)
list (APPEND ${PROJ_NAME}_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/source/lua/lua_config.cpp)
add_executable(${PROJ_NAME} ${${PROJ_NAME}_SRC_FILES} ${${PROJ_NAME}_SRC_HEADERS})

I'm using the 'Unix Makefiles' generator.

I see that all my projects header files are not part of the generated depend.cmake file. I guess this is the root of the problem. All the header files from the other conan packages are there, but not the ones for the top level project.

Cristian Bidea
  • 679
  • 4
  • 12
  • 1
    Is [this](https://stackoverflow.com/questions/7461000/handling-header-files-dependencies-with-cmake) any help? – Neil Gatenby Feb 20 '19 at 09:01
  • May be, you are changing the header *during* the some build? Or your filesystem doesn't store precise timestamps. Given part of the code seems to be a correct. Note, that rebuilding is performed according timestamps of the executable and its dependencies. When you find that rebuilding doesn't occure but should, just manually check timestamps of the executable and the header you have changed. – Tsyvarev Feb 20 '19 at 09:03
  • You can consider avoiding incremental builds altogether. Or at least avoiding incremental build based on timestamp change or on implicitly collected dependency graph. – user7860670 Feb 20 '19 at 09:21
  • @NeilGatenby yes, that was helpful, thank you! – Cristian Bidea Feb 20 '19 at 10:35

1 Answers1

0

Two things are needed for the header files to be added to the depend.make file. First adding them in the list of files of the target, which I did and add the include directory using target_include_directories.

target_include_directories(${PROJ_NAME} PRIVATE
     $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

At this point it's still not working. This is because I'm passing two lists of files that are separated using a space ' ' character. After I joined the two lists into a single one using a ';' it started working.

add_executable(${PROJ_NAME} "${${PROJ_NAME}_SRC_FILES};${${PROJ_NAME}_HEADER_FILES}")
Cristian Bidea
  • 679
  • 4
  • 12