Skip to content

Commit f2275c2

Browse files
committed
update README.md
1 parent a2588c5 commit f2275c2

File tree

4 files changed

+78
-17
lines changed

4 files changed

+78
-17
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ include(cmake/CPM.cmake)
3232
CPMAddPackage(
3333
NAME PackageProject.cmake
3434
GITHUB_REPOSITORY TheLartians/PackageProject.cmake
35-
VERSION 1.5.0
35+
VERSION 1.5.1
3636
)
3737

38-
set(COMPONENT_TARGETS_ENABLED NO)
38+
option(COMPONENT_TARGETS_ENABLED "Install multiple cmake config target files" NO)
3939
set(PROJECT_NAMESPACE ${PROJECT_NAME})
4040
set(NAMESPACE_HEADER_LOCATION ${CMAKE_CURRENT_LIST_DIR}/include)
4141
string(TOLOWER ${PROJECT_NAMESPACE} PROJECT_HEADER_LOCATION)
@@ -115,5 +115,5 @@ export(
115115
# install cmake project config files
116116
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/MathFunctionsConfig.cmake
117117
${CMAKE_CURRENT_BINARY_DIR}/MathFunctionsConfigVersion.cmake
118-
DESTINATION lib/cmake/MathFunctions
118+
DESTINATION lib/cmake/${PROJECT_NAMESPACE}
119119
)

README.md

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ with tests, executables and continuous integration. This template is the
1010
result of learnings from many previous projects and should help reduce
1111
the work required to setup up a modern C++ project.
1212

13+
This repository is intended as a template to show the "proper" way to
14+
setup a "Modern CMake" project with `components`. The required usage (for a
15+
downstream library) should be nothing more than:
16+
17+
```cmake
18+
find_package(
19+
MathFunctions 1
20+
COMPONENTS Addition SquareRoot
21+
REQUIRED
22+
)
23+
24+
/#..
25+
26+
target_link_libraries(
27+
MathFunctionsTests Boost::ut MathFunctions::Addition MathFunctions::SquareRoot
28+
)
29+
```
30+
1331
## Features
1432

1533
- [Modern CMake practices](https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/)
@@ -27,6 +45,9 @@ the work required to setup up a modern C++ project.
2745
- Automatic [documentation](https://thelartians.github.io/ModernCppStarter) and deployment with [Doxygen](https://www.doxygen.nl) and [GitHub Pages](https://pages.github.com)
2846
- Support for [sanitizer tools, and more](#additional-tools)
2947

48+
### Tip: Use [Gitflow Workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow)
49+
50+
3051
## Usage
3152

3253
### Adjust the template to your needs
@@ -39,22 +60,32 @@ the work required to setup up a modern C++ project.
3960

4061
Eventually, you can remove any unused files, such as the standalone
4162
directory or irrelevant github workflows for your project. Feel free to
42-
replace the License with one suited for your project.
63+
replace the [License](License) with one suited for your project.
4364

4465
To cleanly separate the library and subproject code, the outer
4566
`CMakeList.txt` only defines the library itself while the tests and other
4667
subprojects are self-contained in their own directories. During
4768
development it is usually convenient to [build all subprojects at
4869
once](#build-everything-at-once).
4970

71+
72+
### Use the makefile wrapper on unix bash or with GVIM
73+
74+
There is a [makefile](GNUmakefile) to wrap the
75+
[CMake](https://cmake.org/cmake/help/latest/manual/cmake.1.html)
76+
command-line interface for esay use at bash shell.
77+
78+
5079
### Build and run the standalone target
5180

5281
Use the following command to build and run the executable target.
5382

5483
```bash
55-
cmake -Sstandalone -Bbuild/standalone
84+
make standalone
85+
86+
# or
5687
cmake --build build/standalone
57-
./build/standalone/MathFunctionsStandalone --help
88+
build/standalone/MathFunctionsStandalone 2.0
5889
```
5990

6091
### Build and run test suite
@@ -63,25 +94,39 @@ Use the following commands from the project's root directory to run the
6394
test suite.
6495

6596
```bash
66-
cmake -Stest -Bbuild/test
97+
make test
98+
99+
# or
100+
cmake -S test -B build/test
67101
cmake --build build/test
68102
CTEST_OUTPUT_ON_FAILURE=1 cmake --build build/test --target test
69103

70104
# or simply call the executable:
71-
./build/test/MathFunctionsTest
105+
build/test/MathFunctionsTest
72106
```
73107

74108
To collect code coverage information, run CMake with the
75109
`-DENABLE_TEST_COVERAGE=1` option.
76110

111+
112+
### Run clang-tidy
113+
114+
To check your project with _clang-tidy_ simply do
115+
116+
`make check`
117+
118+
77119
### Run clang-format
78120

79121
Use the following commands from the project's root directory to check and
80122
fix C++ and CMake source style. This requires _clang-format_,
81123
_cmake-format_ and _pyyaml_ to be installed on the current system.
82124

83125
```bash
84-
cmake -Stest -Bbuild/test
126+
make format
127+
128+
# or
129+
cmake -S test -B build/test
85130

86131
# view changes
87132
cmake --build build/test --target format
@@ -92,12 +137,16 @@ cmake --build build/test --target fix-format
92137

93138
See [Format.cmake](https://github.com/TheLartians/Format.cmake) for details.
94139

140+
95141
### Build the documentation
96142

97143
To manually build documentation, call the following command.
98144

99145
```bash
100-
cmake -Sdocumentation -Bbuild/doc
146+
make doc
147+
148+
# or
149+
cmake -S documentation -B build/doc
101150
cmake --build build/doc --target GenerateDocs
102151
# view the docs
103152
open build/doc/doxygen/html/index.html
@@ -106,23 +155,34 @@ open build/doc/doxygen/html/index.html
106155
To build the documentation locally, you will need Doxygen, jinja2 and
107156
Pygments on installed your system.
108157

158+
109159
### Build everything at once
110160

111161
The project also includes an `all` directory that allows building all
112162
targets at the same time. This is useful during development, as it
113163
exposes all subprojects to your IDE and avoids redundant builds of the
114164
library.
115165

166+
#### Hint: Try [Qt Creator](https://www.qt.io/download-open-source) as IDE
167+
168+
It creates the best usable results when open a project via
169+
[all/CMakeLists.txt](all/CMakeLists.txt). And it supports to direct
170+
import a existing CMake build directory.
171+
172+
116173
```bash
117-
cmake -Sall -Bbuild
174+
make all
175+
176+
# or
177+
cmake -S all -B build
118178
cmake --build build
119179

120180
# run tests
121-
./build/test/MathFunctionsTest
181+
build/test/MathFunctionsTest
122182
# format code
123183
cmake --build build --target fix-format
124184
# run standalone
125-
./build/standalone/MathFunctionsStandalone --help
185+
build/standalone/MathFunctionsStandalone 42.0
126186
# build docs
127187
cmake --build build --target GenerateDocs
128188
```
@@ -152,6 +212,7 @@ setting the `CLANG_TIDY_ARGS`, `IWYU_ARGS` or `CPPCHECK_ARGS` variables.
152212

153213
Ccache can be enabled by configuring with `-DUSE_CCACHE=<ON | OFF>`.
154214

215+
155216
## FAQ
156217

157218
> Can I use this for header-only libraries?

cmake/tools.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if(USE_SANITIZER OR USE_STATIC_ANALYZER)
2121
CPMAddPackage(
2222
NAME StableCoder-cmake-scripts
2323
GITHUB_REPOSITORY StableCoder/cmake-scripts
24-
GIT_TAG 3d2d5a9fb26f0ce24e3e4eaeeff686ec2ecfb3fb
24+
GIT_TAG 21.01
2525
)
2626

2727
if(USE_SANITIZER)

test/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ endif()
3939
CPMAddPackage(
4040
NAME Format.cmake
4141
GITHUB_REPOSITORY TheLartians/Format.cmake
42-
VERSION 1.6
43-
OPTIONS # enable cmake formatting
44-
"FORMAT_CHECK_CMAKE ON"
42+
VERSION 1.7.0
43+
OPTIONS # skip cmake formatting
44+
"FORMAT_SKIP_CMAKE ON"
4545
)
4646

4747
# ---- Create binary ----

0 commit comments

Comments
 (0)