Quellcode durchsuchen

Merge topic 'preset-includes-macro-expansion'

1a38ffc656 presets: Expand more macros in the `include` directive

Acked-by: Kitware Robot <[email protected]>
Merge-request: !9108
Brad King vor 1 Jahr
Ursprung
Commit
14ed766e12

+ 6 - 1
Help/manual/cmake-presets.7.rst

@@ -78,6 +78,9 @@ The root object recognizes the following fields:
   ``8``
   ``8``
     .. versionadded:: 3.28
     .. versionadded:: 3.28
 
 
+  ``9``
+    .. versionadded:: 3.30
+
 ``cmakeMinimumRequired``
 ``cmakeMinimumRequired``
   An optional object representing the minimum version of CMake needed to
   An optional object representing the minimum version of CMake needed to
   build this project. This object consists of the following fields:
   build this project. This object consists of the following fields:
@@ -146,7 +149,9 @@ guaranteed to be provided by the project. ``CMakeUserPresets.json`` may
 include files from anywhere.
 include files from anywhere.
 
 
 Starting from version ``7``, the ``include`` field supports
 Starting from version ``7``, the ``include`` field supports
-`macro expansion`_, but only ``$penv{}`` macro expansion.
+`macro expansion`_, but only ``$penv{}`` macro expansion. Starting from version
+``9``, other macro expansions are also available, except for preset specific
+ones (e.g. ``presetName``), and ``$env{}``.
 
 
 Configure Preset
 Configure Preset
 ^^^^^^^^^^^^^^^^
 ^^^^^^^^^^^^^^^^

+ 18 - 0
Help/manual/presets/schema.json

@@ -124,6 +124,24 @@
         "include": { "$ref": "#/definitions/include" }
         "include": { "$ref": "#/definitions/include" }
       },
       },
       "additionalProperties": false
       "additionalProperties": false
+    },
+    {
+      "properties": {
+        "$schema": { "$ref": "#/definitions/$schema" },
+        "version": {
+          "const": 9,
+          "description": "A required integer representing the version of the JSON schema."
+        },
+        "cmakeMinimumRequired": { "$ref": "#/definitions/cmakeMinimumRequired" },
+        "vendor": { "$ref": "#/definitions/vendor" },
+        "configurePresets": { "$ref": "#/definitions/configurePresetsV7" },
+        "buildPresets": { "$ref": "#/definitions/buildPresetsV4" },
+        "testPresets": { "$ref": "#/definitions/testPresetsV6" },
+        "packagePresets": { "$ref": "#/definitions/packagePresetsV6" },
+        "workflowPresets": { "$ref": "#/definitions/workflowPresetsV6" },
+        "include": { "$ref": "#/definitions/include" }
+      },
+      "additionalProperties": false
     }
     }
   ],
   ],
   "required": [
   "required": [

+ 7 - 0
Help/release/dev/preset-includes-macro-expansion.rst

@@ -0,0 +1,7 @@
+preset-includes-macro-expansion
+-------------------------------
+
+* :manual:`cmake-presets(7)` files now support schema version ``9``:
+
+  * ``include`` fields now expand all macros except ``$env{}`` and
+    preset-specific macros.

+ 6 - 1
Source/cmCMakePresetsGraphReadJSON.cxx

@@ -36,10 +36,11 @@ using JSONHelperBuilder = cmJSONHelperBuilder;
 using ExpandMacroResult = cmCMakePresetsGraphInternal::ExpandMacroResult;
 using ExpandMacroResult = cmCMakePresetsGraphInternal::ExpandMacroResult;
 using MacroExpander = cmCMakePresetsGraphInternal::MacroExpander;
 using MacroExpander = cmCMakePresetsGraphInternal::MacroExpander;
 using MacroExpanderVector = cmCMakePresetsGraphInternal::MacroExpanderVector;
 using MacroExpanderVector = cmCMakePresetsGraphInternal::MacroExpanderVector;
+using cmCMakePresetsGraphInternal::BaseMacroExpander;
 using cmCMakePresetsGraphInternal::ExpandMacros;
 using cmCMakePresetsGraphInternal::ExpandMacros;
 
 
 constexpr int MIN_VERSION = 1;
 constexpr int MIN_VERSION = 1;
-constexpr int MAX_VERSION = 8;
+constexpr int MAX_VERSION = 9;
 
 
 struct CMakeVersion
 struct CMakeVersion
 {
 {
@@ -732,6 +733,10 @@ bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
 
 
   MacroExpanderVector macroExpanders{};
   MacroExpanderVector macroExpanders{};
 
 
+  if (v >= 9) {
+    macroExpanders.push_back(
+      cm::make_unique<BaseMacroExpander>(*this, filename));
+  }
   macroExpanders.push_back(cm::make_unique<EnvironmentMacroExpander>());
   macroExpanders.push_back(cm::make_unique<EnvironmentMacroExpander>());
 
 
   for (Json::ArrayIndex i = 0; i < presets.Include.size(); ++i) {
   for (Json::ArrayIndex i = 0; i < presets.Include.size(); ++i) {

+ 5 - 0
Tests/RunCMake/CMakePresets/IncludeExpansionOtherMacros-stdout.txt

@@ -0,0 +1,5 @@
+^Not searching for unused variables given on the command line\.
+Available configure presets:
+
+  "Include"
+  "IncludeCommon"$

+ 10 - 0
Tests/RunCMake/CMakePresets/IncludeExpansionOtherMacros.json.in

@@ -0,0 +1,10 @@
+{
+  "version": 9,
+  "include": ["${sourceDir}/IncludeCommon.json"],
+  "configurePresets": [
+    {
+      "name": "Include",
+      "inherits": ["IncludeCommon"]
+    }
+  ]
+}

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

@@ -407,6 +407,7 @@ set(CMakePresets_EXTRA_FILES
 set(ENV{TEST_ENV_INCLUDE_DIR} ${RunCMake_BINARY_DIR}/IncludeExpansion)
 set(ENV{TEST_ENV_INCLUDE_DIR} ${RunCMake_BINARY_DIR}/IncludeExpansion)
 run_cmake_presets(IncludeExpansion --list-presets)
 run_cmake_presets(IncludeExpansion --list-presets)
 unset(ENV{TEST_ENV_INCLUDE_DIR})
 unset(ENV{TEST_ENV_INCLUDE_DIR})
+run_cmake_presets(IncludeExpansionOtherMacros --list-presets)
 unset(CMakePresets_EXTRA_FILES)
 unset(CMakePresets_EXTRA_FILES)
 run_cmake_presets(IncludeNotFound)
 run_cmake_presets(IncludeNotFound)
 run_cmake_presets(IncludeCycle)
 run_cmake_presets(IncludeCycle)