mirror of
https://github.com/Kitware/CMake.git
synced 2026-07-11 18:13:40 +00:00
preset: Easier command line interface for Workflow Presets
A positional option allows 'cmake --workflow --preset <preset>' to be shortened to 'cmake --workflow <preset>'. Fixes: #26270
This commit is contained in:
@@ -31,7 +31,7 @@ Synopsis
|
||||
cmake --find-package [<options>]
|
||||
|
||||
`Run a Workflow Preset`_
|
||||
cmake --workflow [<options>]
|
||||
cmake --workflow <options>
|
||||
|
||||
`View Help`_
|
||||
cmake --help[-<topic>]
|
||||
@@ -1394,7 +1394,7 @@ build steps in order:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
cmake --workflow [<options>]
|
||||
cmake --workflow <options>
|
||||
|
||||
The options are:
|
||||
|
||||
@@ -1411,6 +1411,15 @@ The options are:
|
||||
must contain CMake preset files.
|
||||
See :manual:`preset <cmake-presets(7)>` for more details.
|
||||
|
||||
.. versionchanged:: 3.31
|
||||
When following immediately after the ``--workflow`` option,
|
||||
the ``--preset`` argument can be omitted and just the ``<preset>``
|
||||
name can be given. This means the following syntax is valid:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ cmake --workflow my-preset
|
||||
|
||||
.. option:: --list-presets
|
||||
|
||||
Lists the available workflow presets. The current working directory must
|
||||
|
||||
6
Help/release/dev/cmake--workflow-preset.rst
Normal file
6
Help/release/dev/cmake--workflow-preset.rst
Normal file
@@ -0,0 +1,6 @@
|
||||
cmake--workflow-preset
|
||||
----------------------
|
||||
|
||||
* When executing a CMake workflow preset, the ``--preset`` option can now be
|
||||
omitted, allowing the simpler command line
|
||||
:option:`cmake --workflow \<preset\> <cmake--workflow --preset>`.
|
||||
@@ -1039,6 +1039,11 @@ int do_workflow(int ac, char const* const* av)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!matched && i == 0) {
|
||||
inputArgs.insert(inputArgs.begin(), "--preset");
|
||||
matched = true;
|
||||
parsed = arguments[0].parse("--preset", i, inputArgs);
|
||||
}
|
||||
if (!(matched && parsed)) {
|
||||
if (!matched) {
|
||||
presetName.clear();
|
||||
@@ -1052,7 +1057,7 @@ int do_workflow(int ac, char const* const* av)
|
||||
if (presetName.empty() && listPresets == WorkflowListPresets::No) {
|
||||
/* clang-format off */
|
||||
std::cerr <<
|
||||
"Usage: cmake --workflow [options]\n"
|
||||
"Usage: cmake --workflow <options>\n"
|
||||
"Options:\n"
|
||||
" --preset <preset> = Workflow preset to execute.\n"
|
||||
" --list-presets = List available workflow presets.\n"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
^Unknown argument -DINVALID_OPTION
|
||||
Usage: cmake --workflow \[options\]
|
||||
Usage: cmake --workflow <options>
|
||||
Options:
|
||||
--preset <preset> = Workflow preset to execute\.
|
||||
--list-presets = List available workflow presets\.
|
||||
|
||||
41
Tests/RunCMake/CMakePresetsWorkflow/MultiplePresets.json.in
Normal file
41
Tests/RunCMake/CMakePresetsWorkflow/MultiplePresets.json.in
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"version": 6,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "SinglePresetArg",
|
||||
"generator": "@RunCMake_GENERATOR@",
|
||||
"cacheVariables":
|
||||
{
|
||||
"WORKFLOW_PRESET": "SinglePresetArg"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "RepeatedPresetArg",
|
||||
"generator": "@RunCMake_GENERATOR@",
|
||||
"cacheVariables":
|
||||
{
|
||||
"WORKFLOW_PRESET": "RepeatedPresetArg"
|
||||
}
|
||||
}
|
||||
],
|
||||
"workflowPresets": [
|
||||
{
|
||||
"name": "SinglePresetArg",
|
||||
"steps": [
|
||||
{
|
||||
"type": "configure",
|
||||
"name": "SinglePresetArg"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "RepeatedPresetArg",
|
||||
"steps": [
|
||||
{
|
||||
"type": "configure",
|
||||
"name": "RepeatedPresetArg"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
if(WORKFLOW_PRESET STREQUAL "RepeatedPresetArg")
|
||||
message(FATAL_ERROR "First preset argument used instead of repeated preset argument")
|
||||
endif()
|
||||
@@ -45,7 +45,9 @@ function(run_cmake_workflow_presets name)
|
||||
set(RunCMake-check-file "check.cmake")
|
||||
endif()
|
||||
|
||||
if(eq)
|
||||
if(CMakePresets_DIRECT_ARG)
|
||||
set(preset_arg "${name}")
|
||||
elseif(eq)
|
||||
set(eq 0 PARENT_SCOPE)
|
||||
set(preset_arg "--preset=${name}")
|
||||
else()
|
||||
@@ -87,3 +89,10 @@ file(MAKE_DIRECTORY "${RunCMake_BINARY_DIR}/Fresh/build")
|
||||
file(WRITE "${RunCMake_BINARY_DIR}/Fresh/build/CMakeCache.txt" "FRESH_CONFIGURE:BOOL=OFF\n")
|
||||
run_cmake_workflow_presets(Fresh --fresh)
|
||||
unset(RunCMake_TEST_NO_CLEAN)
|
||||
|
||||
set(CMakePresets_DIRECT_ARG TRUE)
|
||||
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/MultiplePresets.json.in")
|
||||
run_cmake_workflow_presets(SinglePresetArg)
|
||||
run_cmake_workflow_presets(RepeatedPresetArg --preset SinglePresetArg)
|
||||
unset(CMakePresets_FILE)
|
||||
unset(CMakePresets_DIRECT_ARG)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
if(NOT WORKFLOW_PRESET STREQUAL "SinglePresetArg")
|
||||
message(FATAL_ERROR "Expected 'SinglePresetArg' workflow preset, but actual value is ${WORKFLOW_PRESET}")
|
||||
endif()
|
||||
Reference in New Issue
Block a user