From 94c955e508daa0ed84290cc1d3e946a74fde0e40 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Fri, 9 Oct 2020 15:35:54 -0400 Subject: Tests: Test the CMakePresets.json example in the documentation --- Help/manual/cmake.1.rst | 27 ++-------------------- Help/manual/presets/example.json | 23 ++++++++++++++++++ .../CMakePresets/DocumentationExample.cmake | 3 +++ Tests/RunCMake/CMakePresets/RunCMakeTest.cmake | 9 ++++++++ 4 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 Help/manual/presets/example.json create mode 100644 Tests/RunCMake/CMakePresets/DocumentationExample.cmake diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 0eadff4..b345db0 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -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: diff --git a/Help/manual/presets/example.json b/Help/manual/presets/example.json new file mode 100644 index 0000000..a299a06 --- /dev/null +++ b/Help/manual/presets/example.json @@ -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" + } + } + } + ] +} diff --git a/Tests/RunCMake/CMakePresets/DocumentationExample.cmake b/Tests/RunCMake/CMakePresets/DocumentationExample.cmake new file mode 100644 index 0000000..1f2fc00 --- /dev/null +++ b/Tests/RunCMake/CMakePresets/DocumentationExample.cmake @@ -0,0 +1,3 @@ +include(${CMAKE_CURRENT_LIST_DIR}/TestVariable.cmake) + +test_variable(MY_CACHE_VARIABLE "BOOL" "OFF") diff --git a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake index 4b430b3..18ea093 100644 --- a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake @@ -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) -- cgit v0.12