mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-15 20:46:37 +08:00
CMakePresets.json: Add ${hostSystemName} macro
This commit is contained in:
@@ -830,6 +830,12 @@ Recognized macros include:
|
||||
test presets, this will evaluate to the generator specified by
|
||||
``configurePreset``.
|
||||
|
||||
``${hostSystemName}``
|
||||
|
||||
The name of the host operating system. Contains the same value as
|
||||
:variable:`CMAKE_HOST_SYSTEM_NAME`. This is allowed in preset files
|
||||
specifying version ``3`` or above.
|
||||
|
||||
``${dollar}``
|
||||
|
||||
A literal dollar sign (``$``).
|
||||
|
5
Help/release/dev/cmake-presets-host-system-name.rst
Normal file
5
Help/release/dev/cmake-presets-host-system-name.rst
Normal file
@@ -0,0 +1,5 @@
|
||||
cmake-presets-host-system-name
|
||||
------------------------------
|
||||
|
||||
* :manual:`cmake-presets(7)` gained support for a new ``${hostSystemName}``
|
||||
macro.
|
@@ -9,6 +9,7 @@
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
|
||||
#include <cm/string_view>
|
||||
#include <cmext/string_view>
|
||||
|
||||
#include <cm3p/json/reader.h>
|
||||
@@ -981,7 +982,7 @@ bool ExpandMacros(const cmCMakePresetsFile& file, const T& preset,
|
||||
MacroExpander defaultMacroExpander =
|
||||
[&file, &preset](const std::string& macroNamespace,
|
||||
const std::string& macroName, std::string& macroOut,
|
||||
int /*version*/) -> ExpandMacroResult {
|
||||
int version) -> ExpandMacroResult {
|
||||
if (macroNamespace.empty()) {
|
||||
if (macroName == "sourceDir") {
|
||||
macroOut += file.SourceDir;
|
||||
@@ -1010,6 +1011,13 @@ bool ExpandMacros(const cmCMakePresetsFile& file, const T& preset,
|
||||
macroOut += '$';
|
||||
return ExpandMacroResult::Ok;
|
||||
}
|
||||
if (macroName == "hostSystemName") {
|
||||
if (version < 3) {
|
||||
return ExpandMacroResult::Error;
|
||||
}
|
||||
macroOut += cmSystemTools::GetSystemName();
|
||||
return ExpandMacroResult::Ok;
|
||||
}
|
||||
}
|
||||
|
||||
return ExpandMacroResult::Ignore;
|
||||
|
3
Tests/RunCMake/CMakePresets/HostSystemName.cmake
Normal file
3
Tests/RunCMake/CMakePresets/HostSystemName.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/TestVariable.cmake)
|
||||
|
||||
test_variable(TEST_HOST_SYSTEM_NAME "" "${CMAKE_HOST_SYSTEM_NAME}")
|
13
Tests/RunCMake/CMakePresets/HostSystemName.json.in
Normal file
13
Tests/RunCMake/CMakePresets/HostSystemName.json.in
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": 3,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "HostSystemName",
|
||||
"generator": "@RunCMake_GENERATOR@",
|
||||
"binaryDir": "${sourceDir}/build",
|
||||
"cacheVariables": {
|
||||
"TEST_HOST_SYSTEM_NAME": "${hostSystemName}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1 @@
|
||||
1
|
@@ -0,0 +1,2 @@
|
||||
^CMake Error: Could not read presets from [^
|
||||
]*/Tests/RunCMake/CMakePresets/HostSystemNameFuture: Invalid macro expansion$
|
13
Tests/RunCMake/CMakePresets/HostSystemNameFuture.json.in
Normal file
13
Tests/RunCMake/CMakePresets/HostSystemNameFuture.json.in
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": 2,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "HostSystemNameFuture",
|
||||
"generator": "@RunCMake_GENERATOR@",
|
||||
"binaryDir": "${sourceDir}/build",
|
||||
"cacheVariables": {
|
||||
"TEST_HOST_SYSTEM_NAME": "${hostSystemName}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@@ -261,6 +261,12 @@ set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/Debug.json.in")
|
||||
run_cmake_presets(NoDebug)
|
||||
run_cmake_presets(Debug)
|
||||
|
||||
# Test ${hostSystemName} macro
|
||||
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/HostSystemName.json.in")
|
||||
run_cmake_presets(HostSystemName)
|
||||
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/HostSystemNameFuture.json.in")
|
||||
run_cmake_presets(HostSystemNameFuture)
|
||||
|
||||
# Test the example from the documentation
|
||||
file(READ "${RunCMake_SOURCE_DIR}/../../../Help/manual/presets/example.json" _example)
|
||||
string(REPLACE "\"generator\": \"Ninja\"" "\"generator\": \"@RunCMake_GENERATOR@\"" _example "${_example}")
|
||||
|
Reference in New Issue
Block a user