0

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?

Jodo
  • 4,515
  • 6
  • 38
  • 50
  • *install* step comes after *build* one, so no target can postpone its building until installation is completed. Instead of using `foo` subproject via `add_subdirectory(components/foo1)` approach, you may build and install it via `ExternalProject_Add`. That way installation of the subproject will be part of the main project's build process, so you may adjust appropriate dependencies. – Tsyvarev Nov 17 '19 at 16:57
  • See also https://stackoverflow.com/questions/41751574/cmake-target-depends-on-installed-target and https://stackoverflow.com/questions/8636479/postpone-making-custom-target-until-install. – Tsyvarev Nov 17 '19 at 16:57
  • See also https://stackoverflow.com/questions/58004057/undefined-reference-to-in-cmake-lib-to-lib?noredirect=1#comment102417211_58004057 https://github.com/ggshaman888/my_example/tree/master/cmake_lib_to_lib – shaman888 Nov 18 '19 at 08:25

0 Answers0