mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
committed by
Brad King
parent
a584d8ed75
commit
02dd870535
@@ -260,6 +260,18 @@ Recognized macros include:
|
||||
|
||||
This is a preset-specific macro.
|
||||
|
||||
``${configurePresetName}``
|
||||
.. presets-versionadded:: 13
|
||||
|
||||
Name of the configure preset associated with the preset being evaluated.
|
||||
For configure presets, this is equivalent to ``${presetName}``. For build,
|
||||
test, and package presets, this is the name specified by the
|
||||
``configurePreset`` field.
|
||||
|
||||
This macro is not available for workflow presets.
|
||||
|
||||
This is a preset-specific macro.
|
||||
|
||||
``${generator}``
|
||||
Generator specified in the preset's ``generator`` field. For build and
|
||||
test presets, this will evaluate to the generator specified by
|
||||
@@ -513,6 +525,10 @@ they were added and a summary of the new features and changes is given below.
|
||||
:preset:`configurePresets.warnings` and
|
||||
:preset:`configurePresets.errors`.
|
||||
|
||||
* Changes to `Macro Expansion`_
|
||||
|
||||
* The ``${configurePresetName}`` macro was added.
|
||||
|
||||
Schema
|
||||
======
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
presets-configure-preset-name
|
||||
-----------------------------
|
||||
|
||||
* :manual:`cmake-presets(7)` gained the ``${configurePresetName}`` macro to
|
||||
expand to the name of the configure preset associated with the preset being
|
||||
evaluated. It is available for configure, build, test, and package presets,
|
||||
but not for workflow presets.
|
||||
@@ -91,6 +91,36 @@ public:
|
||||
int version) const override;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
std::string const* GetConfigurePresetName(T const& /*preset*/)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline std::string const* GetConfigurePresetName(
|
||||
cmCMakePresetsGraph::ConfigurePreset const& preset)
|
||||
{
|
||||
return &preset.Name;
|
||||
}
|
||||
|
||||
inline std::string const* GetConfigurePresetName(
|
||||
cmCMakePresetsGraph::BuildPreset const& preset)
|
||||
{
|
||||
return &preset.ConfigurePreset;
|
||||
}
|
||||
|
||||
inline std::string const* GetConfigurePresetName(
|
||||
cmCMakePresetsGraph::TestPreset const& preset)
|
||||
{
|
||||
return &preset.ConfigurePreset;
|
||||
}
|
||||
|
||||
inline std::string const* GetConfigurePresetName(
|
||||
cmCMakePresetsGraph::PackagePreset const& preset)
|
||||
{
|
||||
return &preset.ConfigurePreset;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class PresetMacroExpander : public MacroExpander
|
||||
{
|
||||
@@ -113,6 +143,16 @@ public:
|
||||
macroOut += Preset.Name;
|
||||
return ExpandMacroResult::Ok;
|
||||
}
|
||||
if (macroName == "configurePresetName") {
|
||||
if (version < 13) {
|
||||
return ExpandMacroResult::Error;
|
||||
}
|
||||
if (auto const* configurePresetName = GetConfigurePresetName(Preset)) {
|
||||
macroOut += *configurePresetName;
|
||||
return ExpandMacroResult::Ok;
|
||||
}
|
||||
return ExpandMacroResult::Error;
|
||||
}
|
||||
if (macroName == "generator") {
|
||||
// Generator only makes sense if preset is not hidden.
|
||||
if (!Preset.Hidden) {
|
||||
|
||||
@@ -44,7 +44,7 @@ using cmCMakePresetsGraphInternal::ExpandMacros;
|
||||
using cmCMakePresetsGraphInternal::ExpandImmediateMacros;
|
||||
|
||||
constexpr int MIN_VERSION = 1;
|
||||
constexpr int MAX_VERSION = 12;
|
||||
constexpr int MAX_VERSION = 13;
|
||||
|
||||
struct CMakeVersion
|
||||
{
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
if(NOT "${TEST_PRESET_NAME}" STREQUAL "ConfigurePresetName")
|
||||
message(FATAL_ERROR
|
||||
"Expected preset name 'ConfigurePresetName', got '${TEST_PRESET_NAME}'")
|
||||
endif()
|
||||
|
||||
if(NOT "${TEST_CONFIGURE_PRESET_NAME}" STREQUAL "${TEST_PRESET_NAME}")
|
||||
message(FATAL_ERROR
|
||||
"Expected configure preset name '${TEST_PRESET_NAME}', got '${TEST_CONFIGURE_PRESET_NAME}'")
|
||||
endif()
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"version": 13,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "ConfigurePresetName",
|
||||
"generator": "@RunCMake_GENERATOR@",
|
||||
"binaryDir": "${sourceDir}/build",
|
||||
"cacheVariables": {
|
||||
"TEST_PRESET_NAME": "${presetName}",
|
||||
"TEST_CONFIGURE_PRESET_NAME": "${configurePresetName}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,3 @@
|
||||
^CMake Error: Could not read presets from [^
|
||||
]*/Tests/RunCMake/CMakePresets/ConfigurePresetNameFuture:
|
||||
Invalid macro expansion in "ConfigurePresetNameFuture"$
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": 12,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "ConfigurePresetNameFuture",
|
||||
"generator": "@RunCMake_GENERATOR@",
|
||||
"binaryDir": "${sourceDir}/build",
|
||||
"cacheVariables": {
|
||||
"TEST_CONFIGURE_PRESET_NAME": "${configurePresetName}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
^CMake Error: Could not read presets from [^
|
||||
]*/Tests/RunCMake/CMakePresets/HighVersion:
|
||||
CMakePresets\.json:2: Unrecognized "version" 1000: must be >=1 and <=12
|
||||
CMakePresets\.json:2: Unrecognized "version" 1000: must be >=1 and <=13
|
||||
"version": 1000,
|
||||
\^$
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
^CMake Error: Could not read presets from [^
|
||||
]*/Tests/RunCMake/CMakePresets/LowVersion:
|
||||
CMakePresets\.json:2: Unrecognized "version" 0: must be >=1 and <=12
|
||||
CMakePresets\.json:2: Unrecognized "version" 0: must be >=1 and <=13
|
||||
"version": 0,
|
||||
\^
|
||||
|
||||
@@ -500,6 +500,14 @@ run_cmake_presets(PathListSep)
|
||||
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/PathListSepFuture.json.in")
|
||||
run_cmake_presets(PathListSepFuture)
|
||||
|
||||
# Test ${configurePresetName} macro
|
||||
set(CMakePresets_FILE
|
||||
"${RunCMake_SOURCE_DIR}/ConfigurePresetName.json.in")
|
||||
run_cmake_presets(ConfigurePresetName)
|
||||
set(CMakePresets_FILE
|
||||
"${RunCMake_SOURCE_DIR}/ConfigurePresetNameFuture.json.in")
|
||||
run_cmake_presets(ConfigurePresetNameFuture)
|
||||
|
||||
# Test conditions
|
||||
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/Conditions.json.in")
|
||||
run_cmake_presets(ListConditions --list-presets)
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
include("${RunCMake_SOURCE_DIR}/TestVariable.cmake")
|
||||
|
||||
test_environment_variable("TEST_PRESET_NAME" "build-release")
|
||||
test_environment_variable("TEST_CONFIGURE_PRESET_NAME" "release")
|
||||
test_environment_variable("SOME_PATH"
|
||||
"[^\n]*[/\\\\]ConfigurePresetNameUseCase[/\\\\]build[/\\\\]release[/\\\\]generated")
|
||||
|
||||
include("${RunCMake_SOURCE_DIR}/check.cmake")
|
||||
@@ -0,0 +1,2 @@
|
||||
add_custom_target(show-path ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E environment)
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"version": 13,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "release",
|
||||
"generator": "@RunCMake_GENERATOR@",
|
||||
"binaryDir": "${sourceDir}/build/${configurePresetName}"
|
||||
}
|
||||
],
|
||||
"buildPresets": [
|
||||
{
|
||||
"name": "base",
|
||||
"hidden": true,
|
||||
"environment": {
|
||||
"TEST_PRESET_NAME": "${presetName}",
|
||||
"TEST_CONFIGURE_PRESET_NAME": "${configurePresetName}",
|
||||
"SOME_PATH": "${sourceDir}/build/${configurePresetName}/generated"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "build-release",
|
||||
"inherits": "base",
|
||||
"configurePreset": "release"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -77,6 +77,7 @@ else()
|
||||
endif()
|
||||
|
||||
run_cmake_build_presets(Good "default;other" "build-other;withEnvironment;noEnvironment;macros;vendorObject;singleTarget;initResolve" "")
|
||||
run_cmake_build_presets(ConfigurePresetNameUseCase "release" "build-release" "")
|
||||
run_cmake_build_presets(InvalidConfigurePreset "default" "badConfigurePreset" "")
|
||||
run_cmake_build_presets(Condition "default" "enabled;disabled" "")
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
set(CPACK_PACKAGE_NAME ConfigurePresetName)
|
||||
include(CPack)
|
||||
|
||||
file(WRITE "${CMAKE_BINARY_DIR}/check-preset-names.cmake" [[
|
||||
if(NOT "$ENV{TEST_PRESET_NAME}" STREQUAL "package")
|
||||
message(FATAL_ERROR
|
||||
"Expected preset name 'package', got '$ENV{TEST_PRESET_NAME}'")
|
||||
endif()
|
||||
if(NOT "$ENV{TEST_CONFIGURE_PRESET_NAME}" STREQUAL "configure")
|
||||
message(FATAL_ERROR
|
||||
"Expected configure preset name 'configure', got '$ENV{TEST_CONFIGURE_PRESET_NAME}'")
|
||||
endif()
|
||||
]])
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"version": 13,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "configure",
|
||||
"generator": "@RunCMake_GENERATOR@",
|
||||
"binaryDir": "${sourceDir}/build/configure"
|
||||
}
|
||||
],
|
||||
"packagePresets": [
|
||||
{
|
||||
"name": "base",
|
||||
"hidden": true,
|
||||
"generators": [
|
||||
"External"
|
||||
],
|
||||
"environment": {
|
||||
"TEST_PRESET_NAME": "${presetName}",
|
||||
"TEST_CONFIGURE_PRESET_NAME": "${configurePresetName}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "package",
|
||||
"inherits": "base",
|
||||
"configurePreset": "configure",
|
||||
"variables": {
|
||||
"CPACK_EXTERNAL_PACKAGE_SCRIPT": "${sourceDir}/build/configure/check-preset-names.cmake"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -105,6 +105,7 @@ 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")
|
||||
run_cmake_package_presets(ConfigurePresetName "configure" "" "package")
|
||||
run_cmake_package_presets(ListPresets "default" "" "x" "--list-presets")
|
||||
set(CMakePresetsPackage_FILE "${RunCMake_SOURCE_DIR}/ListPresets.json.in")
|
||||
run_cmake_package_presets(ListDefinedPresets "" "" "x" "--list-presets=defined")
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
include("${RunCMake_SOURCE_DIR}/../CMakePresetsBuild/TestVariable.cmake")
|
||||
|
||||
test_environment_variable("TEST_PRESET_NAME" "test")
|
||||
test_environment_variable("TEST_CONFIGURE_PRESET_NAME" "configure")
|
||||
|
||||
include("${RunCMake_SOURCE_DIR}/check.cmake")
|
||||
@@ -0,0 +1,2 @@
|
||||
enable_testing()
|
||||
add_test(NAME print-environment COMMAND ${CMAKE_COMMAND} -E environment)
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"version": 13,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "configure",
|
||||
"generator": "@RunCMake_GENERATOR@",
|
||||
"binaryDir": "${sourceDir}/build/configure"
|
||||
}
|
||||
],
|
||||
"testPresets": [
|
||||
{
|
||||
"name": "base",
|
||||
"hidden": true,
|
||||
"environment": {
|
||||
"TEST_PRESET_NAME": "${presetName}",
|
||||
"TEST_CONFIGURE_PRESET_NAME": "${configurePresetName}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "test",
|
||||
"inherits": "base",
|
||||
"configurePreset": "configure",
|
||||
"configuration": "Debug",
|
||||
"output": {
|
||||
"verbosity": "verbose"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -95,6 +95,8 @@ run_cmake_test_presets(Good
|
||||
"${GoodTestPresets}")
|
||||
unset(CMakePresetsTest_ASSETS)
|
||||
|
||||
run_cmake_test_presets(ConfigurePresetName "configure" "" "test")
|
||||
|
||||
run_cmake_test_presets(InvalidConfigurePreset "default" "" "badConfigurePreset")
|
||||
|
||||
set(CMakePresetsTest_NO_CONFIGURE 1)
|
||||
|
||||
Reference in New Issue
Block a user