1
0
Эх сурвалжийг харах

Tests: Test the CMakePresets.json example in the documentation

Kyle Edwards 5 жил өмнө
parent
commit
94c955e508

+ 2 - 25
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:
 

+ 23 - 0
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"
+        }
+      }
+    }
+  ]
+}

+ 3 - 0
Tests/RunCMake/CMakePresets/DocumentationExample.cmake

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

+ 9 - 0
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)