diff --git a/Help/envvar/CMAKE_INTERMEDIATE_DIR_STRATEGY.rst b/Help/envvar/CMAKE_INTERMEDIATE_DIR_STRATEGY.rst new file mode 100644 index 0000000000..a3a01a76a5 --- /dev/null +++ b/Help/envvar/CMAKE_INTERMEDIATE_DIR_STRATEGY.rst @@ -0,0 +1,10 @@ +CMAKE_INTERMEDIATE_DIR_STRATEGY +------------------------------- + +.. versionadded:: 4.2 + +.. include:: include/ENV_VAR.rst + +``CMAKE_INTERMEDIATE_DIR_STRATEGY`` is a string specifying the strategy to use +for target intermediate directories. It initializes the +:variable:`CMAKE_INTERMEDIATE_DIR_STRATEGY` variable. diff --git a/Help/manual/cmake-env-variables.7.rst b/Help/manual/cmake-env-variables.7.rst index e4936555df..b079c33bd5 100644 --- a/Help/manual/cmake-env-variables.7.rst +++ b/Help/manual/cmake-env-variables.7.rst @@ -65,6 +65,7 @@ Environment Variables that Control the Build /envvar/CMAKE_LANG_IMPLICIT_LINK_LIBRARIES_EXCLUDE /envvar/CMAKE_LANG_LINKER_LAUNCHER /envvar/CMAKE_MSVCIDE_RUN_PATH + /envvar/CMAKE_INTERMEDIATE_DIR_STRATEGY /envvar/CMAKE_NO_VERBOSE /envvar/CMAKE_OSX_ARCHITECTURES /envvar/CMAKE_TEST_LAUNCHER diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 1b8d0a791a..57678a4c93 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -261,6 +261,7 @@ Variables that Change Behavior /variable/CMAKE_MESSAGE_LOG_LEVEL /variable/CMAKE_MFC_FLAG /variable/CMAKE_MODULE_PATH + /variable/CMAKE_INTERMEDIATE_DIR_STRATEGY /variable/CMAKE_PKG_CONFIG_DISABLE_UNINSTALLED /variable/CMAKE_PKG_CONFIG_PC_LIB_DIRS /variable/CMAKE_PKG_CONFIG_PC_PATH diff --git a/Help/variable/CMAKE_INTERMEDIATE_DIR_STRATEGY.rst b/Help/variable/CMAKE_INTERMEDIATE_DIR_STRATEGY.rst new file mode 100644 index 0000000000..4b0849a8c4 --- /dev/null +++ b/Help/variable/CMAKE_INTERMEDIATE_DIR_STRATEGY.rst @@ -0,0 +1,28 @@ +CMAKE_INTERMEDIATE_DIR_STRATEGY +------------------------------- + +.. versionadded:: 4.2 + +``CMAKE_INTERMEDIATE_DIR_STRATEGY`` is a string cache variable specifying the +strategy to use for target intermediate directories and their contents. The +supported values are: + +- ``FULL``: Intermediate directories are named based on a + ``.dir`` pattern (with some slight deviations and sanitizations + applied in various places). Object file names are based on the filename of + the source file being compiled. +- ``SHORT``: Intermediate directories are named from the hash of the target + name and the build directory location. Object file names are based on hashes + of the source file name to reduce path lengths. This may help with projects + that generate long paths in the build directory to support building in + directories other than those near a root path. + +When unset or the named strategy is not supported, the ``FULL`` strategy is +used. + +.. note:: + This only works as a cache variable, not a locally-scoped variable. + +.. note:: + Not all generators support all strategies and paths may differ between + generators. diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 466c6f49e6..a1cce112d4 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -933,6 +933,8 @@ void cmake::LoadEnvironmentPresets() readGeneratorVar("CMAKE_GENERATOR_INSTANCE", this->GeneratorInstance); readGeneratorVar("CMAKE_GENERATOR_PLATFORM", this->GeneratorPlatform); readGeneratorVar("CMAKE_GENERATOR_TOOLSET", this->GeneratorToolset); + this->IntermediateDirStrategy = + cmSystemTools::GetEnvVar("CMAKE_INTERMEDIATE_DIR_STRATEGY"); } namespace { @@ -2600,6 +2602,14 @@ int cmake::ActualConfigure() "Name of generator toolset.", cmStateEnums::INTERNAL); } + if (!this->State->GetInitializedCacheValue( + "CMAKE_INTERMEDIATE_DIR_STRATEGY") && + this->IntermediateDirStrategy) { + this->AddCacheEntry( + "CMAKE_INTERMEDIATE_DIR_STRATEGY", *this->IntermediateDirStrategy, + "Select the intermediate directory strategy", cmStateEnums::STRING); + } + if (!this->State->GetInitializedCacheValue("CMAKE_TEST_LAUNCHER")) { cm::optional testLauncher = cmSystemTools::GetEnvVar("CMAKE_TEST_LAUNCHER"); diff --git a/Source/cmake.h b/Source/cmake.h index f338c13f1e..6c4416715a 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -768,6 +768,7 @@ protected: std::string GeneratorInstance; std::string GeneratorPlatform; std::string GeneratorToolset; + cm::optional IntermediateDirStrategy; bool GeneratorInstanceSet = false; bool GeneratorPlatformSet = false; bool GeneratorToolsetSet = false;