浏览代码

Merge topic 'add_prefix_cmake_option'

400536c317 cmCommandLineArgument: trim leading empty spaces
b227a9565e cmake: configure preset add support for --install-prefix mapping
38140713ad cmake: add support for --install-prefix command argument

Acked-by: Kitware Robot <[email protected]>
Merge-request: !5843
Brad King 4 年之前
父节点
当前提交
9a80ce6d24

+ 4 - 0
Help/manual/OPTIONS_BUILD.txt

@@ -76,6 +76,10 @@
  native build system to choose a compiler or SDK.  See the
  native build system to choose a compiler or SDK.  See the
  :variable:`CMAKE_GENERATOR_PLATFORM` variable for details.
  :variable:`CMAKE_GENERATOR_PLATFORM` variable for details.
 
 
+``--install-prefix <directory>``
+ Specify the installation directory, used by the
+ :variable:`CMAKE_INSTALL_PREFIX` variable. Must be an absolute path.
+
 ``-Wno-dev``
 ``-Wno-dev``
  Suppress developer warnings.
  Suppress developer warnings.
 
 

+ 6 - 0
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
   specified, it must be inherited from the ``inherits`` preset (unless this
   preset is ``hidden``).
   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``
 ``cmakeExecutable``
 
 
   An optional string representing the path to the CMake executable to use
   An optional string representing the path to the CMake executable to use

+ 91 - 3
Help/manual/presets/schema.json

@@ -11,7 +11,7 @@
         },
         },
         "cmakeMinimumRequired": { "$ref": "#/definitions/cmakeMinimumRequired"},
         "cmakeMinimumRequired": { "$ref": "#/definitions/cmakeMinimumRequired"},
         "vendor": { "$ref": "#/definitions/vendor" },
         "vendor": { "$ref": "#/definitions/vendor" },
-        "configurePresets": { "$ref": "#/definitions/configurePresets"}
+        "configurePresets": { "$ref": "#/definitions/configurePresetsV1"}
       },
       },
       "additionalProperties": false
       "additionalProperties": false
     },
     },
@@ -19,11 +19,25 @@
       "properties": {
       "properties": {
         "version": {
         "version": {
           "const": 2,
           "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."
           "description": "A required integer representing the version of the JSON schema."
         },
         },
         "cmakeMinimumRequired": { "$ref": "#/definitions/cmakeMinimumRequired"},
         "cmakeMinimumRequired": { "$ref": "#/definitions/cmakeMinimumRequired"},
         "vendor": { "$ref": "#/definitions/vendor" },
         "vendor": { "$ref": "#/definitions/vendor" },
-        "configurePresets": { "$ref": "#/definitions/configurePresets"},
+        "configurePresets": { "$ref": "#/definitions/configurePresetsV3"},
         "buildPresets": { "$ref": "#/definitions/buildPresets"},
         "buildPresets": { "$ref": "#/definitions/buildPresets"},
         "testPresets": { "$ref": "#/definitions/testPresets"}
         "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.",
       "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": {}
       "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",
       "type": "array",
       "description": "An optional array of configure preset objects.",
       "description": "An optional array of configure preset objects.",
       "items": {
       "items": {
@@ -302,6 +330,66 @@
             },
             },
             "additionalProperties": false
             "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": [
         "required": [
           "name"
           "name"

+ 8 - 0
Help/release/dev/cmake-install-prefix-command.rst

@@ -0,0 +1,8 @@
+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.

+ 24 - 1
Source/cmCMakePresetsFile.cxx

@@ -57,7 +57,7 @@ using TestPreset = cmCMakePresetsFile::TestPreset;
 using ArchToolsetStrategy = cmCMakePresetsFile::ArchToolsetStrategy;
 using ArchToolsetStrategy = cmCMakePresetsFile::ArchToolsetStrategy;
 
 
 constexpr int MIN_VERSION = 1;
 constexpr int MIN_VERSION = 1;
-constexpr int MAX_VERSION = 2;
+constexpr int MAX_VERSION = 3;
 
 
 struct CMakeVersion
 struct CMakeVersion
 {
 {
@@ -327,6 +327,8 @@ auto const ConfigurePresetHelper =
     .Bind("toolset"_s, ToolsetHelper, false)
     .Bind("toolset"_s, ToolsetHelper, false)
     .Bind("binaryDir"_s, &ConfigurePreset::BinaryDir, PresetStringHelper,
     .Bind("binaryDir"_s, &ConfigurePreset::BinaryDir, PresetStringHelper,
           false)
           false)
+    .Bind("installDir"_s, &ConfigurePreset::InstallDir, PresetStringHelper,
+          false)
     .Bind<std::string>("cmakeExecutable"_s, nullptr, PresetStringHelper, false)
     .Bind<std::string>("cmakeExecutable"_s, nullptr, PresetStringHelper, false)
     .Bind("cacheVariables"_s, &ConfigurePreset::CacheVariables,
     .Bind("cacheVariables"_s, &ConfigurePreset::CacheVariables,
           VariablesHelper, false)
           VariablesHelper, false)
@@ -872,6 +874,17 @@ bool ExpandMacros(const cmCMakePresetsFile& file,
   out->BinaryDir = cmSystemTools::CollapseFullPath(binaryDir);
   out->BinaryDir = cmSystemTools::CollapseFullPath(binaryDir);
   cmSystemTools::ConvertToUnixSlashes(out->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) {
   for (auto& variable : out->CacheVariables) {
     if (variable.second) {
     if (variable.second) {
       CHECK_EXPAND(out, variable.second->Value, macroExpanders)
       CHECK_EXPAND(out, variable.second->Value, macroExpanders)
@@ -1174,6 +1187,7 @@ cmCMakePresetsFile::ConfigurePreset::VisitPresetInherit(
     preset.ToolsetStrategy = parent.ToolsetStrategy;
     preset.ToolsetStrategy = parent.ToolsetStrategy;
   }
   }
   InheritString(preset.BinaryDir, parent.BinaryDir);
   InheritString(preset.BinaryDir, parent.BinaryDir);
+  InheritString(preset.InstallDir, parent.InstallDir);
   InheritOptionalValue(preset.WarnDev, parent.WarnDev);
   InheritOptionalValue(preset.WarnDev, parent.WarnDev);
   InheritOptionalValue(preset.ErrorDev, parent.ErrorDev);
   InheritOptionalValue(preset.ErrorDev, parent.ErrorDev);
   InheritOptionalValue(preset.WarnDeprecated, parent.WarnDeprecated);
   InheritOptionalValue(preset.WarnDeprecated, parent.WarnDeprecated);
@@ -1502,6 +1516,9 @@ const char* cmCMakePresetsFile::ResultToString(ReadFileResult result)
     case ReadFileResult::BUILD_TEST_PRESETS_UNSUPPORTED:
     case ReadFileResult::BUILD_TEST_PRESETS_UNSUPPORTED:
       return "File version must be 2 or higher for build and test preset "
       return "File version must be 2 or higher for build and test preset "
              "support.";
              "support.";
+    case ReadFileResult::INSTALL_PREFIX_UNSUPPORTED:
+      return "File version must be 3 or higher for installDir preset "
+             "support.";
   }
   }
 
 
   return "Unknown error";
   return "Unknown error";
@@ -1571,6 +1588,12 @@ cmCMakePresetsFile::ReadFileResult cmCMakePresetsFile::ReadJSONFile(
            .second) {
            .second) {
       return ReadFileResult::DUPLICATE_PRESETS;
       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);
     this->ConfigurePresetOrder.push_back(preset.Name);
   }
   }
 
 

+ 2 - 0
Source/cmCMakePresetsFile.h

@@ -32,6 +32,7 @@ public:
     USER_PRESET_INHERITANCE,
     USER_PRESET_INHERITANCE,
     INVALID_MACRO_EXPANSION,
     INVALID_MACRO_EXPANSION,
     BUILD_TEST_PRESETS_UNSUPPORTED,
     BUILD_TEST_PRESETS_UNSUPPORTED,
+    INSTALL_PREFIX_UNSUPPORTED,
   };
   };
 
 
   enum class ArchToolsetStrategy
   enum class ArchToolsetStrategy
@@ -102,6 +103,7 @@ public:
     std::string Toolset;
     std::string Toolset;
     cm::optional<ArchToolsetStrategy> ToolsetStrategy;
     cm::optional<ArchToolsetStrategy> ToolsetStrategy;
     std::string BinaryDir;
     std::string BinaryDir;
+    std::string InstallDir;
 
 
     std::map<std::string, cm::optional<CacheVariable>> CacheVariables;
     std::map<std::string, cm::optional<CacheVariable>> CacheVariables;
 
 

+ 4 - 0
Source/cmCommandLineArgument.h

@@ -110,6 +110,10 @@ struct cmCommandLineArgument
           }
           }
         }
         }
         if (parseState == ParseMode::Valid) {
         if (parseState == ParseMode::Valid) {
+          if (possible_value[0] == ' ') {
+            possible_value.remove_prefix(1);
+          }
+
           parseState = this->StoreCall(std::string(possible_value),
           parseState = this->StoreCall(std::string(possible_value),
                                        std::forward<CallState>(state)...)
                                        std::forward<CallState>(state)...)
             ? ParseMode::Valid
             ? ParseMode::Valid

+ 31 - 0
Source/cmake.cxx

@@ -28,6 +28,7 @@
 
 
 #include "cm_sys_stat.h"
 #include "cm_sys_stat.h"
 
 
+#include "cmCMakePath.h"
 #include "cmCMakePresetsFile.h"
 #include "cmCMakePresetsFile.h"
 #include "cmCommandLineArgument.h"
 #include "cmCommandLineArgument.h"
 #include "cmCommands.h"
 #include "cmCommands.h"
@@ -493,6 +494,21 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
     return true;
     return true;
   };
   };
 
 
+  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);
+#endif
+      state->ProcessCacheArg(var, path, type);
+      return true;
+    }
+    cmSystemTools::Error("Absolute paths are required for --install-prefix");
+    return false;
+  };
+
   std::vector<CommandArgument> arguments = {
   std::vector<CommandArgument> arguments = {
     CommandArgument{ "-D", "-D must be followed with VAR=VALUE.",
     CommandArgument{ "-D", "-D must be followed with VAR=VALUE.",
                      CommandArgument::Values::One, DefineLambda },
                      CommandArgument::Values::One, DefineLambda },
@@ -511,8 +527,12 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
                        state->ReadListFile(args, path);
                        state->ReadListFile(args, path);
                        return true;
                        return true;
                      } },
                      } },
+
     CommandArgument{ "-P", "-P must be followed by a file name.",
     CommandArgument{ "-P", "-P must be followed by a file name.",
                      CommandArgument::Values::One, ScriptLambda },
                      CommandArgument::Values::One, ScriptLambda },
+    CommandArgument{ "--install-prefix",
+                     "No install directory specified for --install-prefix",
+                     CommandArgument::Values::One, PrefixLambda },
     CommandArgument{ "--find-package", CommandArgument::Values::Zero,
     CommandArgument{ "--find-package", CommandArgument::Values::Zero,
                      [&](std::string const&, cmake*) -> bool {
                      [&](std::string const&, cmake*) -> bool {
                        findPackageMode = true;
                        findPackageMode = true;
@@ -815,6 +835,9 @@ void cmake::SetArgs(const std::vector<std::string>& args)
                      CommandArgument::Values::One, PlatformLambda },
                      CommandArgument::Values::One, PlatformLambda },
     CommandArgument{ "-T", "No toolset specified for -T",
     CommandArgument{ "-T", "No toolset specified for -T",
                      CommandArgument::Values::One, ToolsetLamda },
                      CommandArgument::Values::One, ToolsetLamda },
+    CommandArgument{ "--install-prefix",
+                     "No install directory specified for --install-prefix",
+                     CommandArgument::Values::One, IgnoreAndTrueLambda },
 
 
     CommandArgument{ "--check-build-system", CommandArgument::Values::Two,
     CommandArgument{ "--check-build-system", CommandArgument::Values::Two,
                      [](std::string const& value, cmake* state) -> bool {
                      [](std::string const& value, cmake* state) -> bool {
@@ -1207,6 +1230,14 @@ void cmake::SetArgs(const std::vector<std::string>& args)
     this->UnprocessedPresetVariables = expandedPreset->CacheVariables;
     this->UnprocessedPresetVariables = expandedPreset->CacheVariables;
     this->UnprocessedPresetEnvironment = expandedPreset->Environment;
     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 ||
     if (!expandedPreset->ArchitectureStrategy ||
         expandedPreset->ArchitectureStrategy ==
         expandedPreset->ArchitectureStrategy ==
           cmCMakePresetsFile::ArchToolsetStrategy::Set) {
           cmCMakePresetsFile::ArchToolsetStrategy::Set) {

+ 2 - 0
Source/cmake.h

@@ -712,6 +712,8 @@ private:
       "Specify toolset name if supported by generator." },                    \
       "Specify toolset name if supported by generator." },                    \
     { "-A <platform-name>",                                                   \
     { "-A <platform-name>",                                                   \
       "Specify platform name if supported by generator." },                   \
       "Specify platform name if supported by generator." },                   \
+    { "--install-prefix <directory>",                                         \
+      "Specify install directory [CMAKE_INSTALL_PREFIX]." },                  \
     { "-Wdev", "Enable developer warnings." },                                \
     { "-Wdev", "Enable developer warnings." },                                \
     { "-Wno-dev", "Suppress developer warnings." },                           \
     { "-Wno-dev", "Suppress developer warnings." },                           \
     { "-Werror=dev", "Make developer warnings errors." },                     \
     { "-Werror=dev", "Make developer warnings errors." },                     \

+ 3 - 3
Tests/ExternalProjectLocal/CMakeLists.txt

@@ -41,7 +41,7 @@ set(TutorialStep5_install_dir ${install_dir})
 set(proj TutorialStep5-Local-TestAfterInstall)
 set(proj TutorialStep5-Local-TestAfterInstall)
 ExternalProject_Add(${proj}
 ExternalProject_Add(${proj}
 URL "${CMAKE_CURRENT_SOURCE_DIR}/Step5"
 URL "${CMAKE_CURRENT_SOURCE_DIR}/Step5"
-CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -G ${CMAKE_GENERATOR} <SOURCE_DIR>
+CMAKE_ARGS --install-prefix=<INSTALL_DIR> -G ${CMAKE_GENERATOR} <SOURCE_DIR>
 CMAKE_CACHE_DEFAULT_ARGS -DUSE_MYMATH:BOOL=OFF
 CMAKE_CACHE_DEFAULT_ARGS -DUSE_MYMATH:BOOL=OFF
 TEST_AFTER_INSTALL 1
 TEST_AFTER_INSTALL 1
 LOG_TEST 1
 LOG_TEST 1
@@ -51,7 +51,7 @@ set_property(TARGET ${proj} PROPERTY FOLDER "Local")
 set(proj TutorialStep5-Local-TestExcludeFromMainBefore)
 set(proj TutorialStep5-Local-TestExcludeFromMainBefore)
 ExternalProject_Add(${proj}
 ExternalProject_Add(${proj}
 URL "${CMAKE_CURRENT_SOURCE_DIR}/Step5"
 URL "${CMAKE_CURRENT_SOURCE_DIR}/Step5"
-CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>  -G ${CMAKE_GENERATOR} <SOURCE_DIR>
+CMAKE_ARGS --install-prefix=<INSTALL_DIR>  -G ${CMAKE_GENERATOR} <SOURCE_DIR>
 CMAKE_CACHE_DEFAULT_ARGS -DUSE_MYMATH:BOOL=OFF
 CMAKE_CACHE_DEFAULT_ARGS -DUSE_MYMATH:BOOL=OFF
 TEST_BEFORE_INSTALL 1
 TEST_BEFORE_INSTALL 1
 TEST_EXCLUDE_FROM_MAIN 1
 TEST_EXCLUDE_FROM_MAIN 1
@@ -63,7 +63,7 @@ set_property(TARGET ${proj} PROPERTY FOLDER "Local")
 set(proj TutorialStep5-Local-TestExcludeFromMainAfter)
 set(proj TutorialStep5-Local-TestExcludeFromMainAfter)
 ExternalProject_Add(${proj}
 ExternalProject_Add(${proj}
 URL "${CMAKE_CURRENT_SOURCE_DIR}/Step5"
 URL "${CMAKE_CURRENT_SOURCE_DIR}/Step5"
-CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>  -G ${CMAKE_GENERATOR} <SOURCE_DIR>
+CMAKE_ARGS --install-prefix=<INSTALL_DIR>  -G ${CMAKE_GENERATOR} <SOURCE_DIR>
 CMAKE_CACHE_DEFAULT_ARGS -DUSE_MYMATH:BOOL=OFF
 CMAKE_CACHE_DEFAULT_ARGS -DUSE_MYMATH:BOOL=OFF
 TEST_AFTER_INSTALL 1
 TEST_AFTER_INSTALL 1
 TEST_EXCLUDE_FROM_MAIN 1
 TEST_EXCLUDE_FROM_MAIN 1

+ 4 - 0
Tests/RunCMake/CMP0041/RunCMakeTest.cmake

@@ -6,6 +6,10 @@ set(RunCMake_TEST_OPTIONS "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/NotDefa
 run_cmake(CMP0041-OLD)
 run_cmake(CMP0041-OLD)
 run_cmake(CMP0041-NEW)
 run_cmake(CMP0041-NEW)
 run_cmake(CMP0041-WARN)
 run_cmake(CMP0041-WARN)
+
+# Protect tests from running inside the default install prefix.
+set(RunCMake_TEST_OPTIONS "--install-prefix ${RunCMake_BINARY_DIR}/NotDefaultPrefix")
+
 run_cmake(CMP0041-tid-OLD)
 run_cmake(CMP0041-tid-OLD)
 run_cmake(CMP0041-tid-NEW)
 run_cmake(CMP0041-tid-NEW)
 run_cmake(CMP0041-tid-WARN)
 run_cmake(CMP0041-tid-WARN)

+ 1 - 0
Tests/RunCMake/CMakePresets/FuturePresetInstallDirField-result.txt

@@ -0,0 +1 @@
+1

+ 2 - 0
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.$

+ 11 - 0
Tests/RunCMake/CMakePresets/FuturePresetInstallDirField.json.in

@@ -0,0 +1,11 @@
+{
+  "version": 1,
+  "configurePresets": [
+    {
+      "name": "FuturePresetInstallDirField",
+      "generator": "@RunCMake_GENERATOR@",
+      "binaryDir": "${sourceDir}/build",
+      "installDir": "${sourceDir}/install"
+    }
+  ]
+}

+ 30 - 0
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"
+        }
+    ]
+}

+ 3 - 0
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")

+ 3 - 0
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")

+ 3 - 0
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")

+ 3 - 0
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")

+ 8 - 0
Tests/RunCMake/CMakePresets/RunCMakeTest.cmake

@@ -94,6 +94,7 @@ run_cmake_presets(InvalidVariableValue)
 run_cmake_presets(ExtraRootField)
 run_cmake_presets(ExtraRootField)
 run_cmake_presets(ExtraPresetField)
 run_cmake_presets(ExtraPresetField)
 run_cmake_presets(ExtraVariableField)
 run_cmake_presets(ExtraVariableField)
+run_cmake_presets(FuturePresetInstallDirField)
 run_cmake_presets(InvalidPresetVendor)
 run_cmake_presets(InvalidPresetVendor)
 set(CMakePresets_SCHEMA_EXPECTED_RESULT 0)
 set(CMakePresets_SCHEMA_EXPECTED_RESULT 0)
 run_cmake_presets(DuplicatePresets)
 run_cmake_presets(DuplicatePresets)
@@ -181,6 +182,13 @@ run_cmake_presets(GoodInheritanceMulti)
 run_cmake_presets(GoodInheritanceMultiSecond)
 run_cmake_presets(GoodInheritanceMultiSecond)
 run_cmake_presets(GoodInheritanceMacro)
 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
 # Test bad preset arguments
 run_cmake_presets(VendorMacro)
 run_cmake_presets(VendorMacro)
 run_cmake_presets(InvalidGenerator)
 run_cmake_presets(InvalidGenerator)

+ 3 - 0
Tests/RunCMake/CommandLine/RunCMakeTest.cmake

@@ -61,6 +61,9 @@ run_cmake_command(build-bad-dir
 run_cmake_command(build-bad-generator
 run_cmake_command(build-bad-generator
   ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-bad-generator)
   ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-bad-generator)
 
 
+
+run_cmake_command(install-prefix-no-arg ${CMAKE_COMMAND} -B DummyBuildDir --install-prefix)
+
 run_cmake_command(install-no-dir
 run_cmake_command(install-no-dir
   ${CMAKE_COMMAND} --install)
   ${CMAKE_COMMAND} --install)
 run_cmake_command(install-bad-dir
 run_cmake_command(install-bad-dir

+ 1 - 0
Tests/RunCMake/CommandLine/install-prefix-no-arg-result.txt

@@ -0,0 +1 @@
+1

+ 1 - 0
Tests/RunCMake/CommandLine/install-prefix-no-arg-stderr.txt

@@ -0,0 +1 @@
+^CMake Error: No install directory specified for --install-prefix

+ 5 - 3
Tests/RunCMake/IfacePaths/RunCMakeTest.cmake

@@ -18,6 +18,9 @@ run_cmake(BinaryDirectoryInInterface)
 set(RunCMake_TEST_OPTIONS "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/DirInInstallPrefix/prefix")
 set(RunCMake_TEST_OPTIONS "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/DirInInstallPrefix/prefix")
 run_cmake(DirInInstallPrefix)
 run_cmake(DirInInstallPrefix)
 
 
+set(RunCMake_TEST_OPTIONS "--install-prefix=${RunCMake_BINARY_DIR}/DirInInstallPrefix/prefix")
+run_cmake(DirInInstallPrefix)
+
 configure_file(
 configure_file(
   "${RunCMake_SOURCE_DIR}/CMakeLists.txt"
   "${RunCMake_SOURCE_DIR}/CMakeLists.txt"
   "${RunCMake_BINARY_DIR}/copy/CMakeLists.txt"
   "${RunCMake_BINARY_DIR}/copy/CMakeLists.txt"
@@ -34,14 +37,13 @@ configure_file(
   COPYONLY
   COPYONLY
 )
 )
 set(RunCMake_TEST_OPTIONS
 set(RunCMake_TEST_OPTIONS
-  "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/copy/SourceDirectoryInInterface/prefix"
+  "--install-prefix=${RunCMake_BINARY_DIR}/copy/SourceDirectoryInInterface/prefix"
   "-DTEST_FILE=${RunCMake_BINARY_DIR}/copy/SourceDirectoryInInterface.cmake"
   "-DTEST_FILE=${RunCMake_BINARY_DIR}/copy/SourceDirectoryInInterface.cmake"
   )
   )
 set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/copy")
 set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/copy")
 run_cmake(InstallInSrcDir)
 run_cmake(InstallInSrcDir)
 unset(RunCMake_TEST_SOURCE_DIR)
 unset(RunCMake_TEST_SOURCE_DIR)
 
 
-set(RunCMake_TEST_OPTIONS "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/InstallInBinDir-build/prefix")
 set(RunCMake_TEST_OPTIONS
 set(RunCMake_TEST_OPTIONS
   "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/InstallInBinDir-build/prefix"
   "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/InstallInBinDir-build/prefix"
   "-DTEST_FILE=${RunCMake_SOURCE_DIR}/BinaryDirectoryInInterface.cmake"
   "-DTEST_FILE=${RunCMake_SOURCE_DIR}/BinaryDirectoryInInterface.cmake"
@@ -77,7 +79,7 @@ foreach(policyStatus NEW OLD "")
     set(policySuffix -CMP0052-${policyStatus})
     set(policySuffix -CMP0052-${policyStatus})
   endif()
   endif()
   set(RunCMake_TEST_OPTIONS
   set(RunCMake_TEST_OPTIONS
-    "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/prefix" ${policyOption}
+    "--install-prefix ${RunCMake_BINARY_DIR}/prefix" ${policyOption}
     "-DTEST_FILE=${RunCMake_SOURCE_DIR}/BinaryDirectoryInInterface.cmake"
     "-DTEST_FILE=${RunCMake_SOURCE_DIR}/BinaryDirectoryInInterface.cmake"
     )
     )
   # Set the RunCMake_TEST_SOURCE_DIR here to the copy too. This is needed to run
   # Set the RunCMake_TEST_SOURCE_DIR here to the copy too. This is needed to run