I use the superbuild approach to build and install dependencies with ExternalProject_Add. Since I have some common CMake options, I factor them out in the main CMakeLists.txt. For instance, to install the dependencies in a common directory install/, and within that directory under the subdirectory based on the project name, I add
"-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}/install/$<PROJECT_NAME>"
to CMAKE_ARGS, expecting an install tree like this:
${CMAKE_SOURCE_DIR}
|- install
| |- depencency1 # the name depencency1 deduced from PROJECT_NAME
| | |- ... # installed artifacts
| |- ...
| |- dependencyN # the name depencencyN deduced from PROJECT_NAME
| | |- ... # installed artifacts
Unfortunately, PROJECT_NAME is not accepted as a generator expression.
How can I achieve the desired install tree structure above?
An alternative is to add
"-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}/install/${PROJECT_NAME}"
to CMAKE_ARGS in the subprojects, but that would mean duplication for each subproject, so I would have to modify all of them if I change my mind and choose a different base install directory.