mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 10:47:59 +08:00
cmake: configure preset add support for --install-prefix mapping
This commit is contained in:
@@ -77,7 +77,8 @@
|
||||
:variable:`CMAKE_GENERATOR_PLATFORM` variable for details.
|
||||
|
||||
``--install-prefix <directory>``
|
||||
Specify the installation prefix, :variable:`CMAKE_INSTALL_PREFIX`.
|
||||
Specify the installation directory, used by the
|
||||
:variable:`CMAKE_INSTALL_PREFIX` variable. Must be an absolute path.
|
||||
|
||||
``-Wno-dev``
|
||||
Suppress developer warnings.
|
||||
|
@@ -183,6 +183,12 @@ that may contain the following fields:
|
||||
specified, it must be inherited from the ``inherits`` preset (unless this
|
||||
preset is ``hidden``).
|
||||
|
||||
``installDir``
|
||||
|
||||
An optional string representing the path to the installation directory.
|
||||
This field supports `macro expansion`_. If a relative path is specified,
|
||||
it is calculated relative to the source directory.
|
||||
|
||||
``cmakeExecutable``
|
||||
|
||||
An optional string representing the path to the CMake executable to use
|
||||
|
@@ -11,7 +11,7 @@
|
||||
},
|
||||
"cmakeMinimumRequired": { "$ref": "#/definitions/cmakeMinimumRequired"},
|
||||
"vendor": { "$ref": "#/definitions/vendor" },
|
||||
"configurePresets": { "$ref": "#/definitions/configurePresets"}
|
||||
"configurePresets": { "$ref": "#/definitions/configurePresetsV1"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
@@ -19,11 +19,25 @@
|
||||
"properties": {
|
||||
"version": {
|
||||
"const": 2,
|
||||
"description": "A requVired integer representing the version of the JSON schema."
|
||||
},
|
||||
"cmakeMinimumRequired": { "$ref": "#/definitions/cmakeMinimumRequired"},
|
||||
"vendor": { "$ref": "#/definitions/vendor" },
|
||||
"configurePresets": { "$ref": "#/definitions/configurePresetsV1"},
|
||||
"buildPresets": { "$ref": "#/definitions/buildPresets"},
|
||||
"testPresets": { "$ref": "#/definitions/testPresets"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"version": {
|
||||
"const": 3,
|
||||
"description": "A required integer representing the version of the JSON schema."
|
||||
},
|
||||
"cmakeMinimumRequired": { "$ref": "#/definitions/cmakeMinimumRequired"},
|
||||
"vendor": { "$ref": "#/definitions/vendor" },
|
||||
"configurePresets": { "$ref": "#/definitions/configurePresets"},
|
||||
"configurePresets": { "$ref": "#/definitions/configurePresetsV3"},
|
||||
"buildPresets": { "$ref": "#/definitions/buildPresets"},
|
||||
"testPresets": { "$ref": "#/definitions/testPresets"}
|
||||
},
|
||||
@@ -58,7 +72,21 @@
|
||||
"description": "An optional map containing vendor-specific information. CMake does not interpret the contents of this field except to verify that it is a map if it does exist. However, the keys should be a vendor-specific domain name followed by a /-separated path. For example, the Example IDE 1.0 could use example.com/ExampleIDE/1.0. The value of each field can be anything desired by the vendor, though will typically be a map.",
|
||||
"properties": {}
|
||||
},
|
||||
"configurePresets": {
|
||||
"configurePresetsItemsV3": {
|
||||
"type": "array",
|
||||
"description": "A configure preset object.",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"description": "A configure preset object.",
|
||||
"properties": {
|
||||
"installDir": {
|
||||
"type": "string",
|
||||
"description": "An optional string representing the path to the output binary directory. This field supports macro expansion. If a relative path is specified, it is calculated relative to the source directory. If binaryDir is not specified, it must be inherited from the inherits preset (unless this preset is hidden)."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"configurePresetsItemsV1": {
|
||||
"type": "array",
|
||||
"description": "An optional array of configure preset objects.",
|
||||
"items": {
|
||||
@@ -302,6 +330,66 @@
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"configurePresetsV3": {
|
||||
"type": "array",
|
||||
"description": "An optional array of configure preset objects.",
|
||||
"allOf": [
|
||||
{ "$ref": "#/definitions/configurePresetsItemsV1" },
|
||||
{ "$ref": "#/definitions/configurePresetsItemsV3" }
|
||||
],
|
||||
"items": {
|
||||
"properties": {
|
||||
"name": {},
|
||||
"hidden": {},
|
||||
"inherits": {},
|
||||
"vendor": {},
|
||||
"displayName": {},
|
||||
"description": {},
|
||||
"generator": {},
|
||||
"architecture": {},
|
||||
"toolset": {},
|
||||
"binaryDir": {},
|
||||
"installDir": {},
|
||||
"cmakeExecutable": {},
|
||||
"cacheVariables": {},
|
||||
"environment": {},
|
||||
"warnings": {},
|
||||
"errors": {},
|
||||
"debug": {}
|
||||
},
|
||||
"required": [
|
||||
"name"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"configurePresetsV1": {
|
||||
"type": "array",
|
||||
"description": "An optional array of configure preset objects.",
|
||||
"allOf": [
|
||||
{ "$ref": "#/definitions/configurePresetsItemsV1" }
|
||||
],
|
||||
"items": {
|
||||
"properties": {
|
||||
"name": {},
|
||||
"hidden": {},
|
||||
"inherits": {},
|
||||
"vendor": {},
|
||||
"displayName": {},
|
||||
"description": {},
|
||||
"generator": {},
|
||||
"architecture": {},
|
||||
"toolset": {},
|
||||
"binaryDir": {},
|
||||
"cmakeExecutable": {},
|
||||
"cacheVariables": {},
|
||||
"environment": {},
|
||||
"warnings": {},
|
||||
"errors": {},
|
||||
"debug": {}
|
||||
},
|
||||
"required": [
|
||||
"name"
|
||||
|
@@ -3,3 +3,6 @@ cmake-install-prefix-command
|
||||
|
||||
* The :manual:`cmake(1)` command gained the ``--install-prefix <dir>``
|
||||
command line option to specify the location of the install prefix.
|
||||
|
||||
* :manual:`cmake-presets(7)` configure preset gained support for specifying
|
||||
the install prefix.
|
||||
|
@@ -57,7 +57,7 @@ using TestPreset = cmCMakePresetsFile::TestPreset;
|
||||
using ArchToolsetStrategy = cmCMakePresetsFile::ArchToolsetStrategy;
|
||||
|
||||
constexpr int MIN_VERSION = 1;
|
||||
constexpr int MAX_VERSION = 2;
|
||||
constexpr int MAX_VERSION = 3;
|
||||
|
||||
struct CMakeVersion
|
||||
{
|
||||
@@ -327,6 +327,8 @@ auto const ConfigurePresetHelper =
|
||||
.Bind("toolset"_s, ToolsetHelper, false)
|
||||
.Bind("binaryDir"_s, &ConfigurePreset::BinaryDir, PresetStringHelper,
|
||||
false)
|
||||
.Bind("installDir"_s, &ConfigurePreset::InstallDir, PresetStringHelper,
|
||||
false)
|
||||
.Bind<std::string>("cmakeExecutable"_s, nullptr, PresetStringHelper, false)
|
||||
.Bind("cacheVariables"_s, &ConfigurePreset::CacheVariables,
|
||||
VariablesHelper, false)
|
||||
@@ -872,6 +874,17 @@ bool ExpandMacros(const cmCMakePresetsFile& file,
|
||||
out->BinaryDir = cmSystemTools::CollapseFullPath(binaryDir);
|
||||
cmSystemTools::ConvertToUnixSlashes(out->BinaryDir);
|
||||
|
||||
if (!preset.InstallDir.empty()) {
|
||||
std::string installDir = preset.InstallDir;
|
||||
CHECK_EXPAND(out, installDir, macroExpanders)
|
||||
|
||||
if (!cmSystemTools::FileIsFullPath(installDir)) {
|
||||
installDir = cmStrCat(file.SourceDir, '/', installDir);
|
||||
}
|
||||
out->InstallDir = cmSystemTools::CollapseFullPath(installDir);
|
||||
cmSystemTools::ConvertToUnixSlashes(out->InstallDir);
|
||||
}
|
||||
|
||||
for (auto& variable : out->CacheVariables) {
|
||||
if (variable.second) {
|
||||
CHECK_EXPAND(out, variable.second->Value, macroExpanders)
|
||||
@@ -1174,6 +1187,7 @@ cmCMakePresetsFile::ConfigurePreset::VisitPresetInherit(
|
||||
preset.ToolsetStrategy = parent.ToolsetStrategy;
|
||||
}
|
||||
InheritString(preset.BinaryDir, parent.BinaryDir);
|
||||
InheritString(preset.InstallDir, parent.InstallDir);
|
||||
InheritOptionalValue(preset.WarnDev, parent.WarnDev);
|
||||
InheritOptionalValue(preset.ErrorDev, parent.ErrorDev);
|
||||
InheritOptionalValue(preset.WarnDeprecated, parent.WarnDeprecated);
|
||||
@@ -1502,6 +1516,9 @@ const char* cmCMakePresetsFile::ResultToString(ReadFileResult result)
|
||||
case ReadFileResult::BUILD_TEST_PRESETS_UNSUPPORTED:
|
||||
return "File version must be 2 or higher for build and test preset "
|
||||
"support.";
|
||||
case ReadFileResult::INSTALL_PREFIX_UNSUPPORTED:
|
||||
return "File version must be 3 or higher for installDir preset "
|
||||
"support.";
|
||||
}
|
||||
|
||||
return "Unknown error";
|
||||
@@ -1571,6 +1588,12 @@ cmCMakePresetsFile::ReadFileResult cmCMakePresetsFile::ReadJSONFile(
|
||||
.second) {
|
||||
return ReadFileResult::DUPLICATE_PRESETS;
|
||||
}
|
||||
|
||||
// Support for installDir presets added in version 3.
|
||||
if (v < 3 && !preset.InstallDir.empty()) {
|
||||
return ReadFileResult::INSTALL_PREFIX_UNSUPPORTED;
|
||||
}
|
||||
|
||||
this->ConfigurePresetOrder.push_back(preset.Name);
|
||||
}
|
||||
|
||||
|
@@ -32,6 +32,7 @@ public:
|
||||
USER_PRESET_INHERITANCE,
|
||||
INVALID_MACRO_EXPANSION,
|
||||
BUILD_TEST_PRESETS_UNSUPPORTED,
|
||||
INSTALL_PREFIX_UNSUPPORTED,
|
||||
};
|
||||
|
||||
enum class ArchToolsetStrategy
|
||||
@@ -102,6 +103,7 @@ public:
|
||||
std::string Toolset;
|
||||
cm::optional<ArchToolsetStrategy> ToolsetStrategy;
|
||||
std::string BinaryDir;
|
||||
std::string InstallDir;
|
||||
|
||||
std::map<std::string, cm::optional<CacheVariable>> CacheVariables;
|
||||
|
||||
|
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "cm_sys_stat.h"
|
||||
|
||||
#include "cmCMakePath.h"
|
||||
#include "cmCMakePresetsFile.h"
|
||||
#include "cmCommandLineArgument.h"
|
||||
#include "cmCommands.h"
|
||||
@@ -496,11 +497,16 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
|
||||
auto PrefixLambda = [&](std::string const& path, cmake* state) -> bool {
|
||||
const std::string var = "CMAKE_INSTALL_PREFIX";
|
||||
cmStateEnums::CacheEntryType type = cmStateEnums::PATH;
|
||||
cmCMakePath absolutePath(path);
|
||||
if (absolutePath.IsAbsolute()) {
|
||||
#ifndef CMAKE_BOOTSTRAP
|
||||
state->UnprocessedPresetVariables.erase(var);
|
||||
state->UnprocessedPresetVariables.erase(var);
|
||||
#endif
|
||||
state->ProcessCacheArg(var, path, type);
|
||||
return true;
|
||||
state->ProcessCacheArg(var, path, type);
|
||||
return true;
|
||||
}
|
||||
cmSystemTools::Error("Absolute paths are required for --install-prefix");
|
||||
return false;
|
||||
};
|
||||
|
||||
std::vector<CommandArgument> arguments = {
|
||||
@@ -1224,6 +1230,14 @@ void cmake::SetArgs(const std::vector<std::string>& args)
|
||||
this->UnprocessedPresetVariables = expandedPreset->CacheVariables;
|
||||
this->UnprocessedPresetEnvironment = expandedPreset->Environment;
|
||||
|
||||
if (!expandedPreset->InstallDir.empty() &&
|
||||
this->State->GetInitializedCacheValue("CMAKE_INSTALL_PREFIX") ==
|
||||
nullptr) {
|
||||
this->UnprocessedPresetVariables["CMAKE_INSTALL_PREFIX"] = {
|
||||
"PATH", expandedPreset->InstallDir
|
||||
};
|
||||
}
|
||||
|
||||
if (!expandedPreset->ArchitectureStrategy ||
|
||||
expandedPreset->ArchitectureStrategy ==
|
||||
cmCMakePresetsFile::ArchToolsetStrategy::Set) {
|
||||
|
@@ -0,0 +1 @@
|
||||
1
|
@@ -0,0 +1,2 @@
|
||||
^CMake Error: Could not read presets from [^
|
||||
]*/Tests/RunCMake/CMakePresets/FuturePresetInstallDirField: File version must be 3 or higher for installDir preset support.$
|
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": 1,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "FuturePresetInstallDirField",
|
||||
"generator": "@RunCMake_GENERATOR@",
|
||||
"binaryDir": "${sourceDir}/build",
|
||||
"installDir": "${sourceDir}/install"
|
||||
}
|
||||
]
|
||||
}
|
30
Tests/RunCMake/CMakePresets/GoodInstall.json.in
Normal file
30
Tests/RunCMake/CMakePresets/GoodInstall.json.in
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"version": 3,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "GoodInstallDefault",
|
||||
"generator": "@RunCMake_GENERATOR@",
|
||||
"binaryDir": "${sourceDir}/build/${presetName}",
|
||||
"installDir": "${sourceDir}/build/install_dir1"
|
||||
},
|
||||
{
|
||||
"name": "GoodInstallInherit",
|
||||
"inherits": "GoodInstallDefault",
|
||||
"cacheVariables": {
|
||||
"CMAKE_INSTALL_PREFIX": {
|
||||
"type": "PATH",
|
||||
"value": "${sourceDir}/build/bad_path"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "GoodInstallOverride",
|
||||
"inherits": "GoodInstallInherit",
|
||||
"installDir": "${sourceDir}/build/install_dir2"
|
||||
},
|
||||
{
|
||||
"name": "GoodInstallCommandLine",
|
||||
"inherits": "GoodInstallOverride"
|
||||
}
|
||||
]
|
||||
}
|
3
Tests/RunCMake/CMakePresets/GoodInstallCommandLine.cmake
Normal file
3
Tests/RunCMake/CMakePresets/GoodInstallCommandLine.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
include("${RunCMake_SOURCE_DIR}/TestVariable.cmake")
|
||||
|
||||
test_variable("CMAKE_INSTALL_PREFIX" "PATH" "${RunCMake_SOURCE_DIR}/path/passed/on/command_line")
|
3
Tests/RunCMake/CMakePresets/GoodInstallDefault.cmake
Normal file
3
Tests/RunCMake/CMakePresets/GoodInstallDefault.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
include("${RunCMake_SOURCE_DIR}/TestVariable.cmake")
|
||||
|
||||
test_variable("CMAKE_INSTALL_PREFIX" "PATH" "${CMAKE_SOURCE_DIR}/build/install_dir1")
|
3
Tests/RunCMake/CMakePresets/GoodInstallInherit.cmake
Normal file
3
Tests/RunCMake/CMakePresets/GoodInstallInherit.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
include("${RunCMake_SOURCE_DIR}/TestVariable.cmake")
|
||||
|
||||
test_variable("CMAKE_INSTALL_PREFIX" "PATH" "${CMAKE_SOURCE_DIR}/build/install_dir1")
|
3
Tests/RunCMake/CMakePresets/GoodInstallOverride.cmake
Normal file
3
Tests/RunCMake/CMakePresets/GoodInstallOverride.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
include("${RunCMake_SOURCE_DIR}/TestVariable.cmake")
|
||||
|
||||
test_variable("CMAKE_INSTALL_PREFIX" "PATH" "${CMAKE_SOURCE_DIR}/build/install_dir2")
|
@@ -94,6 +94,7 @@ run_cmake_presets(InvalidVariableValue)
|
||||
run_cmake_presets(ExtraRootField)
|
||||
run_cmake_presets(ExtraPresetField)
|
||||
run_cmake_presets(ExtraVariableField)
|
||||
run_cmake_presets(FuturePresetInstallDirField)
|
||||
run_cmake_presets(InvalidPresetVendor)
|
||||
set(CMakePresets_SCHEMA_EXPECTED_RESULT 0)
|
||||
run_cmake_presets(DuplicatePresets)
|
||||
@@ -181,6 +182,13 @@ run_cmake_presets(GoodInheritanceMulti)
|
||||
run_cmake_presets(GoodInheritanceMultiSecond)
|
||||
run_cmake_presets(GoodInheritanceMacro)
|
||||
|
||||
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/GoodInstall.json.in")
|
||||
run_cmake_presets(GoodInstallDefault)
|
||||
run_cmake_presets(GoodInstallInherit)
|
||||
run_cmake_presets(GoodInstallOverride)
|
||||
run_cmake_presets(GoodInstallCommandLine "--install-prefix=${RunCMake_SOURCE_DIR}/path/passed/on/command_line")
|
||||
|
||||
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/CMakePresets.json.in")
|
||||
# Test bad preset arguments
|
||||
run_cmake_presets(VendorMacro)
|
||||
run_cmake_presets(InvalidGenerator)
|
||||
|
@@ -0,0 +1 @@
|
||||
1
|
@@ -0,0 +1 @@
|
||||
^CMake Error: No install directory specified for --install-prefix
|
@@ -79,7 +79,7 @@ foreach(policyStatus NEW OLD "")
|
||||
set(policySuffix -CMP0052-${policyStatus})
|
||||
endif()
|
||||
set(RunCMake_TEST_OPTIONS
|
||||
"--install-prefix=${RunCMake_BINARY_DIR}/prefix" ${policyOption}
|
||||
"--install-prefix ${RunCMake_BINARY_DIR}/prefix" ${policyOption}
|
||||
"-DTEST_FILE=${RunCMake_SOURCE_DIR}/BinaryDirectoryInInterface.cmake"
|
||||
)
|
||||
# Set the RunCMake_TEST_SOURCE_DIR here to the copy too. This is needed to run
|
||||
|
Reference in New Issue
Block a user