diff options
author | Felix Lelchuk <felix.lelchuk@gmx.de> | 2021-08-02 17:42:26 (GMT) |
---|---|---|
committer | Felix Lelchuk <felix.lelchuk@gmx.de> | 2021-08-02 17:42:26 (GMT) |
commit | 58d10cf6f13493db124af18e3cac127b2164ea59 (patch) | |
tree | 593dc156eae14ffe6584fa1a31e17f9a18d88a2f /Tests/InstallMode/Subproject.cmake | |
parent | c15bb6f8b8c2eac691138e35d96570d537cc6d69 (diff) | |
download | CMake-58d10cf6f13493db124af18e3cac127b2164ea59.zip CMake-58d10cf6f13493db124af18e3cac127b2164ea59.tar.gz CMake-58d10cf6f13493db124af18e3cac127b2164ea59.tar.bz2 |
Alternative symlink-creating mode for file(INSTALL ...)
An new environment variable 'CMAKE_INSTALL_MODE' is introduced,
which can be used to ask CMake to create symbolic links
instead of copying files during a file(INSTALL ...).
The operation is at the file level only, directory trees are
still created using actual directories, not links.
Signed-off-by: Felix Lelchuk <felix.lelchuk@gmx.de>
Diffstat (limited to 'Tests/InstallMode/Subproject.cmake')
-rw-r--r-- | Tests/InstallMode/Subproject.cmake | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Tests/InstallMode/Subproject.cmake b/Tests/InstallMode/Subproject.cmake new file mode 100644 index 0000000..e4354d6 --- /dev/null +++ b/Tests/InstallMode/Subproject.cmake @@ -0,0 +1,76 @@ +include(ExternalProject) + +# add_subproject(<name> [NO_INSTALL] [DIR <dirname>] [DEPENDS [subpro_dep ...]]) +function(add_subproject _name) + cmake_parse_arguments(_arg "NO_INSTALL" "DIR" "DEPENDS" ${ARGN}) + + if(_arg_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "There are unparsed arguments") + endif() + + set(_maybe_NO_INSTALL) + if(_arg_NO_INSTALL) + set(_maybe_NO_INSTALL "INSTALL_COMMAND") + else() + # This is a trick to get a valid call. + # Since we set UPDATE_COMMAND to "" + # explicitly below, this won't harm. + set(_maybe_NO_INSTALL "UPDATE_COMMAND") + endif() + + if(CMAKE_GENERATOR MATCHES "Ninja Multi-Config") + # Replace list separator before passing on to ExternalProject_Add + string(REPLACE ";" "|" _CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}") + string(REPLACE ";" "|" _CROSS_CONFIGS "${CMAKE_CROSS_CONFIGS}") + string(REPLACE ";" "|" _DEFAULT_CONFIGS "${CMAKE_DEFAULT_CONFIGS}") + + set(_maybe_NINJA_MULTICONFIG_ARGS + "-DCMAKE_CONFIGURATION_TYPES:STRINGS=${_CONFIGURATION_TYPES}" + "-DCMAKE_CROSS_CONFIGS:STRINGS=${_CROSS_CONFIGS}" + "-DCMAKE_DEFAULT_BUILD_TYPE:STRING=${CMAKE_DEFAULT_BUILD_TYPE}" + "-DCMAKE_DEFAULT_CONFIGS:STRINGS=${_DEFAULT_CONFIGS}" + ) + endif() + + ExternalProject_Add("${_name}" + DOWNLOAD_COMMAND "" + UPDATE_COMMAND "" + ${_maybe_NO_INSTALL} "" + + BUILD_ALWAYS ON + + LOG_DOWNLOAD OFF + LOG_UPDATE OFF + LOG_PATCH OFF + LOG_CONFIGURE OFF + LOG_BUILD OFF + LOG_INSTALL OFF + + SOURCE_DIR "${PROJECT_SOURCE_DIR}/${_arg_DIR}" + + # Private build directory per subproject + BINARY_DIR "${PROJECT_BINARY_DIR}/subproject/${_arg_DIR}" + + # Common install directory, populated immediately + # during build (during build - not install - of superproject) + INSTALL_DIR "${CMAKE_INSTALL_PREFIX}" + + DEPENDS + ${_arg_DEPENDS} + + LIST_SEPARATOR "|" + CMAKE_ARGS + "-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>" + + # We can rely on ExternalProject to pick the right + # generator (and architecture/toolset where applicable), + # however, we need to explicitly inherit other parent + # project's build settings. + "-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}" + ${_maybe_NINJA_MULTICONFIG_ARGS} + + # Subproject progress reports clutter up the output, disable + "-DCMAKE_TARGET_MESSAGES:BOOL=OFF" + "-DCMAKE_RULE_MESSAGES:BOOL=OFF" + ) +endfunction() |