summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Maynard <rmaynard@nvidia.com>2021-02-22 16:58:52 (GMT)
committerRobert Maynard <rmaynard@nvidia.com>2021-03-09 18:53:16 (GMT)
commitb227a9565eb06dcc6e59bfa31e6939edf1ddbaad (patch)
tree622ff00179b0ee21bc86308aac5fd26f3ffb3f28
parent38140713ad24576f1c4e6253a1de91ff217dd475 (diff)
downloadCMake-b227a9565eb06dcc6e59bfa31e6939edf1ddbaad.zip
CMake-b227a9565eb06dcc6e59bfa31e6939edf1ddbaad.tar.gz
CMake-b227a9565eb06dcc6e59bfa31e6939edf1ddbaad.tar.bz2
cmake: configure preset add support for --install-prefix mapping
-rw-r--r--Help/manual/OPTIONS_BUILD.txt3
-rw-r--r--Help/manual/cmake-presets.7.rst6
-rw-r--r--Help/manual/presets/schema.json94
-rw-r--r--Help/release/dev/cmake-install-prefix-command.rst3
-rw-r--r--Source/cmCMakePresetsFile.cxx25
-rw-r--r--Source/cmCMakePresetsFile.h2
-rw-r--r--Source/cmake.cxx20
-rw-r--r--Tests/RunCMake/CMakePresets/FuturePresetInstallDirField-result.txt1
-rw-r--r--Tests/RunCMake/CMakePresets/FuturePresetInstallDirField-stderr.txt2
-rw-r--r--Tests/RunCMake/CMakePresets/FuturePresetInstallDirField.json.in11
-rw-r--r--Tests/RunCMake/CMakePresets/GoodInstall.json.in30
-rw-r--r--Tests/RunCMake/CMakePresets/GoodInstallCommandLine.cmake3
-rw-r--r--Tests/RunCMake/CMakePresets/GoodInstallDefault.cmake3
-rw-r--r--Tests/RunCMake/CMakePresets/GoodInstallInherit.cmake3
-rw-r--r--Tests/RunCMake/CMakePresets/GoodInstallOverride.cmake3
-rw-r--r--Tests/RunCMake/CMakePresets/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/CommandLine/install-prefix-no-arg-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/install-prefix-no-arg-stderr.txt1
-rw-r--r--Tests/RunCMake/IfacePaths/RunCMakeTest.cmake2
19 files changed, 212 insertions, 9 deletions
diff --git a/Help/manual/OPTIONS_BUILD.txt b/Help/manual/OPTIONS_BUILD.txt
index 251672e..c4f9be8 100644
--- a/Help/manual/OPTIONS_BUILD.txt
+++ b/Help/manual/OPTIONS_BUILD.txt
@@ -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.
diff --git a/Help/manual/cmake-presets.7.rst b/Help/manual/cmake-presets.7.rst
index 467818d..3d2ada8 100644
--- a/Help/manual/cmake-presets.7.rst
+++ b/Help/manual/cmake-presets.7.rst
@@ -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
diff --git a/Help/manual/presets/schema.json b/Help/manual/presets/schema.json
index ffbd7fe..a5025bb 100644
--- a/Help/manual/presets/schema.json
+++ b/Help/manual/presets/schema.json
@@ -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"
diff --git a/Help/release/dev/cmake-install-prefix-command.rst b/Help/release/dev/cmake-install-prefix-command.rst
index a5b140a..2de5d91 100644
--- a/Help/release/dev/cmake-install-prefix-command.rst
+++ b/Help/release/dev/cmake-install-prefix-command.rst
@@ -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.
diff --git a/Source/cmCMakePresetsFile.cxx b/Source/cmCMakePresetsFile.cxx
index c8d69b8..e9e8c4c 100644
--- a/Source/cmCMakePresetsFile.cxx
+++ b/Source/cmCMakePresetsFile.cxx
@@ -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);
}
diff --git a/Source/cmCMakePresetsFile.h b/Source/cmCMakePresetsFile.h
index e92c86b..517215d 100644
--- a/Source/cmCMakePresetsFile.h
+++ b/Source/cmCMakePresetsFile.h
@@ -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;
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index f96badd..b12eeee 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -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) {
diff --git a/Tests/RunCMake/CMakePresets/FuturePresetInstallDirField-result.txt b/Tests/RunCMake/CMakePresets/FuturePresetInstallDirField-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/FuturePresetInstallDirField-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMakePresets/FuturePresetInstallDirField-stderr.txt b/Tests/RunCMake/CMakePresets/FuturePresetInstallDirField-stderr.txt
new file mode 100644
index 0000000..36123bd
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/FuturePresetInstallDirField-stderr.txt
@@ -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.$
diff --git a/Tests/RunCMake/CMakePresets/FuturePresetInstallDirField.json.in b/Tests/RunCMake/CMakePresets/FuturePresetInstallDirField.json.in
new file mode 100644
index 0000000..2e5f7d5
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/FuturePresetInstallDirField.json.in
@@ -0,0 +1,11 @@
+{
+ "version": 1,
+ "configurePresets": [
+ {
+ "name": "FuturePresetInstallDirField",
+ "generator": "@RunCMake_GENERATOR@",
+ "binaryDir": "${sourceDir}/build",
+ "installDir": "${sourceDir}/install"
+ }
+ ]
+}
diff --git a/Tests/RunCMake/CMakePresets/GoodInstall.json.in b/Tests/RunCMake/CMakePresets/GoodInstall.json.in
new file mode 100644
index 0000000..6287c65
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/GoodInstall.json.in
@@ -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"
+ }
+ ]
+}
diff --git a/Tests/RunCMake/CMakePresets/GoodInstallCommandLine.cmake b/Tests/RunCMake/CMakePresets/GoodInstallCommandLine.cmake
new file mode 100644
index 0000000..a4f6178
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/GoodInstallCommandLine.cmake
@@ -0,0 +1,3 @@
+include("${RunCMake_SOURCE_DIR}/TestVariable.cmake")
+
+test_variable("CMAKE_INSTALL_PREFIX" "PATH" "${RunCMake_SOURCE_DIR}/path/passed/on/command_line")
diff --git a/Tests/RunCMake/CMakePresets/GoodInstallDefault.cmake b/Tests/RunCMake/CMakePresets/GoodInstallDefault.cmake
new file mode 100644
index 0000000..656fda0
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/GoodInstallDefault.cmake
@@ -0,0 +1,3 @@
+include("${RunCMake_SOURCE_DIR}/TestVariable.cmake")
+
+test_variable("CMAKE_INSTALL_PREFIX" "PATH" "${CMAKE_SOURCE_DIR}/build/install_dir1")
diff --git a/Tests/RunCMake/CMakePresets/GoodInstallInherit.cmake b/Tests/RunCMake/CMakePresets/GoodInstallInherit.cmake
new file mode 100644
index 0000000..656fda0
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/GoodInstallInherit.cmake
@@ -0,0 +1,3 @@
+include("${RunCMake_SOURCE_DIR}/TestVariable.cmake")
+
+test_variable("CMAKE_INSTALL_PREFIX" "PATH" "${CMAKE_SOURCE_DIR}/build/install_dir1")
diff --git a/Tests/RunCMake/CMakePresets/GoodInstallOverride.cmake b/Tests/RunCMake/CMakePresets/GoodInstallOverride.cmake
new file mode 100644
index 0000000..3d12b07
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/GoodInstallOverride.cmake
@@ -0,0 +1,3 @@
+include("${RunCMake_SOURCE_DIR}/TestVariable.cmake")
+
+test_variable("CMAKE_INSTALL_PREFIX" "PATH" "${CMAKE_SOURCE_DIR}/build/install_dir2")
diff --git a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake
index dfc56ee..ee21130 100644
--- a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake
@@ -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)
diff --git a/Tests/RunCMake/CommandLine/install-prefix-no-arg-result.txt b/Tests/RunCMake/CommandLine/install-prefix-no-arg-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/install-prefix-no-arg-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/install-prefix-no-arg-stderr.txt b/Tests/RunCMake/CommandLine/install-prefix-no-arg-stderr.txt
new file mode 100644
index 0000000..a464c70
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/install-prefix-no-arg-stderr.txt
@@ -0,0 +1 @@
+^CMake Error: No install directory specified for --install-prefix
diff --git a/Tests/RunCMake/IfacePaths/RunCMakeTest.cmake b/Tests/RunCMake/IfacePaths/RunCMakeTest.cmake
index 6530aee..c84e95e 100644
--- a/Tests/RunCMake/IfacePaths/RunCMakeTest.cmake
+++ b/Tests/RunCMake/IfacePaths/RunCMakeTest.cmake
@@ -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