Rebuilds static library when some .cpp source in another static library changes
I have several static libraries that cross-include header files, but do not directly depend on each other.
One static library has this CMakeLists.txt:
add_library(lib1 STATIC module1.cpp module2.cpp)
target_include_directories(lib1 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_INSTALL_PREFIX}/include
${CMAKE_INSTALL_PREFIX}/include/nlohmann
../lib2)
set_property(TARGET lib1 PROPERTY POSITION_INDEPENDENT_CODE ON)
The problem: When some .cpp file is touched in ../lib2, cmake (correctly) rebuilds that .cpp.o file and lib2.a, but then (erroneously) also rebuilds lib1.a.
There is no need to rebuild lib1.a when some .cpp file is touched in its include directory ../lib1.
I think dependency tracking is broken somewhere in cmake. The touched .cpp file is not included anywhere, it is only used for lib1.a
Edited by yurivict