From 2f13fdef0a9471165751f628cb4b2ba7b83b1ae1 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 23 Feb 2021 08:45:12 -0500 Subject: cmake: Document '--preset ' form of the argument This form already works. Document it and add tests. Issue: #21855 --- Help/manual/cmake.1.rst | 2 +- Source/cmakemain.cxx | 2 +- Tests/RunCMake/CMakePresets/CMakePresets.json.in | 8 +++++++- Tests/RunCMake/CMakePresets/GoodSpaces-stdout.txt | 3 +++ Tests/RunCMake/CMakePresets/GoodSpacesEq-stdout.txt | 3 +++ Tests/RunCMake/CMakePresets/GoodSpacesEq.cmake | 0 Tests/RunCMake/CMakePresets/NoPresetArgumentEq-result.txt | 1 + Tests/RunCMake/CMakePresets/NoPresetArgumentEq-stderr.txt | 2 ++ Tests/RunCMake/CMakePresets/RunCMakeTest.cmake | 6 ++++-- 9 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 Tests/RunCMake/CMakePresets/GoodSpaces-stdout.txt create mode 100644 Tests/RunCMake/CMakePresets/GoodSpacesEq-stdout.txt create mode 100644 Tests/RunCMake/CMakePresets/GoodSpacesEq.cmake create mode 100644 Tests/RunCMake/CMakePresets/NoPresetArgumentEq-result.txt create mode 100644 Tests/RunCMake/CMakePresets/NoPresetArgumentEq-stderr.txt diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index b2bd1ed..1759b9d 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -377,7 +377,7 @@ Options about:tracing tab of Google Chrome or using a plugin for a tool like Trace Compass. -``--preset=`` +``--preset ``, ``--preset=`` Reads a :manual:`preset ` from ``/CMakePresets.json`` and ``/CMakeUserPresets.json``. The preset specifies the diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index cd3c955..4260ca2 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -64,7 +64,7 @@ const char* cmDocumentationUsageNote[][2] = { const char* cmDocumentationOptions[][2] = { CMAKE_STANDARD_OPTIONS_TABLE, - { "--preset=", "Specify a configure preset." }, + { "--preset ,--preset=", "Specify a configure preset." }, { "--list-presets", "List available presets." }, { "-E", "CMake command mode." }, { "-L[A][H]", "List non-advanced cached variables." }, diff --git a/Tests/RunCMake/CMakePresets/CMakePresets.json.in b/Tests/RunCMake/CMakePresets/CMakePresets.json.in index 54e4140..d4d1838 100644 --- a/Tests/RunCMake/CMakePresets/CMakePresets.json.in +++ b/Tests/RunCMake/CMakePresets/CMakePresets.json.in @@ -132,7 +132,13 @@ { "name": "Good Spaces", "generator": "@RunCMake_GENERATOR@", - "binaryDir": "${sourceDir}/build" + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "GOOD_SPACES": { + "type": "STRING", + "value": "1" + } + } }, { "name": "GoodWindowsBackslash", diff --git a/Tests/RunCMake/CMakePresets/GoodSpaces-stdout.txt b/Tests/RunCMake/CMakePresets/GoodSpaces-stdout.txt new file mode 100644 index 0000000..d106c45 --- /dev/null +++ b/Tests/RunCMake/CMakePresets/GoodSpaces-stdout.txt @@ -0,0 +1,3 @@ +Preset CMake variables: + + GOOD_SPACES:STRING="1" diff --git a/Tests/RunCMake/CMakePresets/GoodSpacesEq-stdout.txt b/Tests/RunCMake/CMakePresets/GoodSpacesEq-stdout.txt new file mode 100644 index 0000000..d106c45 --- /dev/null +++ b/Tests/RunCMake/CMakePresets/GoodSpacesEq-stdout.txt @@ -0,0 +1,3 @@ +Preset CMake variables: + + GOOD_SPACES:STRING="1" diff --git a/Tests/RunCMake/CMakePresets/GoodSpacesEq.cmake b/Tests/RunCMake/CMakePresets/GoodSpacesEq.cmake new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CMakePresets/NoPresetArgumentEq-result.txt b/Tests/RunCMake/CMakePresets/NoPresetArgumentEq-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CMakePresets/NoPresetArgumentEq-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CMakePresets/NoPresetArgumentEq-stderr.txt b/Tests/RunCMake/CMakePresets/NoPresetArgumentEq-stderr.txt new file mode 100644 index 0000000..a53682d --- /dev/null +++ b/Tests/RunCMake/CMakePresets/NoPresetArgumentEq-stderr.txt @@ -0,0 +1,2 @@ +^CMake Error: No preset specified for --preset +CMake Error: Run 'cmake --help' for all supported options.$ diff --git a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake index 25a7f2f..114abc5 100644 --- a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake @@ -143,7 +143,8 @@ run_cmake_presets(GoodBinaryUp) set(CMakePresets_SOURCE_ARG "../GoodBinaryRelative") run_cmake_presets(GoodBinaryRelative) unset(CMakePresets_SOURCE_ARG) -run_cmake_presets(GoodSpaces "--preset=Good Spaces") +run_cmake_presets(GoodSpaces "--preset" "Good Spaces") +run_cmake_presets(GoodSpacesEq "--preset=Good Spaces") if(WIN32) run_cmake_presets(GoodWindowsBackslash) endif() @@ -206,7 +207,8 @@ endif() # Test bad command line arguments run_cmake_presets(NoSuchPreset) -run_cmake_presets(NoPresetArgument --preset=) +run_cmake_presets(NoPresetArgument --preset) +run_cmake_presets(NoPresetArgumentEq --preset= -DA=B) run_cmake_presets(UseHiddenPreset) # Test CMakeUserPresets.json -- cgit v0.12 From 3357d377612fc238ff9da61666041764792034bb Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 23 Feb 2021 08:50:40 -0500 Subject: cmake: Add support for '--build --prefix=' form of the argument The main `cmake --preset` argument for configure presets supports both forms, so support it for `cmake --build --preset` too. Issue: #21855 --- Help/manual/cmake.1.rst | 2 +- Source/cmakemain.cxx | 3 ++- Tests/RunCMake/CMakePresetsBuild/RunCMakeTest.cmake | 12 ++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 1759b9d..157ea5f 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -416,7 +416,7 @@ following options: Project binary directory to be built. This is required (unless a preset is specified) and must be first. -``--preset `` +``--preset ``, ``--preset=`` Use a build preset to specify build options. The project binary directory is inferred from the ``configurePreset`` key. The current working directory must contain CMake preset files. diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 4260ca2..88ba011 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -511,6 +511,7 @@ int do_build(int ac, char const* const* av) bool hasPreset = false; for (int i = 2; i < ac; ++i) { if (strcmp(av[i], "--list-presets") == 0 || + cmHasLiteralPrefix(av[i], "--preset=") || strcmp(av[i], "--preset") == 0) { hasPreset = true; break; @@ -584,7 +585,7 @@ int do_build(int ac, char const* const* av) "Usage: cmake --build [ | --preset ] [options] [-- [native-options]]\n" "Options:\n" " = Project binary directory to be built.\n" - " --preset \n" + " --preset , --preset=\n" " = Specify a build preset.\n" " --list-presets\n" " = List available build presets.\n" diff --git a/Tests/RunCMake/CMakePresetsBuild/RunCMakeTest.cmake b/Tests/RunCMake/CMakePresetsBuild/RunCMakeTest.cmake index 9491524..fd95c2c 100644 --- a/Tests/RunCMake/CMakePresetsBuild/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMakePresetsBuild/RunCMakeTest.cmake @@ -40,6 +40,7 @@ function(run_cmake_build_presets name CMakePresetsBuild_CONFIGURE_PRESETS CMakeP endforeach() endif() + set(eq 0) foreach(BUILD_PRESET ${CMakePresetsBuild_BUILD_PRESETS}) if (EXISTS "${RunCMake_SOURCE_DIR}/${name}-build-${BUILD_PRESET}-check.cmake") set(RunCMake-check-file "${name}-build-${BUILD_PRESET}-check.cmake") @@ -47,8 +48,15 @@ function(run_cmake_build_presets name CMakePresetsBuild_CONFIGURE_PRESETS CMakeP set(RunCMake-check-file "check.cmake") endif() - run_cmake_command(${name}-build-${BUILD_PRESET} - ${CMAKE_COMMAND} "--build" "--preset" "${BUILD_PRESET}" ${ARGN}) + if(eq) + run_cmake_command(${name}-build-${BUILD_PRESET} + ${CMAKE_COMMAND} "--build" "--preset=${BUILD_PRESET}" ${ARGN}) + set(eq 0) + else() + run_cmake_command(${name}-build-${BUILD_PRESET} + ${CMAKE_COMMAND} "--build" "--preset" "${BUILD_PRESET}" ${ARGN}) + set(eq 1) + endif() endforeach() endfunction() -- cgit v0.12 From 6fa36470239a40ef81752ddea923d8618ad6eb7c Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 23 Feb 2021 09:12:55 -0500 Subject: ctest: Add support for '--prefix=' form of the argument The main `cmake --preset` argument for configure presets supports both forms, so support it for `ctest --preset` too. Fixes: #21855 --- Help/manual/ctest.1.rst | 2 +- Source/cmCTest.cxx | 10 ++++++++-- Source/ctest.cxx | 3 ++- Tests/RunCMake/CMakePresetsTest/RunCMakeTest.cmake | 12 ++++++++++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Help/manual/ctest.1.rst b/Help/manual/ctest.1.rst index 0a3614f..175359d 100644 --- a/Help/manual/ctest.1.rst +++ b/Help/manual/ctest.1.rst @@ -30,7 +30,7 @@ This program will run the tests and report results. Options ======= -``--preset `` +``--preset ``, ``--preset=`` Use a test preset to specify test options. The project binary directory is inferred from the ``configurePreset`` key. The current working directory must contain CMake preset files. diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index e8d7c05..620ba19 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -2574,7 +2574,10 @@ int cmCTest::Run(std::vector& args, std::string* output) bool listPresets = find(args.begin(), args.end(), "--list-presets") != args.end(); - auto it = find(args.begin(), args.end(), "--preset"); + auto it = + std::find_if(args.begin(), args.end(), [](std::string const& arg) -> bool { + return arg == "--preset" || cmHasLiteralPrefix(arg, "--preset="); + }); if (listPresets || it != args.end()) { std::string errormsg; bool success; @@ -2583,7 +2586,10 @@ int cmCTest::Run(std::vector& args, std::string* output) // If listing presets we don't need a presetName success = this->SetArgsFromPreset("", listPresets); } else { - if (++it != args.end()) { + if (cmHasLiteralPrefix(*it, "--preset=")) { + auto presetName = it->substr(9); + success = this->SetArgsFromPreset(presetName, listPresets); + } else if (++it != args.end()) { auto presetName = *it; success = this->SetArgsFromPreset(presetName, listPresets); } else { diff --git a/Source/ctest.cxx b/Source/ctest.cxx index 1404b0c..3c331d3 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -26,7 +26,8 @@ static const char* cmDocumentationUsage[][2] = { { nullptr, { nullptr, nullptr } }; static const char* cmDocumentationOptions[][2] = { - { "--preset ", "Read arguments from a test preset." }, + { "--preset , --preset=", + "Read arguments from a test preset." }, { "--list-presets", "List available test presets." }, { "-C , --build-config ", "Choose configuration to test." }, { "--progress", "Enable short progress output from tests." }, diff --git a/Tests/RunCMake/CMakePresetsTest/RunCMakeTest.cmake b/Tests/RunCMake/CMakePresetsTest/RunCMakeTest.cmake index 6360fc2..4ffdfab 100644 --- a/Tests/RunCMake/CMakePresetsTest/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMakePresetsTest/RunCMakeTest.cmake @@ -51,6 +51,7 @@ function(run_cmake_test_presets name CMakePresetsTest_CONFIGURE_PRESETS CMakePre endforeach() endif() + set(eq 0) foreach(TEST_PRESET ${CMakePresetsTest_TEST_PRESETS}) if (EXISTS "${RunCMake_SOURCE_DIR}/${name}-test-${TEST_PRESET}-check.cmake") set(RunCMake-check-file "${name}-test-${TEST_PRESET}-check.cmake") @@ -58,8 +59,15 @@ function(run_cmake_test_presets name CMakePresetsTest_CONFIGURE_PRESETS CMakePre set(RunCMake-check-file "check.cmake") endif() - run_cmake_command(${name}-test-${TEST_PRESET} - ${CMAKE_CTEST_COMMAND} "--preset" "${TEST_PRESET}" ${ARGN}) + if(eq) + run_cmake_command(${name}-test-${TEST_PRESET} + ${CMAKE_CTEST_COMMAND} "--preset=${TEST_PRESET}" ${ARGN}) + set(eq 0) + else() + run_cmake_command(${name}-test-${TEST_PRESET} + ${CMAKE_CTEST_COMMAND} "--preset" "${TEST_PRESET}" ${ARGN}) + set(eq 1) + endif() endforeach() endfunction() -- cgit v0.12