diff options
author | Craig Scott <craig.scott@crascit.com> | 2020-10-23 10:35:51 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-10-23 10:36:03 (GMT) |
commit | 761dc324e043a504f6cec26b03bd86eb59c48710 (patch) | |
tree | 7412e73ffa82a88e7beb9cc01fe7a638a5363444 | |
parent | 609122007dc074739b394d2f70f674bbccca6073 (diff) | |
parent | 25742c589c80724b1d03357e0c911c443ab991f4 (diff) | |
download | CMake-761dc324e043a504f6cec26b03bd86eb59c48710.zip CMake-761dc324e043a504f6cec26b03bd86eb59c48710.tar.gz CMake-761dc324e043a504f6cec26b03bd86eb59c48710.tar.bz2 |
Merge topic 'cmake-presets-source-dir-name' into release-3.19
25742c589c CMakePresets.json: Add ${sourceDirName} macro
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: Craig Scott <craig.scott@crascit.com>
Merge-request: !5386
-rw-r--r-- | Help/manual/cmake-presets.7.rst | 5 | ||||
-rw-r--r-- | Source/cmCMakePresetsFile.cxx | 4 | ||||
-rw-r--r-- | Tests/RunCMake/CMakePresets/CMakePresets.json.in | 1 | ||||
-rw-r--r-- | Tests/RunCMake/CMakePresets/Good-stdout.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/CMakePresets/Good.cmake | 1 |
5 files changed, 12 insertions, 0 deletions
diff --git a/Help/manual/cmake-presets.7.rst b/Help/manual/cmake-presets.7.rst index 7040ad5..68e6cb9 100644 --- a/Help/manual/cmake-presets.7.rst +++ b/Help/manual/cmake-presets.7.rst @@ -308,6 +308,11 @@ Format Path to the project source directory's parent directory. + ``${sourceDirName}`` + + The last filename component of ``${sourceDir}``. For example, if + ``${sourceDir}`` is ``/path/to/source``, this would be ``source``. + ``${presetName}`` Name specified in the preset's ``name`` field. diff --git a/Source/cmCMakePresetsFile.cxx b/Source/cmCMakePresetsFile.cxx index b3bb6df..69bae7f 100644 --- a/Source/cmCMakePresetsFile.cxx +++ b/Source/cmCMakePresetsFile.cxx @@ -638,6 +638,10 @@ ExpandMacroResult ExpandMacro(const cmCMakePresetsFile& file, out += cmSystemTools::GetParentDirectory(file.SourceDir); return ExpandMacroResult::Ok; } + if (macroName == "sourceDirName") { + out += cmSystemTools::GetFilenameName(file.SourceDir); + return ExpandMacroResult::Ok; + } if (macroName == "presetName") { out += preset.Name; return ExpandMacroResult::Ok; diff --git a/Tests/RunCMake/CMakePresets/CMakePresets.json.in b/Tests/RunCMake/CMakePresets/CMakePresets.json.in index ea7df45..3ad667c 100644 --- a/Tests/RunCMake/CMakePresets/CMakePresets.json.in +++ b/Tests/RunCMake/CMakePresets/CMakePresets.json.in @@ -72,6 +72,7 @@ "TEST_DOLLAR": { "value": "${dollar}" }, + "TEST_SOURCE_DIR_NAME": "${sourceDirName}", "TEST_ENV_REF": "$env{TEST_ENV_REF}", "TEST_ENV": "$env{TEST_ENV}", "TEST_D_ENV_REF": "$env{TEST_D_ENV_REF}", diff --git a/Tests/RunCMake/CMakePresets/Good-stdout.txt b/Tests/RunCMake/CMakePresets/Good-stdout.txt index 7adf1ca..75003c7 100644 --- a/Tests/RunCMake/CMakePresets/Good-stdout.txt +++ b/Tests/RunCMake/CMakePresets/Good-stdout.txt @@ -26,6 +26,7 @@ Preset CMake variables: TEST_PRESET_NAME:STRING="xGoodx" TEST_SOURCE_DIR:PATH="[^ ]*/Tests/RunCMake/CMakePresets/Good" + TEST_SOURCE_DIR_NAME="Good" TEST_SOURCE_LIST:FILEPATH="[^ ]*/Tests/RunCMake/CMakePresets/Good/CMakeLists\.txt" TEST_SOURCE_PARENT_DIR:PATH="[^ diff --git a/Tests/RunCMake/CMakePresets/Good.cmake b/Tests/RunCMake/CMakePresets/Good.cmake index 55b85da..73a618d 100644 --- a/Tests/RunCMake/CMakePresets/Good.cmake +++ b/Tests/RunCMake/CMakePresets/Good.cmake @@ -17,6 +17,7 @@ test_variable(TEST_UNTYPED_BOOL_FALSE "UNINITIALIZED" "FALSE") test_variable(TEST_PRESET_NAME "STRING" "xGoodx") test_variable(TEST_GENERATOR "UNINITIALIZED" "x${CMAKE_GENERATOR}x") test_variable(TEST_DOLLAR "UNINITIALIZED" "$") +test_variable(TEST_SOURCE_DIR_NAME "UNINITIALIZED" "Good") test_variable(TEST_ENV_REF "UNINITIALIZED" "Environment variable") test_variable(TEST_ENV "UNINITIALIZED" "Environment variable") test_variable(TEST_D_ENV_REF "UNINITIALIZED" "xEnvironment variablex") |