mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 05:11:15 -06:00
@@ -1053,6 +1053,11 @@ Recognized macros include:
|
||||
:variable:`CMAKE_HOST_SYSTEM_NAME`. This is allowed in preset files
|
||||
specifying version ``3`` or above.
|
||||
|
||||
``${fileDir}``
|
||||
|
||||
Path to the directory containing the preset file which contains the macro.
|
||||
This is allowed in preset files specifying version ``4`` or above.
|
||||
|
||||
``${dollar}``
|
||||
|
||||
A literal dollar sign (``$``).
|
||||
|
||||
@@ -18,6 +18,9 @@ Presets
|
||||
* :manual:`cmake-presets(7)` files now have an optional ``include`` field,
|
||||
which allows the files to include other files.
|
||||
|
||||
* :manual:`cmake-presets(7)` files now support a ``${fileDir}`` macro, which
|
||||
contains the directory containing the preset file.
|
||||
|
||||
* :manual:`cmake-presets(7)` gained support for specifying the
|
||||
``resolvePackageReferences`` command line option in a build preset to control
|
||||
restoration behavior of package references from external package managers.
|
||||
|
||||
@@ -353,6 +353,14 @@ bool ExpandMacros(const cmCMakePresetsGraph& graph, const T& preset,
|
||||
macroOut += cmSystemTools::GetSystemName();
|
||||
return ExpandMacroResult::Ok;
|
||||
}
|
||||
if (macroName == "fileDir") {
|
||||
if (version < 4) {
|
||||
return ExpandMacroResult::Error;
|
||||
}
|
||||
macroOut +=
|
||||
cmSystemTools::GetParentDirectory(preset.OriginFile->Filename);
|
||||
return ExpandMacroResult::Ok;
|
||||
}
|
||||
}
|
||||
|
||||
return ExpandMacroResult::Ignore;
|
||||
|
||||
3
Tests/RunCMake/CMakePresets/FileDir.cmake
Normal file
3
Tests/RunCMake/CMakePresets/FileDir.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/TestVariable.cmake)
|
||||
|
||||
test_variable(TEST_FILE_DIR "" "${CMAKE_CURRENT_SOURCE_DIR}/subdir")
|
||||
6
Tests/RunCMake/CMakePresets/FileDir.json.in
Normal file
6
Tests/RunCMake/CMakePresets/FileDir.json.in
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"version": 4,
|
||||
"include": [
|
||||
"subdir/FileDir.json"
|
||||
]
|
||||
}
|
||||
1
Tests/RunCMake/CMakePresets/FileDirFuture-result.txt
Normal file
1
Tests/RunCMake/CMakePresets/FileDirFuture-result.txt
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
2
Tests/RunCMake/CMakePresets/FileDirFuture-stderr.txt
Normal file
2
Tests/RunCMake/CMakePresets/FileDirFuture-stderr.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
^CMake Error: Could not read presets from [^
|
||||
]*/Tests/RunCMake/CMakePresets/FileDirFuture: Invalid macro expansion$
|
||||
13
Tests/RunCMake/CMakePresets/FileDirFuture.json.in
Normal file
13
Tests/RunCMake/CMakePresets/FileDirFuture.json.in
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": 3,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "FileDirFuture",
|
||||
"generator": "@RunCMake_GENERATOR@",
|
||||
"binaryDir": "${sourceDir}/build",
|
||||
"cacheVariables": {
|
||||
"TEST_FILE_DIR": "${fileDir}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -53,7 +53,7 @@ function(run_cmake_presets name)
|
||||
)
|
||||
string(REGEX REPLACE "\\.in$" "" _extra_file_out_relative "${_extra_file_relative}")
|
||||
set(_extra_file_out "${RunCMake_TEST_SOURCE_DIR}/${_extra_file_out_relative}")
|
||||
configure_file("${_extra_file}" "${_extra_file_out}")
|
||||
configure_file("${_extra_file}" "${_extra_file_out}" @ONLY)
|
||||
list(APPEND _CMakePresets_EXTRA_FILES_OUT "${_extra_file_out}")
|
||||
list(APPEND _CMakePresets_EXTRA_FILES_SCHEMA_EXPECTED_RESULTS 0)
|
||||
endforeach()
|
||||
@@ -317,6 +317,16 @@ run_cmake_presets(HostSystemName)
|
||||
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/HostSystemNameFuture.json.in")
|
||||
run_cmake_presets(HostSystemNameFuture)
|
||||
|
||||
# Test ${fileDir} macro
|
||||
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/FileDir.json.in")
|
||||
set(CMakePresets_EXTRA_FILES
|
||||
"${RunCMake_SOURCE_DIR}/subdir/FileDir.json.in"
|
||||
)
|
||||
run_cmake_presets(FileDir)
|
||||
unset(CMakePresets_EXTRA_FILES)
|
||||
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/FileDirFuture.json.in")
|
||||
run_cmake_presets(FileDirFuture)
|
||||
|
||||
# Test conditions
|
||||
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/Conditions.json.in")
|
||||
run_cmake_presets(ListConditions --list-presets)
|
||||
|
||||
13
Tests/RunCMake/CMakePresets/subdir/FileDir.json.in
Normal file
13
Tests/RunCMake/CMakePresets/subdir/FileDir.json.in
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": 4,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "FileDir",
|
||||
"generator": "@RunCMake_GENERATOR@",
|
||||
"binaryDir": "${sourceDir}/build",
|
||||
"cacheVariables": {
|
||||
"TEST_FILE_DIR": "${fileDir}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user