cmake: support setting the intermediate dir strategy from the environment

This commit is contained in:
John Parent
2025-05-21 14:45:19 +02:00
committed by Ben Boeckel
parent c6763bb021
commit 392543384f
6 changed files with 51 additions and 0 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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

View File

@@ -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
``<TARGET_NAME>.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.

View File

@@ -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<std::string> testLauncher =
cmSystemTools::GetEnvVar("CMAKE_TEST_LAUNCHER");

View File

@@ -768,6 +768,7 @@ protected:
std::string GeneratorInstance;
std::string GeneratorPlatform;
std::string GeneratorToolset;
cm::optional<std::string> IntermediateDirStrategy;
bool GeneratorInstanceSet = false;
bool GeneratorPlatformSet = false;
bool GeneratorToolsetSet = false;