mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-09 15:20:56 -06:00
Tests: Test the CMakePresets.json example in the documentation
This commit is contained in:
@@ -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:
|
||||
|
||||
|
||||
23
Help/manual/presets/example.json
Normal file
23
Help/manual/presets/example.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
3
Tests/RunCMake/CMakePresets/DocumentationExample.cmake
Normal file
3
Tests/RunCMake/CMakePresets/DocumentationExample.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/TestVariable.cmake)
|
||||
|
||||
test_variable(MY_CACHE_VARIABLE "BOOL" "OFF")
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user