add_library(bar STATIC bar.cpp) add_library(foo STATIC foo.cpp) add_library(baz STATIC foo.cpp) set_target_properties(baz PROPERTIES EXCLUDE_FROM_ALL OFF) file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/main.txt" CONTENT "$") file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/bar.txt" CONTENT "$") file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/baz.txt" CONTENT "$") target_include_directories(foo PUBLIC .)