I use a top-level CMake projects with ExternalProject to manage the build/assembling of a big software release consisting of many CMake subprojects (each one builds install with cmake --build / --install).
e.g. an entry for a subproject in the top-level CMakeLists.txt would look like:
ExternalProject_Add(subproject1
DEPENDS dependency1 dependency2 ...
GIT_REPOSITORY https://github.com/...
SOURCE_DIR ${CMAKE_BINARY_DIR}/Source/subproject1
CMAKE_ARGS ${COMMON_CMAKE_ARGS} ${COMMON_SUBPROJECTS_CMAKE_ARGS} -DFOO=BAR
BUILD_COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/Build/subproject1 --config ${CMAKE_BUILD_TYPE}
INSTALL_COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR}/Build/subproject1 --config ${CMAKE_BUILD_TYPE}
)
Because the project can be built in various “flavours”, I repeat the top-level build N times once for each flavor, passing CMake variables to differentiate the flavour. But only a few of the subprojects actually build differently based on the flavour, so this is a waste of time.
A more optimized approach would be to declare only those flavor-dependent subprojects multiple times (i.e. one ExternalProject_Add call per flavour, with same git repo, but different CMake variables, which would end up installing the items in different locations depending on flavour)…
But then how to have the other subprojects (independent of flavour) installed into the multiple (flavour) locations from the same build, i.e. without building N times?
I want to keep using the install rules defined in the subproject’s CMakeLists.txt, i.e.:
INSTALL_COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR}/Build/subproject1 --config ${CMAKE_BUILD_TYPE}
and not a custom copy command such as:
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/Build/subproject1/someBuildProduct ${TOPLEVELPROJECT_INSTALL_DIR}
Is there an option (to --install ideally) to switch install location without having to reconfigure/rebuild the subproject?
I have found only CMAKE_INSTALL_PREFIX / --prefix… doesn’t look like it is meant for this job.
Maybe I am complicating my life with using CMake for release engineering, and there is a simpler tool that does the job? But since I want to re-use the install rules defined in each subproject’s CMakeLists.txt, the question stands: how to avoid rebuilding the subproject, and install it into multiple locations?