@@ -4,4 +4,111 @@ TODO: Currently only a skeleton.
4
4
5
5
## Infrastructure
6
6
7
+ ### ` lockfile.json `
8
+
9
+ #### Why
10
+
11
+ Some users and environments that are not currently using a package manager.
12
+ While CMake supports these scenarios in several ways, this project prefers to
13
+ provide and document a simple solution for those user who, reasonably, aren't
14
+ familiar with mechanisms available to configure CMake to configure a
15
+ ` find_package(GTest) ` command into steps that provide a GoogleTest
16
+ library fully built from source.
17
+
18
+ As documented in this project's README, that workflow involves injecting
19
+ some custom CMake logic into the project by using the
20
+ ` CMAKE_PROJECT_TOP_LEVEL_INCLUDES ` CMake variable to inject a file called
21
+ ` use-fetch-content.cmake ` into the build of the project. Here is an example
22
+ command:
23
+
24
+ ``` shell
25
+ cmake -B build -S . -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=./cmake/use-fetch-content.cmake
26
+ ```
27
+
28
+ The precise version of GoogleTest that will be used is maintained in
29
+ ` ./lockfile.json ` . ` use-fetch-content.cmake ` locates that file and configures
30
+ the project from that data.
31
+
32
+ #### Maintenance
33
+
34
+ Typically, the only change needed to ` lockfile.json ` would be updating
35
+ the commit identifiers in ` git_tag ` fields as appropriate.
36
+
37
+ If, hypothetically, the project decided to add tests that use the
38
+ Catch2 test framework, a new dependency would need to be enumerated in
39
+ ` lockfile.json ` . A new dependency object would need to be added like so:
40
+
41
+ ``` json5
42
+ " dependencies" : [
43
+ // ... etc ...
44
+ {
45
+ " name" : " Catch2" ,
46
+ " package_name" : " Catch2" ,
47
+ " git_repository" : " https://github.com/catchorg/Catch2" ,
48
+ " git_tag" : " 914aeecfe23b1e16af6ea675a4fb5dbd5a5b8d0a" // v3.8.0
49
+ },
50
+ // ... etc ...
51
+ ]
52
+ ```
53
+
54
+ [ The upstream Catch2 documentation] [ catch2-docs ] declare that ` Catch2 `
55
+ is to be include with ` find_package ` like so:
56
+ ` find_package(Catch2) ` . That means the ` name ` field in the ` lockfile.json `
57
+ dependency object is ` Catch2 ` . That same document describes support for
58
+ ` FetchContent ` APIs like so: ` FetchContent_Declare(Catch2 ...) ` . That means
59
+ the ` name ` field in the ` lockfile.json ` dependency object is also ` Catch2 ` .
60
+
61
+ The ` git_repository ` field is the URL to the official Catch2 repository:
62
+ ` https://github.com/catchorg/Catch2 ` . The latest release of Catch2 is
63
+ ` v3.8.0 ` , which has the SHA ` 914aeecfe23b1e16af6ea675a4fb5dbd5a5b8d0a ` , so
64
+ we will pin that value in ` git_tag ` field.
65
+
66
+ #### Design
67
+
68
+ This is a design for defining dependency providers
69
+ [ discussed in CMake upstream documentation] [ dependency-providers ] . The
70
+ ` use-fetch-content.cmake ` file * also* leverages CMake support for parsing
71
+ JSON to get the details of projects to provide from ` lockfile.json ` . This:
72
+
73
+ * Ensures that calls to FetchContent APIs within this project are consistent
74
+ and meet Beman Standards
75
+
76
+ * Provides a proof-of-concept for a utility that could potentially be used
77
+ across all Beman libraries, reducing the complexity of each project.
78
+
79
+ * Avoids churn in CMake files simply because a version of a dependency
80
+ needs updated.
81
+
82
+ * Eliminates a significant requirement for any potential automation for
83
+ bumping the version of dependencies -- the need to parse and transform
84
+ files written in the CMake syntax.
85
+
86
+ #### JSON Structure
87
+
88
+ The ` lockfile.json ` file contains an object with one field named ` dependencies ` .
89
+
90
+ ` dependencies ` should have a value that is an array of objects.
91
+
92
+ Each dependency object should contain exactly four fields with string values:
93
+
94
+ * ` name ` is used as the FetchContent name for the project. See
95
+ [ the API docs for FetchContent] [ fetch-content ] for more on what a "FetchContent
96
+ name" is.
97
+
98
+ * ` package_name ` * must* match the upstream-documented "package name" that would
99
+ be provided to a ` find_package ` call. For GoogleTest, this is ` GTest ` , for instance.
100
+
101
+ * ` git_repository ` is a full https URL for the repository to clone.
102
+
103
+ * ` git_tag ` must be a valid git ref in that repository. This identifies precisely which
104
+ version of the dependency to build. While branch and tag names will work for this value,
105
+ the Beman Project prefers the stability provided by a full-length git commit ID, so
106
+ please use one of those in any changes submitted to ` lockfile.json ` .
107
+
7
108
### Lint
109
+
110
+ [ catch2-docs ] : https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md#cmake-targets
111
+
112
+ [ dependency-providers ] : https://cmake.org/cmake/help/latest/guide/using-dependencies/index.html#dependency-providers]
113
+
114
+ [ fetch-content ] : https://cmake.org/cmake/help/latest/module/FetchContent.html
0 commit comments