From a8d73085f4779390fe52a4115a7ba5d0edc5631b Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Thu, 3 Feb 2022 17:36:51 -0500 Subject: CPack: Add support for presets Fixes: #23117 --- Help/manual/cmake-presets.7.rst | 140 ++++++++++++++- Help/manual/cmake.1.rst | 6 +- Help/manual/cpack.1.rst | 8 + Help/manual/presets/schema.json | 200 ++++++++++++++++++++- Help/release/dev/cmake-presets-package.rst | 5 + Source/CPack/cpack.cxx | 169 ++++++++++++++++- Source/cmake.cxx | 5 + Tests/RunCMake/CMakeLists.txt | 4 + .../RunCMake/CMakePresetsPackage/CMakeLists.txt.in | 3 + .../Good-package-config-file-check.cmake | 6 + .../Good-package-configurations-check.cmake | 18 ++ .../Good-package-debug-stdout.txt | 2 + .../Good-package-generators-check.cmake | 1 + .../Good-package-no-environment-check.cmake | 7 + .../Good-package-package-directory-check.cmake | 6 + .../Good-package-package-name-check.cmake | 7 + .../Good-package-package-version-check.cmake | 7 + .../Good-package-variables-check.cmake | 6 + .../Good-package-verbose-stdout.txt | 1 + .../Good-package-with-environment-check.cmake | 7 + Tests/RunCMake/CMakePresetsPackage/Good.cmake | 31 ++++ Tests/RunCMake/CMakePresetsPackage/Good.json.in | 135 ++++++++++++++ .../CMakePresetsPackage/RunCMakeTest.cmake | 101 +++++++++++ .../UnsupportedVersion-configure-x-result.txt | 1 + .../UnsupportedVersion-configure-x-stderr.txt | 2 + .../CMakePresetsPackage/UnsupportedVersion.json.in | 4 + Tests/RunCMake/CMakePresetsPackage/check.cmake | 3 + 27 files changed, 872 insertions(+), 13 deletions(-) create mode 100644 Help/release/dev/cmake-presets-package.rst create mode 100644 Tests/RunCMake/CMakePresetsPackage/CMakeLists.txt.in create mode 100644 Tests/RunCMake/CMakePresetsPackage/Good-package-config-file-check.cmake create mode 100644 Tests/RunCMake/CMakePresetsPackage/Good-package-configurations-check.cmake create mode 100644 Tests/RunCMake/CMakePresetsPackage/Good-package-debug-stdout.txt create mode 100644 Tests/RunCMake/CMakePresetsPackage/Good-package-generators-check.cmake create mode 100644 Tests/RunCMake/CMakePresetsPackage/Good-package-no-environment-check.cmake create mode 100644 Tests/RunCMake/CMakePresetsPackage/Good-package-package-directory-check.cmake create mode 100644 Tests/RunCMake/CMakePresetsPackage/Good-package-package-name-check.cmake create mode 100644 Tests/RunCMake/CMakePresetsPackage/Good-package-package-version-check.cmake create mode 100644 Tests/RunCMake/CMakePresetsPackage/Good-package-variables-check.cmake create mode 100644 Tests/RunCMake/CMakePresetsPackage/Good-package-verbose-stdout.txt create mode 100644 Tests/RunCMake/CMakePresetsPackage/Good-package-with-environment-check.cmake create mode 100644 Tests/RunCMake/CMakePresetsPackage/Good.cmake create mode 100644 Tests/RunCMake/CMakePresetsPackage/Good.json.in create mode 100644 Tests/RunCMake/CMakePresetsPackage/RunCMakeTest.cmake create mode 100644 Tests/RunCMake/CMakePresetsPackage/UnsupportedVersion-configure-x-result.txt create mode 100644 Tests/RunCMake/CMakePresetsPackage/UnsupportedVersion-configure-x-stderr.txt create mode 100644 Tests/RunCMake/CMakePresetsPackage/UnsupportedVersion.json.in create mode 100644 Tests/RunCMake/CMakePresetsPackage/check.cmake diff --git a/Help/manual/cmake-presets.7.rst b/Help/manual/cmake-presets.7.rst index 16cd54e..35dac76 100644 --- a/Help/manual/cmake-presets.7.rst +++ b/Help/manual/cmake-presets.7.rst @@ -58,6 +58,9 @@ The root object recognizes the following fields: ``5`` .. versionadded:: 3.24 + ``6`` + .. versionadded:: 3.25 + ``cmakeMinimumRequired`` An optional object representing the minimum version of CMake needed to build this project. This object consists of the following fields: @@ -128,7 +131,8 @@ that may contain the following fields: This identifier is used in the :ref:`cmake --preset ` option. There must not be two configure presets in the union of ``CMakePresets.json`` and ``CMakeUserPresets.json`` in the same directory with the same name. - However, a configure preset may have the same name as a build or test preset. + However, a configure preset may have the same name as a build, test, or + package preset. ``hidden`` An optional boolean specifying whether or not a preset should be hidden. @@ -350,7 +354,8 @@ that may contain the following fields: :ref:`cmake --build --preset ` option. There must not be two build presets in the union of ``CMakePresets.json`` and ``CMakeUserPresets.json`` in the same directory with the same name. - However, a build preset may have the same name as a configure or test preset. + However, a build preset may have the same name as a configure, test, or + package preset. ``hidden`` An optional boolean specifying whether or not a preset should be hidden. @@ -510,7 +515,8 @@ that may contain the following fields: This identifier is used in the :option:`ctest --preset` option. There must not be two test presets in the union of ``CMakePresets.json`` and ``CMakeUserPresets.json`` in the same directory with the same name. - However, a test preset may have the same name as a configure or build preset. + However, a test preset may have the same name as a configure, build, or + package preset. ``hidden`` An optional boolean specifying whether or not a preset should be hidden. @@ -833,6 +839,134 @@ that may contain the following fields: Equivalent to passing :option:`--no-tests=ignore ` on the command line. +Package Preset +^^^^^^^^^^^^^^ + +Package presets may be used in schema version ``6`` or above. Each entry of +the ``packagePresets`` array is a JSON object that may contain the following +fields: + +``name`` + A required string representing the machine-friendly name of the preset. + This identifier is used in the :option:`cpack --preset` option. + There must not be two package presets in the union of ``CMakePresets.json`` + and ``CMakeUserPresets.json`` in the same directory with the same name. + However, a package preset may have the same name as a configure, build, or + test preset. + +``hidden`` + An optional boolean specifying whether or not a preset should be hidden. + If a preset is hidden, it cannot be used in the + :option:`--preset ` argument + and does not have to have a valid ``configurePreset``, even from + inheritance. ``hidden`` presets are intended to be used as a base for + other presets to inherit via the ``inherits`` field. + +``inherits`` + An optional array of strings representing the names of presets to inherit + from. This field can also be a string, which is equivalent to an array + containing one string. + + The preset will inherit all of the fields from the + ``inherits`` presets by default (except ``name``, ``hidden``, + ``inherits``, ``description``, and ``displayName``), but can override + them as desired. If multiple ``inherits`` presets provide conflicting + values for the same field, the earlier preset in the ``inherits`` list + will be preferred. + + A preset can only inherit from another preset that is defined in the + same file or in one of the files it includes (directly or indirectly). + Presets in ``CMakePresets.json`` may not inherit from presets in + ``CMakeUserPresets.json``. + +``condition`` + An optional `Condition`_ object. + +``vendor`` + 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, it should follow the same conventions as the + root-level ``vendor`` field. If vendors use their own per-preset + ``vendor`` field, they should implement inheritance in a sensible manner + when appropriate. + +``displayName`` + An optional string with a human-friendly name of the preset. + +``description`` + An optional string with a human-friendly description of the preset. + +``environment`` + An optional map of environment variables. The key is the variable name + (which may not be an empty string), and the value is either ``null`` or + a string representing the value of the variable. Each variable is set + regardless of whether or not a value was given to it by the process's + environment. This field supports macro expansion, and environment + variables in this map may reference each other, and may be listed in any + order, as long as such references do not cause a cycle (for example, if + ``ENV_1`` is ``$env{ENV_2}``, ``ENV_2`` may not be ``$env{ENV_1}``.) + + Environment variables are inherited through the ``inherits`` field, and + the preset's environment will be the union of its own ``environment`` + and the ``environment`` from all its parents. If multiple presets in + this union define the same variable, the standard rules of ``inherits`` + are applied. Setting a variable to ``null`` causes it to not be set, + even if a value was inherited from another preset. + +``configurePreset`` + An optional string specifying the name of a configure preset to + associate with this package preset. If ``configurePreset`` is not + specified, it must be inherited from the inherits preset (unless this + preset is hidden). The build directory is inferred from the configure + preset, so packaging will run in the same ``binaryDir`` that the + configuration did and build did. + +``inheritConfigureEnvironment`` + An optional boolean that defaults to true. If true, the environment + variables from the associated configure preset are inherited after all + inherited package preset environments, but before environment variables + explicitly specified in this package preset. + +``generators`` + An optional list of strings representing generators for CPack to use. + +``configurations`` + An optional list of strings representing build configurations for CPack to + package. + +``variables`` + An optional map of variables to pass to CPack, equivalent to + :option:`-D ` arguments. Each key is the name of a variable, and + the value is the string to assign to that variable. + +``configFile`` + An optional string representing the config file for CPack to use. + +``output`` + An optional object specifying output options. Valid keys are: + + ``debug`` + An optional boolean specifying whether or not to print debug information. + A value of ``true`` is equivalent to passing + :option:`--debug ` on the command line. + + ``verbose`` + An optional boolean specifying whether or not to print verbosely. A value + of ``true`` is equivalent to passing :option:`--verbose ` + on the command line. + +``packageName`` + An optional string representing the package name. + +``packageVersion`` + An optional string representing the package version. + +``packageDirectory`` + An optional string representing the directory in which to place the package. + +``vendorName`` + An optional string representing the vendor name. + Condition ^^^^^^^^^ diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 8cec9d4..a3e9fd0 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -500,9 +500,9 @@ Options .. option:: --list-presets[=] Lists the available presets of the specified ````. Valid values for - ```` are ``configure``, ``build``, ``test``, or ``all``. If ```` - is omitted, ``configure`` is assumed. The current working directory must - contain CMake preset files. + ```` are ``configure``, ``build``, ``test``, ``package``, or ``all``. + If ```` is omitted, ``configure`` is assumed. The current working + directory must contain CMake preset files. .. _`Build Tool Mode`: diff --git a/Help/manual/cpack.1.rst b/Help/manual/cpack.1.rst index a95df8b..3f26d72 100644 --- a/Help/manual/cpack.1.rst +++ b/Help/manual/cpack.1.rst @@ -119,6 +119,14 @@ Options Override/define :variable:`CPACK_PACKAGE_VENDOR`. +.. option:: --preset + + Use a preset from :manual:`cmake-presets(7)`. + +.. option:: --list-presets + + List presets from :manual:`cmake-presets(7)`. + .. include:: OPTIONS_HELP.txt See Also diff --git a/Help/manual/presets/schema.json b/Help/manual/presets/schema.json index c96405c..f3a7532 100644 --- a/Help/manual/presets/schema.json +++ b/Help/manual/presets/schema.json @@ -72,6 +72,22 @@ "include": { "$ref": "#/definitions/include"} }, "additionalProperties": false + }, + { + "properties": { + "version": { + "const": 6, + "description": "A required integer representing the version of the JSON schema." + }, + "cmakeMinimumRequired": { "$ref": "#/definitions/cmakeMinimumRequired"}, + "vendor": { "$ref": "#/definitions/vendor" }, + "configurePresets": { "$ref": "#/definitions/configurePresetsV3"}, + "buildPresets": { "$ref": "#/definitions/buildPresetsV4"}, + "testPresets": { "$ref": "#/definitions/testPresetsV5"}, + "packagePresets": { "$ref": "#/definitions/packagePresetsV6"}, + "include": { "$ref": "#/definitions/include"} + }, + "additionalProperties": false } ], "required": [ @@ -476,12 +492,12 @@ "properties": { "name": { "type": "string", - "description": "A required string representing the machine-friendly name of the preset. This identifier is used in the --preset argument. There must not be two presets (configure, build, or test) in the union of CMakePresets.json and CMakeUserPresets.json in the same directory with the same name.", + "description": "A required string representing the machine-friendly name of the preset. This identifier is used in the --preset argument. There must not be two presets (configure, build, test, or package) in the union of CMakePresets.json and CMakeUserPresets.json in the same directory with the same name.", "minLength": 1 }, "hidden": { "type": "boolean", - "description": "An optional boolean specifying whether or not a preset should be hidden. If a preset is hidden, it cannot be used in the --preset argument, will not show up in the CMake GUI, and does not have to have a valid configurePreset, even from inheritance. Hidden presets are intended to be used as a base for other presets to inherit via the inherits field." + "description": "An optional boolean specifying whether or not a preset should be hidden. If a preset is hidden, it cannot be used in the --preset argument and does not have to have a valid configurePreset, even from inheritance. Hidden presets are intended to be used as a base for other presets to inherit via the inherits field." }, "inherits": { "anyOf": [ @@ -728,12 +744,12 @@ "properties": { "name": { "type": "string", - "description": "A required string representing the machine-friendly name of the preset. This identifier is used in the --preset argument. There must not be two presets (configure, build, or test) in the union of CMakePresets.json and CMakeUserPresets.json in the same directory with the same name.", + "description": "A required string representing the machine-friendly name of the preset. This identifier is used in the --preset argument. There must not be two presets (configure, build, test, or package) in the union of CMakePresets.json and CMakeUserPresets.json in the same directory with the same name.", "minLength": 1 }, "hidden": { "type": "boolean", - "description": "An optional boolean specifying whether or not a preset should be hidden. If a preset is hidden, it cannot be used in the --preset argument, will not show up in the CMake GUI, and does not have to have a valid configurePreset, even from inheritance. Hidden presets are intended to be used as a base for other presets to inherit via the inherits field." + "description": "An optional boolean specifying whether or not a preset should be hidden. If a preset is hidden, it cannot be used in the --preset argument and does not have to have a valid configurePreset, even from inheritance. Hidden presets are intended to be used as a base for other presets to inherit via the inherits field." }, "inherits": { "anyOf": [ @@ -1129,6 +1145,182 @@ "additionalProperties": false } }, + "packagePresetsItemsV6": { + "type": "array", + "description": "An optional array of package preset objects. Used to specify arguments to cpack. Available in version 6 and higher.", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "A required string representing the machine-friendly name of the preset. This identifier is used in the --preset argument. There must not be two presets (configure, build, test, or package) in the union of CMakePresets.json and CMakeUserPresets.json in the same directory with the same name.", + "minLength": 1 + }, + "hidden": { + "type": "boolean", + "description": "An optional boolean specifying whether or not a preset should be hidden. If a preset is hidden, it cannot be used in the --preset argument and does not have to have a valid configurePreset, even from inheritance. Hidden presets are intended to be used as a base for other presets to inherit via the inherits field." + }, + "inherits": { + "anyOf": [ + { + "type": "string", + "description": "An optional string representing the name of the package preset to inherit from.", + "minLength": 1 + }, + { + "type": "array", + "description": "An optional array of strings representing the names of package presets to inherit from. The preset will inherit all of the fields from the inherits presets by default (except name, hidden, inherits, description, and displayName), but can override them as desired. If multiple inherits presets provide conflicting values for the same field, the earlier preset in the inherits list will be preferred. Presets in CMakePresets.json must not inherit from presets in CMakeUserPresets.json.", + "items": { + "type": "string", + "description": "An optional string representing the name of the preset to inherit from.", + "minLength": 1 + } + } + ] + }, + "configurePreset": { + "type": "string", + "description": "An optional string specifying the name of a configure preset to associate with this package preset. If configurePreset is not specified, it must be inherited from the inherits preset (unless this preset is hidden). The build tree directory is inferred from the configure preset.", + "minLength": 1 + }, + "vendor": { + "type": "object", + "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, it should follow the same conventions as the root-level vendor field. If vendors use their own per-preset vendor field, they should implement inheritance in a sensible manner when appropriate.", + "properties": {} + }, + "displayName": { + "type": "string", + "description": "An optional string with a human-friendly name of the preset." + }, + "description": { + "type": "string", + "description": "An optional string with a human-friendly description of the preset." + }, + "inheritConfigureEnvironment": { + "type": "boolean", + "description": "An optional boolean that defaults to true. If true, the environment variables from the associated configure preset are inherited after all inherited package preset environments, but before environment variables explicitly specified in this package preset." + }, + "environment": { + "type": "object", + "description": "An optional map of environment variables. The key is the variable name (which must not be an empty string). Each variable is set regardless of whether or not a value was given to it by the process's environment. This field supports macro expansion, and environment variables in this map may reference each other, and may be listed in any order, as long as such references do not cause a cycle (for example,if ENV_1 is $env{ENV_2}, ENV_2 may not be $env{ENV_1}.) Environment variables are inherited through the inherits field, and the preset's environment will be the union of its own environment and the environment from all its parents. If multiple presets in this union define the same variable, the standard rules of inherits are applied. Setting a variable to null causes it to not be set, even if a value was inherited from another preset.", + "properties": {}, + "additionalProperties": { + "anyOf": [ + { + "type": "null", + "description": "Setting a variable to null causes it to not be set, even if a value was inherited from another preset." + }, + { + "type": "string", + "description": "A string representing the value of the variable." + } + ] + }, + "propertyNames": { + "pattern": "^.+$" + } + }, + "condition": { "$ref": "#/definitions/topCondition" }, + "generators": { + "type": "array", + "description": "An optional list of strings representing generators for CPack to use.", + "items": { + "type": "string", + "description": "An optional string representing the name of the CPack generator to use." + } + }, + "configurations": { + "type": "array", + "description": "An optional list of strings representing build configurations for CPack to package.", + "items": { + "type": "string", + "description": "An optional string representing the name of the configuration to use." + } + }, + "variables": { + "type": "object", + "description": "An optional map of variables to pass to CPack, equivalent to -D arguments. Each key is the name of a variable, and the value is the string to assign to that variable.", + "items": { + "type": "string", + "description": "An optional string representing the value of the variable." + } + }, + "configFile": { + "type": "string", + "description": "An optional string representing the config file for CPack to use." + }, + "output": { + "type": "object", + "description": "An optional object specifying output options.", + "properties": { + "debug": { + "type": "boolean", + "description": "An optional boolean specifying whether or not to print debug information. A value of true is equivalent to passing --debug on the command line." + }, + "verbose": { + "type": "boolean", + "description": "An optional boolean specifying whether or not to print verbosely. A value of true is equivalent to passing --verbose on the command line." + } + }, + "additionalProperties": false + }, + "packageName": { + "type": "string", + "description": "An optional string representing the package name." + }, + "packageVersion": { + "type": "string", + "description": "An optional string representing the package version." + }, + "packageDirectory": { + "type": "string", + "description": "An optional string representing the directory in which to place the package." + }, + "vendorName": { + "type": "string", + "description": "An optional string representing the vendor name." + } + }, + "required": [ + "name" + ] + } + }, + "packagePresetsV6": { + "type": "array", + "description": "An optional array of package preset objects. Used to specify arguments to cpack. Available in version 6 and higher.", + "allOf": [ + { "$ref": "#/definitions/packagePresetsItemsV6" } + ], + "items": { + "type": "object", + "properties": { + "name": {}, + "hidden": {}, + "inherits": {}, + "configurePreset": {}, + "vendor": {}, + "displayName": {}, + "description": {}, + "inheritConfigureEnvironment": {}, + "environment": {}, + "condition": {}, + "generators": {}, + "configurations": {}, + "variables": {}, + "configFile": {}, + "output": {}, + "packageName": {}, + "packageVersion": {}, + "packageDirectory": {}, + "vendorName": {} + }, + "required": [ + "name" + ], + "additionalProperties": false + } + }, "condition": { "anyOf": [ { diff --git a/Help/release/dev/cmake-presets-package.rst b/Help/release/dev/cmake-presets-package.rst new file mode 100644 index 0000000..8f7ea6b --- /dev/null +++ b/Help/release/dev/cmake-presets-package.rst @@ -0,0 +1,5 @@ +cmake-presets-package +--------------------- + +* The :manual:`cmake-presets(7)` schema version has been bumped to ``6``. +* The :manual:`cmake-presets(7)` format now supports a ``packagePresets`` field. diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index 4d9a42a..631bfd9 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -1,6 +1,7 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ +#include #include #include #include @@ -11,10 +12,12 @@ #include #include +#include #include #include "cmsys/Encoding.hxx" +#include "cmCMakePresetsGraph.h" #include "cmCPackGenerator.h" #include "cmCPackGeneratorFactory.h" #include "cmCPackLog.h" @@ -58,6 +61,8 @@ const char* cmDocumentationOptions[][2] = { { "-R ", "Override/define CPACK_PACKAGE_VERSION" }, { "-B ", "Override/define CPACK_PACKAGE_DIRECTORY" }, { "--vendor ", "Override/define CPACK_PACKAGE_VENDOR" }, + { "--preset", "Read arguments from a package preset" }, + { "--list-presets", "List available package presets" }, { nullptr, nullptr } }; @@ -116,6 +121,9 @@ int main(int argc, char const* const* argv) std::string cpackProjectVendor; std::string cpackConfigFile; + std::string preset; + bool listPresets = false; + std::map definitions; auto const verboseLambda = [&log](const std::string&, cmake*, @@ -182,6 +190,10 @@ int main(int argc, char const* const* argv) CommandArgument::setToValue(cpackProjectPatch) }, CommandArgument{ "--vendor", CommandArgument::Values::One, CommandArgument::setToValue(cpackProjectVendor) }, + CommandArgument{ "--preset", CommandArgument::Values::One, + CommandArgument::setToValue(preset) }, + CommandArgument{ "--list-presets", CommandArgument::Values::Zero, + CommandArgument::setToTrue(listPresets) }, CommandArgument{ "-D", CommandArgument::Values::One, [&log, &definitions](const std::string& arg, cmake*, @@ -228,6 +240,160 @@ int main(int argc, char const* const* argv) } } + cmCPackGeneratorFactory generators; + generators.SetLogger(&log); + + // Set up presets + if (!preset.empty() || listPresets) { + const auto workingDirectory = cmSystemTools::GetCurrentWorkingDirectory(); + + auto const presetGeneratorsPresent = + [&generators](const cmCMakePresetsGraph::PackagePreset& p) { + return std::all_of(p.Generators.begin(), p.Generators.end(), + [&generators](const std::string& gen) { + return generators.GetGeneratorsList().count( + gen) != 0; + }); + }; + + cmCMakePresetsGraph presetsGraph; + auto result = presetsGraph.ReadProjectPresets(workingDirectory); + if (result != cmCMakePresetsGraph::ReadFileResult::READ_OK) { + cmCPack_Log(&log, cmCPackLog::LOG_ERROR, + "Could not read presets from " + << workingDirectory << ": " + << cmCMakePresetsGraph::ResultToString(result) + << std::endl); + return 1; + } + + if (listPresets) { + presetsGraph.PrintPackagePresetList(presetGeneratorsPresent); + return 0; + } + + auto presetPair = presetsGraph.PackagePresets.find(preset); + if (presetPair == presetsGraph.PackagePresets.end()) { + cmCPack_Log(&log, cmCPackLog::LOG_ERROR, + "No such package preset in " << workingDirectory << ": \"" + << preset << '"' << std::endl); + presetsGraph.PrintPackagePresetList(presetGeneratorsPresent); + return 1; + } + + if (presetPair->second.Unexpanded.Hidden) { + cmCPack_Log(&log, cmCPackLog::LOG_ERROR, + "Cannot use hidden package preset in " + << workingDirectory << ": \"" << preset << '"' + << std::endl); + presetsGraph.PrintPackagePresetList(presetGeneratorsPresent); + return 1; + } + + auto const& expandedPreset = presetPair->second.Expanded; + if (!expandedPreset) { + cmCPack_Log(&log, cmCPackLog::LOG_ERROR, + "Could not evaluate package preset \"" + << preset << "\": Invalid macro expansion" << std::endl); + presetsGraph.PrintPackagePresetList(presetGeneratorsPresent); + return 1; + } + + if (!expandedPreset->ConditionResult) { + cmCPack_Log(&log, cmCPackLog::LOG_ERROR, + "Cannot use disabled package preset in " + << workingDirectory << ": \"" << preset << '"' + << std::endl); + presetsGraph.PrintPackagePresetList(presetGeneratorsPresent); + return 1; + } + + if (!presetGeneratorsPresent(presetPair->second.Unexpanded)) { + cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Cannot use preset"); + presetsGraph.PrintPackagePresetList(presetGeneratorsPresent); + return 1; + } + + auto configurePresetPair = + presetsGraph.ConfigurePresets.find(expandedPreset->ConfigurePreset); + if (configurePresetPair == presetsGraph.ConfigurePresets.end()) { + cmCPack_Log(&log, cmCPackLog::LOG_ERROR, + "No such configure preset in " + << workingDirectory << ": \"" + << expandedPreset->ConfigurePreset << '"' << std::endl); + presetsGraph.PrintConfigurePresetList(); + return 1; + } + + if (configurePresetPair->second.Unexpanded.Hidden) { + cmCPack_Log(&log, cmCPackLog::LOG_ERROR, + "Cannot use hidden configure preset in " + << workingDirectory << ": \"" + << expandedPreset->ConfigurePreset << '"' << std::endl); + presetsGraph.PrintConfigurePresetList(); + return 1; + } + + auto const& expandedConfigurePreset = configurePresetPair->second.Expanded; + if (!expandedConfigurePreset) { + cmCPack_Log(&log, cmCPackLog::LOG_ERROR, + "Could not evaluate configure preset \"" + << expandedPreset->ConfigurePreset + << "\": Invalid macro expansion" << std::endl); + return 1; + } + + cmSystemTools::ChangeDirectory(expandedConfigurePreset->BinaryDir); + + auto presetEnvironment = expandedPreset->Environment; + for (auto const& var : presetEnvironment) { + if (var.second) { + cmSystemTools::PutEnv(cmStrCat(var.first, '=', *var.second)); + } + } + + if (!expandedPreset->ConfigFile.empty() && cpackConfigFile.empty()) { + cpackConfigFile = expandedPreset->ConfigFile; + } + + if (!expandedPreset->Generators.empty() && generator.empty()) { + generator = cmJoin(expandedPreset->Generators, ";"); + } + + if (!expandedPreset->Configurations.empty() && cpackBuildConfig.empty()) { + cpackBuildConfig = cmJoin(expandedPreset->Configurations, ";"); + } + + definitions.insert(expandedPreset->Variables.begin(), + expandedPreset->Variables.end()); + + if (expandedPreset->DebugOutput == true) { + debugLambda("", &cminst, &globalMF); + } + + if (expandedPreset->VerboseOutput == true) { + verboseLambda("", &cminst, &globalMF); + } + + if (!expandedPreset->PackageName.empty() && cpackProjectName.empty()) { + cpackProjectName = expandedPreset->PackageName; + } + + if (!expandedPreset->PackageVersion.empty() && + cpackProjectVersion.empty()) { + cpackProjectVersion = expandedPreset->PackageVersion; + } + + if (!expandedPreset->PackageDirectory.empty() && + cpackProjectDirectory.empty()) { + cpackProjectDirectory = expandedPreset->PackageDirectory; + } + + if (!expandedPreset->VendorName.empty() && cpackProjectVendor.empty()) { + cpackProjectVendor = expandedPreset->VendorName; + } + } + cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Read CPack config file: " << cpackConfigFile << std::endl); @@ -238,9 +404,6 @@ int main(int argc, char const* const* argv) cpackConfigFileSpecified = false; } - cmCPackGeneratorFactory generators; - generators.SetLogger(&log); - cmDocumentation doc; doc.addCPackStandardDocSections(); /* Were we invoked to display doc or to do some work ? diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 9b2b119..ee587b2 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -778,6 +778,7 @@ enum class ListPresets Configure, Build, Test, + Package, All, }; } @@ -1133,6 +1134,8 @@ void cmake::SetArgs(const std::vector& args) listPresets = ListPresets::Build; } else if (value == "test") { listPresets = ListPresets::Test; + } else if (value == "package") { + listPresets = ListPresets::Package; } else if (value == "all") { listPresets = ListPresets::All; } else { @@ -1300,6 +1303,8 @@ void cmake::SetArgs(const std::vector& args) presetsGraph.PrintBuildPresetList(); } else if (listPresets == ListPresets::Test) { presetsGraph.PrintTestPresetList(); + } else if (listPresets == ListPresets::Package) { + presetsGraph.PrintPackagePresetList(); } else if (listPresets == ListPresets::All) { presetsGraph.PrintAllPresets(); } diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 542742c..42ff450 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -999,6 +999,10 @@ add_RunCMake_test(CMakePresetsTest -DPython_EXECUTABLE=${Python_EXECUTABLE} -DCMake_TEST_JSON_SCHEMA=${CMake_TEST_JSON_SCHEMA} ) +add_RunCMake_test(CMakePresetsPackage + -DPython_EXECUTABLE=${Python_EXECUTABLE} + -DCMake_TEST_JSON_SCHEMA=${CMake_TEST_JSON_SCHEMA} + ) add_RunCMake_test(VerifyHeaderSets) diff --git a/Tests/RunCMake/CMakePresetsPackage/CMakeLists.txt.in b/Tests/RunCMake/CMakePresetsPackage/CMakeLists.txt.in new file mode 100644 index 0000000..129184a --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/CMakeLists.txt.in @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.19) +project("@CASE_NAME@" NONE) +include("@CASE_SOURCE_DIR@/@CASE_NAME@.cmake") diff --git a/Tests/RunCMake/CMakePresetsPackage/Good-package-config-file-check.cmake b/Tests/RunCMake/CMakePresetsPackage/Good-package-config-file-check.cmake new file mode 100644 index 0000000..40240f9 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/Good-package-config-file-check.cmake @@ -0,0 +1,6 @@ +include("${RunCMake_TEST_BINARY_DIR}/default/CPackConfig.cmake") + +set(filename "${RunCMake_TEST_BINARY_DIR}/default/_CPack_Packages/${CPACK_TOPLEVEL_TAG}/TGZ/config-file-alt.tar.gz") +if(NOT EXISTS "${filename}") + set(RunCMake_TEST_FAILED "Expected ${filename} to exist but it does not") +endif() diff --git a/Tests/RunCMake/CMakePresetsPackage/Good-package-configurations-check.cmake b/Tests/RunCMake/CMakePresetsPackage/Good-package-configurations-check.cmake new file mode 100644 index 0000000..3d684af --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/Good-package-configurations-check.cmake @@ -0,0 +1,18 @@ +if(RunCMake_GENERATOR_IS_MULTI_CONFIG) + include("${RunCMake_TEST_BINARY_DIR}/default/CPackConfig.cmake") + set(cpack_dir "${RunCMake_TEST_BINARY_DIR}/default/_CPack_Packages/${CPACK_TOPLEVEL_TAG}") + set(contents [[Debug +Release +]]) + + file(GLOB dirs RELATIVE "${cpack_dir}" "${cpack_dir}/*") + foreach(dir IN LISTS dirs) + set(configs_file "${cpack_dir}/${dir}/${CPACK_PACKAGE_FILE_NAME}/configs.txt") + file(READ "${configs_file}" actual_contents) + if(NOT contents STREQUAL actual_contents) + string(REPLACE "\n" "\n " contents_formatted "${contents}") + string(REPLACE "\n" "\n " actual_contents_formatted "${actual_contents}") + string(APPEND RunCMake_TEST_FAILED "Expected contents of ${configs_file}:\n ${contents_formatted}\nActual contents:\n ${actual_contents_formatted}\n") + endif() + endforeach() +endif() diff --git a/Tests/RunCMake/CMakePresetsPackage/Good-package-debug-stdout.txt b/Tests/RunCMake/CMakePresetsPackage/Good-package-debug-stdout.txt new file mode 100644 index 0000000..be885b4 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/Good-package-debug-stdout.txt @@ -0,0 +1,2 @@ +CPack: [^ +]* Enable Debug diff --git a/Tests/RunCMake/CMakePresetsPackage/Good-package-generators-check.cmake b/Tests/RunCMake/CMakePresetsPackage/Good-package-generators-check.cmake new file mode 100644 index 0000000..aaa75e4 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/Good-package-generators-check.cmake @@ -0,0 +1 @@ +check_cpack_packages("TBZ2;TXZ" "") diff --git a/Tests/RunCMake/CMakePresetsPackage/Good-package-no-environment-check.cmake b/Tests/RunCMake/CMakePresetsPackage/Good-package-no-environment-check.cmake new file mode 100644 index 0000000..205e7b7 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/Good-package-no-environment-check.cmake @@ -0,0 +1,7 @@ +check_cpack_packages("TGZ;TXZ" [[TEST_ENV not defined +TEST_ENV_REF=xx +TEST_ENV_OVERRIDE not defined +TEST_ENV_OVERRIDE_REF not defined +]]) + +include("${RunCMake_SOURCE_DIR}/check.cmake") diff --git a/Tests/RunCMake/CMakePresetsPackage/Good-package-package-directory-check.cmake b/Tests/RunCMake/CMakePresetsPackage/Good-package-package-directory-check.cmake new file mode 100644 index 0000000..8f4b771 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/Good-package-package-directory-check.cmake @@ -0,0 +1,6 @@ +include("${RunCMake_TEST_BINARY_DIR}/default/CPackConfig.cmake") + +set(filename "${RunCMake_TEST_BINARY_DIR}/default/package-directory/_CPack_Packages/${CPACK_TOPLEVEL_TAG}/TGZ/${CPACK_PACKAGE_FILE_NAME}.tar.gz") +if(NOT EXISTS "${filename}") + set(RunCMake_TEST_FAILED "Expected ${filename} to exist but it does not") +endif() diff --git a/Tests/RunCMake/CMakePresetsPackage/Good-package-package-name-check.cmake b/Tests/RunCMake/CMakePresetsPackage/Good-package-package-name-check.cmake new file mode 100644 index 0000000..fdc4824 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/Good-package-package-name-check.cmake @@ -0,0 +1,7 @@ +include("${RunCMake_TEST_BINARY_DIR}/default/CPackConfig.cmake") + +file(READ "${RunCMake_TEST_BINARY_DIR}/default/${CPACK_PACKAGE_FILE_NAME}.json" contents) +string(JSON package_name GET "${contents}" packageName) +if(NOT package_name STREQUAL "package-name") + set(RunCMake_TEST_FAILED "Expected package name to be \"package-name\" but it was \"${package_name}\"") +endif() diff --git a/Tests/RunCMake/CMakePresetsPackage/Good-package-package-version-check.cmake b/Tests/RunCMake/CMakePresetsPackage/Good-package-package-version-check.cmake new file mode 100644 index 0000000..dba9110 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/Good-package-package-version-check.cmake @@ -0,0 +1,7 @@ +include("${RunCMake_TEST_BINARY_DIR}/default/CPackConfig.cmake") + +file(READ "${RunCMake_TEST_BINARY_DIR}/default/${CPACK_PACKAGE_FILE_NAME}.json" contents) +string(JSON package_version GET "${contents}" packageVersion) +if(NOT package_version STREQUAL "1.0") + set(RunCMake_TEST_FAILED "Expected package version to be \"1.0\" but it was \"${package_version}\"") +endif() diff --git a/Tests/RunCMake/CMakePresetsPackage/Good-package-variables-check.cmake b/Tests/RunCMake/CMakePresetsPackage/Good-package-variables-check.cmake new file mode 100644 index 0000000..2858170 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/Good-package-variables-check.cmake @@ -0,0 +1,6 @@ +include("${RunCMake_TEST_BINARY_DIR}/default/CPackConfig.cmake") + +set(filename "${RunCMake_TEST_BINARY_DIR}/default/_CPack_Packages/${CPACK_TOPLEVEL_TAG}/TGZ/variables-package.tar.gz") +if(NOT EXISTS "${filename}") + set(RunCMake_TEST_FAILED "Expected ${filename} to exist but it does not") +endif() diff --git a/Tests/RunCMake/CMakePresetsPackage/Good-package-verbose-stdout.txt b/Tests/RunCMake/CMakePresetsPackage/Good-package-verbose-stdout.txt new file mode 100644 index 0000000..22fd115 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/Good-package-verbose-stdout.txt @@ -0,0 +1 @@ +CPack: Enable Verbose diff --git a/Tests/RunCMake/CMakePresetsPackage/Good-package-with-environment-check.cmake b/Tests/RunCMake/CMakePresetsPackage/Good-package-with-environment-check.cmake new file mode 100644 index 0000000..a775e4d --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/Good-package-with-environment-check.cmake @@ -0,0 +1,7 @@ +check_cpack_packages("TGZ;TXZ" [[TEST_ENV=Environment variable +TEST_ENV_REF=xEnvironment variablex +TEST_ENV_OVERRIDE=Override +TEST_ENV_OVERRIDE_REF=xOverridex +]]) + +include("${RunCMake_SOURCE_DIR}/check.cmake") diff --git a/Tests/RunCMake/CMakePresetsPackage/Good.cmake b/Tests/RunCMake/CMakePresetsPackage/Good.cmake new file mode 100644 index 0000000..d019443 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/Good.cmake @@ -0,0 +1,31 @@ +set(CPACK_PACKAGE_NAME Good) +set(CPACK_GENERATOR "TGZ;TXZ") + +include(CPack) + +install(CODE [[ +function(print_env name) + if(DEFINED ENV{${name}}) + file(APPEND $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/env.txt "${name}=$ENV{${name}}\n") + else() + file(APPEND $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/env.txt "${name} not defined\n") + endif() +endfunction() + +file(REMOVE $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/env.txt) +print_env(TEST_ENV) +print_env(TEST_ENV_REF) +print_env(TEST_ENV_OVERRIDE) +print_env(TEST_ENV_OVERRIDE_REF) + +file(APPEND $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/configs.txt "$\n") +]]) + +file(WRITE "${CMAKE_BINARY_DIR}/CPackConfigAlt.cmake" [[include(${CMAKE_CURRENT_LIST_DIR}/CPackConfig.cmake) +set(CPACK_PACKAGE_FILE_NAME "config-file-alt") +]]) + +file(WRITE "${CMAKE_BINARY_DIR}/external_package.cmake" [[if(NOT CPACK_PACKAGE_VENDOR STREQUAL "some-vendor") + message(FATAL_ERROR "Expected vendor to be \"some-vendor\" but it was \"${CPACK_PACKAGE_VENDOR}\"") +endif() +]]) diff --git a/Tests/RunCMake/CMakePresetsPackage/Good.json.in b/Tests/RunCMake/CMakePresetsPackage/Good.json.in new file mode 100644 index 0000000..0c0e7d9 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/Good.json.in @@ -0,0 +1,135 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "default", + "generator": "@RunCMake_GENERATOR@", + "binaryDir": "${sourceDir}/build/${presetName}", + "environment": { + "TEST_ENV": "Environment variable", + "TEST_ENV_OVERRIDE": "Overridden environment variable" + } + } + ], + "buildPresets": [ + { + "name": "build-default-debug", + "configurePreset": "default", + "configuration": "Debug" + }, + { + "name": "build-default-release", + "inherits": "build-default-debug", + "configuration": "Release" + } + ], + "packagePresets": [ + { + "name": "minimal", + "configurePreset": "default" + }, + { + "name": "defaults", + "hidden": false, + "inherits": [], + "vendor": {}, + "displayName": "", + "description": "", + "environment": {}, + "configurePreset": "default", + "inheritConfigureEnvironment": true + }, + { + "name": "no-environment", + "configurePreset": "default", + "inheritConfigureEnvironment": false, + "environment": { + "TEST_ENV_REF": "x$env{TEST_ENV}x" + } + }, + { + "name": "with-environment", + "inherits": "no-environment", + "inheritConfigureEnvironment": true, + "environment": { + "TEST_ENV_OVERRIDE": "Override", + "TEST_ENV_OVERRIDE_REF": "x$env{TEST_ENV_OVERRIDE}x", + "TEST_ENV_REF": "x$env{TEST_ENV}x" + } + }, + { + "name": "generators", + "inherits": "minimal", + "generators": [ + "TBZ2", + "TXZ" + ] + }, + { + "name": "configurations", + "inherits": "minimal", + "configurations": [ + "Debug", + "Release" + ] + }, + { + "name": "variables", + "inherits": "minimal", + "variables": { + "CPACK_PACKAGE_FILE_NAME": "variables-package" + } + }, + { + "name": "config-file", + "inherits": "minimal", + "configFile": "CPackConfigAlt.cmake" + }, + { + "name": "debug", + "inherits": "minimal", + "output": { + "debug": true + } + }, + { + "name": "verbose", + "inherits": "minimal", + "output": { + "verbose": true + } + }, + { + "name": "package-name", + "inherits": "minimal", + "generators": [ + "External" + ], + "packageName": "package-name" + }, + { + "name": "package-version", + "inherits": "minimal", + "generators": [ + "External" + ], + "packageVersion": "1.0" + }, + { + "name": "package-directory", + "inherits": "minimal", + "packageDirectory": "${sourceDir}/build/default/package-directory" + }, + { + "name": "vendor-name", + "inherits": "minimal", + "generators": [ + "External" + ], + "variables": { + "CPACK_EXTERNAL_PACKAGE_SCRIPT": "${sourceDir}/build/default/external_package.cmake" + }, + "vendorName": "some-vendor" + } + ] +} diff --git a/Tests/RunCMake/CMakePresetsPackage/RunCMakeTest.cmake b/Tests/RunCMake/CMakePresetsPackage/RunCMakeTest.cmake new file mode 100644 index 0000000..0d5def1 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/RunCMakeTest.cmake @@ -0,0 +1,101 @@ +include(RunCMake) + +# Presets do not support legacy VS generator name architecture suffix. +if(RunCMake_GENERATOR MATCHES "^(Visual Studio [0-9]+ [0-9]+) ") + set(RunCMake_GENERATOR "${CMAKE_MATCH_1}") +endif() + +function(run_cmake_package_presets name CMakePresetsPackage_CONFIGURE_PRESETS CMakePresetsPackage_BUILD_PRESETS CMakePresetsPackage_PACKAGE_PRESETS) + set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/${name}") + set(RunCMake_TEST_BINARY_DIR "${RunCMake_TEST_SOURCE_DIR}/build") + set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${RunCMake_TEST_SOURCE_DIR}") + + set(RunCMake_TEST_NO_CLEAN TRUE) + + file(REMOVE_RECURSE "${RunCMake_TEST_SOURCE_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + + set(CASE_NAME "${name}") + set(CASE_SOURCE_DIR "${RunCMake_SOURCE_DIR}") + configure_file("${RunCMake_SOURCE_DIR}/CMakeLists.txt.in" "${RunCMake_TEST_SOURCE_DIR}/CMakeLists.txt" @ONLY) + + if(NOT CMakePresetsPackage_FILE) + set(CMakePresetsPackage_FILE "${RunCMake_SOURCE_DIR}/${name}.json.in") + endif() + if(EXISTS "${CMakePresetsPackage_FILE}") + configure_file("${CMakePresetsPackage_FILE}" "${RunCMake_TEST_SOURCE_DIR}/CMakePresets.json" @ONLY) + endif() + + if(NOT CMakeUserPresets_FILE) + set(CMakeUserPresets_FILE "${RunCMake_SOURCE_DIR}/${name}User.json.in") + endif() + if(EXISTS "${CMakeUserPresets_FILE}") + configure_file("${CMakeUserPresets_FILE}" "${RunCMake_TEST_SOURCE_DIR}/CMakeUserPresets.json" @ONLY) + endif() + + foreach(ASSET ${CMakePresetsPackage_ASSETS}) + configure_file("${RunCMake_SOURCE_DIR}/${ASSET}" "${RunCMake_TEST_SOURCE_DIR}" COPYONLY) + endforeach() + + if (NOT CMakePresetsPackage_NO_CONFIGURE) + foreach(CONFIGURE_PRESET ${CMakePresetsPackage_CONFIGURE_PRESETS}) + run_cmake_command("${name}-configure-${CONFIGURE_PRESET}" + "${CMAKE_COMMAND}" "--preset" "${CONFIGURE_PRESET}") + endforeach() + endif() + + if (NOT CMakePresetsPackage_NO_BUILD) + foreach(BUILD_PRESET ${CMakePresetsPackage_BUILD_PRESETS}) + run_cmake_command("${name}-build-${BUILD_PRESET}" + "${CMAKE_COMMAND}" "--build" "--preset" "${BUILD_PRESET}") + endforeach() + endif() + + set(eq 0) + foreach(PACKAGE_PRESET ${CMakePresetsPackage_PACKAGE_PRESETS}) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}/default/_CPack_Packages") + + if (EXISTS "${RunCMake_SOURCE_DIR}/${name}-package-${PACKAGE_PRESET}-check.cmake") + set(RunCMake-check-file "${name}-package-${PACKAGE_PRESET}-check.cmake") + else() + set(RunCMake-check-file "check.cmake") + endif() + + if(eq) + run_cmake_command(${name}-package-${PACKAGE_PRESET} + ${CMAKE_CPACK_COMMAND} "--preset=${PACKAGE_PRESET}" ${ARGN}) + set(eq 0) + else() + run_cmake_command(${name}-package-${PACKAGE_PRESET} + ${CMAKE_CPACK_COMMAND} "--preset" "${PACKAGE_PRESET}" ${ARGN}) + set(eq 1) + endif() + endforeach() +endfunction() + +function(check_cpack_packages generators contents) + include("${RunCMake_TEST_BINARY_DIR}/default/CPackConfig.cmake") + + set(cpack_dir "${RunCMake_TEST_BINARY_DIR}/default/_CPack_Packages/${CPACK_TOPLEVEL_TAG}") + file(GLOB dirs RELATIVE "${cpack_dir}" "${cpack_dir}/*") + if(NOT dirs STREQUAL generators) + string(APPEND RunCMake_TEST_FAILED "Expected CPack generators: ${generators}\nActual CPack generators: ${dirs}\n") + endif() + + if(contents) + foreach(dir IN LISTS dirs) + set(env_file "${cpack_dir}/${dir}/${CPACK_PACKAGE_FILE_NAME}/env.txt") + file(READ "${env_file}" actual_contents) + if(NOT contents STREQUAL actual_contents) + string(REPLACE "\n" "\n " contents_formatted "${contents}") + string(REPLACE "\n" "\n " actual_contents_formatted "${actual_contents}") + string(APPEND RunCMake_TEST_FAILED "Expected contents of ${env_file}:\n ${contents_formatted}\nActual contents:\n ${actual_contents_formatted}\n") + endif() + endforeach() + endif() + + set(RunCMake_TEST_FAILED ${RunCMake_TEST_FAILED} PARENT_SCOPE) +endfunction() + +run_cmake_package_presets(UnsupportedVersion "x" "" "") +run_cmake_package_presets(Good "default" "build-default-debug" "no-environment;with-environment;generators;configurations;variables;config-file;debug;verbose;package-name;package-version;package-directory;vendor-name") diff --git a/Tests/RunCMake/CMakePresetsPackage/UnsupportedVersion-configure-x-result.txt b/Tests/RunCMake/CMakePresetsPackage/UnsupportedVersion-configure-x-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/UnsupportedVersion-configure-x-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CMakePresetsPackage/UnsupportedVersion-configure-x-stderr.txt b/Tests/RunCMake/CMakePresetsPackage/UnsupportedVersion-configure-x-stderr.txt new file mode 100644 index 0000000..325af70 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/UnsupportedVersion-configure-x-stderr.txt @@ -0,0 +1,2 @@ +^CMake Error: Could not read presets from [^ +]*/Tests/RunCMake/CMakePresetsPackage/UnsupportedVersion: File version must be 5 or higher for package preset support$ diff --git a/Tests/RunCMake/CMakePresetsPackage/UnsupportedVersion.json.in b/Tests/RunCMake/CMakePresetsPackage/UnsupportedVersion.json.in new file mode 100644 index 0000000..e5f7240 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/UnsupportedVersion.json.in @@ -0,0 +1,4 @@ +{ + "version": 5, + "packagePresets": [] +} diff --git a/Tests/RunCMake/CMakePresetsPackage/check.cmake b/Tests/RunCMake/CMakePresetsPackage/check.cmake new file mode 100644 index 0000000..e79c4f1 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsPackage/check.cmake @@ -0,0 +1,3 @@ +set(CMakePresets_VALIDATE_SCRIPT_PATH "${RunCMake_SOURCE_DIR}/../CMakePresets/validate_schema.py") +include("${RunCMake_SOURCE_DIR}/../CMakePresets/validate_schema.cmake") +include("${RunCMake_SOURCE_DIR}/../CMakePresets/check.cmake") -- cgit v0.12