Tests: Test the CMakePresets.json example in the documentation

This commit is contained in:
Kyle Edwards
2020-10-09 15:35:54 -04:00
parent d6af1e83bc
commit 94c955e508
4 changed files with 37 additions and 25 deletions

View File

@@ -174,31 +174,8 @@ source and build trees and generate a buildsystem:
The files are a JSON document with an object as the root:
.. code-block:: json
{
"version": 1,
"cmakeMinimumRequired": {
"major": 3,
"minor": 19,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "Default Config",
"description": "Default build using Ninja generator",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/default",
"cacheVariables": {
"MY_CACHE_VARIABLE": {
"type": "BOOL",
"value": "OFF"
}
}
}
]
}
.. literalinclude:: presets/example.json
:language: json
The root object recognizes the following fields:

View File

@@ -0,0 +1,23 @@
{
"version": 1,
"cmakeMinimumRequired": {
"major": 3,
"minor": 19,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "Default Config",
"description": "Default build using Ninja generator",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/default",
"cacheVariables": {
"MY_CACHE_VARIABLE": {
"type": "BOOL",
"value": "OFF"
}
}
}
]
}

View File

@@ -0,0 +1,3 @@
include(${CMAKE_CURRENT_LIST_DIR}/TestVariable.cmake)
test_variable(MY_CACHE_VARIABLE "BOOL" "OFF")

View File

@@ -1,3 +1,5 @@
cmake_minimum_required(VERSION 3.19) # CMP0053
include(RunCMake)
# Fix Visual Studio generator name
@@ -214,3 +216,10 @@ unset(CMakePresets_WARN_UNUSED_CLI)
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/Debug.json.in")
run_cmake_presets(NoDebug)
run_cmake_presets(Debug)
# 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}")
file(WRITE "${RunCMake_BINARY_DIR}/example.json.in" "${_example}")
set(CMakePresets_FILE "${RunCMake_BINARY_DIR}/example.json.in")
run_cmake_presets(DocumentationExample --preset=default)