I am building two targets: foo1 and foo2:
add_subdirectory(components/foo1)
add_subdirectory(components/foo2)
For foo1 I am building a library and copy it to a dist folder. Same for all the headers. The CMakeLists.txt looks something like this:
SET(COMPONENT_NAME "foo1")
add_library(lib${COMPONENT_NAME} foo1.cpp)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${INSTALL_INCLUDE_DIR}/${COMPONENT_NAME} FILES_MATCHING PATTERN "*.h*")
install(TARGETS lib${COMPONENT_NAME} DESTINATION ${INSTALL_LIB_DIR})
In foo2 I would like to include the include directory as I want to include headers from foo1:
include_directories(${INSTALL_INCLUDE_DIR})
The problem is that foo1 has not finished installing and copying the include headers to the ${INSTALL_INCLUDE_DIR} and thus foo2 throws an error that it can not find the header file. Basically I have to comment the add_subdirectory(components/foo2) line, build, uncomment the line and build again. Then it works.
How can I tell that add_subdirectory(components/foo2) needs to wait until add_subdirectory(components/foo1) has finished the install process before it starts to build?