Skip to content

Commit ad9e2a7

Browse files
committed
Work on README.md
1 parent a86d338 commit ad9e2a7

File tree

1 file changed

+112
-4
lines changed

1 file changed

+112
-4
lines changed

README.md

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The cmake-init template assumes you want to setup a project using
4040
* [Maintainer Modules](#maintainer-modules)
4141
* [cmake-init Template Check](#cmake-init-template-check)
4242
* [Development Modules](#development-modules)
43+
* [Version Control System Integration](#version-control-system-integration)
4344
* [Build Targets](#build-targets)
4445
* [Documentation](#documentation)
4546
* [Tests](#tests)
@@ -72,18 +73,18 @@ Alternatively, you can update the required modules selectively.
7273

7374
In order to be usable in a deterministic, idiomatic fashion, cmake-init avoids the following approaches and features:
7475

75-
### Super-Build
76+
## Super-Build
7677

7778
Due to the current semantics of targets and CMake internals, combining multiple
7879
cmake-init projects into one super-build project is not officially supported.
7980
There are limited and restricting workarounds.
8081
Actual solution: treat each project separately and use explicit dependency management.
8182

82-
### High Abstraction
83+
## High Abstraction
8384

8485
We use low abstractions to not build a language upon CMake a user has to learn.
8586

86-
### File Glob
87+
## File Glob
8788

8889
Explicit source specification prevents erroneous cases when adding and removing
8990
sources from the project tree.
@@ -124,8 +125,19 @@ include(GenerateExportHeader)
124125
include(WriteCompilerDetectionHeader)
125126
```
126127
128+
129+
### CMake Backward Compatibility
130+
127131
As some modules as `WriteCompilerDetectionHeader` may not be available, cmake-init suggests to use fallbacks and availability detection.
128132
133+
Using this example, the module include
134+
135+
```cmake
136+
include(WriteCompilerDetectionHeader)
137+
```
138+
139+
is replaced by
140+
129141
```cmake
130142
set(WriterCompilerDetectionHeaderFound NOTFOUND)
131143
# This module is only available with CMake >=3.1, so check whether it could be found
@@ -135,12 +147,97 @@ if (${CMAKE_VERSION} VERSION_GREATER "3.2")
135147
endif()
136148
```
137149

138-
### CMake Backward Compatibility
150+
and the result can be later used with
151+
152+
```cmake
153+
if (WriterCompilerDetectionHeaderFound)
154+
# ...
155+
endif ()
156+
```
157+
158+
Another issue with older CMake versions is the unavailability of then-unpublished language standards (e.g., C++11 and CMake 3.0). For those versions, the compile options has to be extended manually.
159+
160+
For new projects, we suggest to require at least CMake 3.2 and to therefore adjust the minimum required version:
161+
162+
```cmake
163+
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
164+
```
165+
139166

140167
### Project Meta Information
141168

169+
The declaration of project-wide information--that are used, e.g., within documentation, testing, and deployment--, is combined within the project meta information section in the main `CMakeLists.txt`.
170+
171+
```cmake
172+
#
173+
# Project description and (meta) information
174+
#
175+
176+
# Meta information about the project
177+
set(META_PROJECT_NAME "template")
178+
set(META_PROJECT_DESCRIPTION "CMake Project Template")
179+
set(META_AUTHOR_ORGANIZATION "CG Internals GmbH")
180+
set(META_AUTHOR_DOMAIN "https://github.com/cginternals/cmake-init/")
181+
set(META_AUTHOR_MAINTAINER "[email protected]")
182+
set(META_VERSION_MAJOR "2")
183+
set(META_VERSION_MINOR "0")
184+
set(META_VERSION_PATCH "0")
185+
set(META_VERSION_REVISION "<REVISION>")
186+
set(META_VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}")
187+
set(META_NAME_VERSION "${META_PROJECT_NAME} v${META_VERSION} (${META_VERSION_REVISION})")
188+
set(META_CMAKE_INIT_SHA "<CMAKE_INIT_REVISION>")
189+
190+
string(MAKE_C_IDENTIFIER ${META_PROJECT_NAME} META_PROJECT_ID)
191+
string(TOUPPER ${META_PROJECT_ID} META_PROJECT_ID)
192+
```
193+
194+
*cmake-init* supports the projects name, description, organization, domain, and maintainer email as well as detailed version information. For the version, we suggest to use [semantic versioning](https://semver.org/).
195+
Depending on your version control system, you may want to integrate the current revision of the software as well: see [Version Control System Integration](#version-control-system-integration). If you use the [cmake-init Template Check](#cmake-init-template-check) module, the cmake-init SHA is declared within this section, too.
196+
197+
Last, *cmake-init* derives a project ID that complies with the naming schemes of C to be used within auto-generated and derived source code content (e.g., macro identifiers).
198+
199+
142200
### Project Meta Information Code Generation
143201

202+
The result of this module is the generation of a C header file that propagates the project meta information to your C and C++ projects.
203+
For this, the CMake file configuration feature is used on the `version.h.in` header template.
204+
205+
```c
206+
#define ${META_PROJECT_ID}_PROJECT_NAME "@META_PROJECT_NAME@"
207+
#define ${META_PROJECT_ID}_PROJECT_DESCRIPTION "@META_PROJECT_DESCRIPTION@"
208+
209+
#define ${META_PROJECT_ID}_AUTHOR_ORGANIZATION "@META_AUTHOR_ORGANIZATION@"
210+
#define ${META_PROJECT_ID}_AUTHOR_DOMAIN "@META_AUTHOR_DOMAIN@"
211+
#define ${META_PROJECT_ID}_AUTHOR_MAINTAINER "@META_AUTHOR_MAINTAINER@"
212+
213+
#define ${META_PROJECT_ID}_VERSION_MAJOR "@META_VERSION_MAJOR@"
214+
#define ${META_PROJECT_ID}_VERSION_MINOR "@META_VERSION_MINOR@"
215+
#define ${META_PROJECT_ID}_VERSION_PATCH "@META_VERSION_PATCH@"
216+
#define ${META_PROJECT_ID}_VERSION_REVISION "@META_VERSION_REVISION@"
217+
218+
#define ${META_PROJECT_ID}_VERSION "@META_VERSION@"
219+
#define ${META_PROJECT_ID}_NAME_VERSION "@META_NAME_VERSION@"
220+
```
221+
222+
The template file is configured with the project meta information and the result is stored within the build directory. Beware that this header is stored in a path derived from your project name. You should adopt this as required.
223+
224+
```cmake
225+
# Generate version-header
226+
configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/${META_PROJECT_NAME}/${META_PROJECT_NAME}-version.h)
227+
```
228+
229+
We suggest to deploy this header disregarding its internal or even public use.
230+
231+
```cmake
232+
#
233+
# Deployment
234+
#
235+
236+
# Deploy generated headers
237+
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/${META_PROJECT_NAME} DESTINATION include COMPONENT dev)
238+
```
239+
240+
144241
### Project Build Options
145242

146243
## Maintainer Modules
@@ -172,6 +269,17 @@ Correctly configures, this module adds a cmake build target named `check-templat
172269

173270
## Development Modules
174271

272+
### Version Control System Integration
273+
274+
```cmake
275+
# Get git revision
276+
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
277+
string(SUBSTRING "${GIT_SHA1}" 0 12 GIT_REV)
278+
if(NOT GIT_SHA1)
279+
set(GIT_REV "0")
280+
endif()
281+
```
282+
175283
### Build Targets
176284

177285
### Documentation

0 commit comments

Comments
 (0)