I've managed to reproduce an issue I'm having with a much larger project. I think this is as minimal as I can make it
Key being I've explicitly added a header to the source list and editing it still does not cause anything to get recompiled.
~/src/test2/_build£ cat ../CMakeLists.txt
cmake_minimum_required (VERSION 3.14)
set (CMAKE_CXX_STANDARD 11)
# various explicit CXX sets are necessary for this tiny project and don't exist in larger original
project(moduletest CXX)
set (HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
add_subdirectory(submod)
add_library(moduletest_static STATIC "$<TARGET_OBJECTS:submod>")
set_target_properties(moduletest_static PROPERTIES LINKER_LANGUAGE CXX)
~/src/test2/_build£ cat ../submod/CMakeLists.txt
include_directories (${HEADER_DIR})
add_library(submod OBJECT compileme.cpp ../includeme.h)
~/src/test2/_build£ cat ../submod/compileme.cpp
#include "includeme.h"
int function()
{
return 5;
}
Make output is as follows:
~/src/test2/_build£ touch ../submod/compileme.cpp
~/src/test2/_build£ make
[ 50%] Building CXX object submod/CMakeFiles/submod.dir/compileme.cpp.o
[ 50%] Built target submod
[100%] Linking CXX static library libmoduletest_static.a
[100%] Built target moduletest_static
~/src/test2/_build£ touch ../includeme.h
~/src/test2/_build£ make
[ 50%] Built target submod
[100%] Built target moduletest_static
If I remove the use of include_directories
, and just #include "../includeme.h"
in my cpp file, everything works correctly, regardless of my add_library
call. (But this is definitely not an option in my real project)
I should also note that the "Scanning dependencies of target submod" is something of a red herring. In my larger project, I tried touching a single cpp file so that this occurred. Other cpp files that should have compiled still did not.
Use of target_include_directories
did not fix anything, regardless of absolute/relative paths.
Problem goes away with cmake -GNinja ..