Skip to content

Commit f00ccd8

Browse files
authored
Update example in readme (#413)
* update readme example * Update README.md
1 parent 1f4909c commit f00ccd8

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

README.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,30 @@ For everything else, the targets can be created manually after the dependency ha
2121
- [CPM: An Awesome Dependency Manager for C++ with CMake](https://medium.com/swlh/cpm-an-awesome-dependency-manager-for-c-with-cmake-3c53f4376766)
2222
- [CMake and the Future of C++ Package Management](https://ibob.github.io/blog/2020/01/13/cmake-package-management/)
2323

24+
## Full CMakeLists Example
25+
26+
```cmake
27+
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
28+
29+
# create project
30+
project(MyProject)
31+
32+
# add executable
33+
add_executable(main main.cpp)
34+
35+
# add dependencies
36+
include(cmake/CPM.cmake)
37+
38+
CPMAddPackage("gh:fmtlib/fmt#7.1.3")
39+
CPMAddPackage("gh:nlohmann/json@3.10.5")
40+
CPMAddPackage("gh:catchorg/Catch2@2.5.0")
41+
42+
# link dependencies
43+
target_link_libraries(main fmt::fmt nlohmann_json::nlohmann_json Catch2::Catch2)
44+
```
45+
46+
See the [examples directory](https://github.com/cpm-cmake/CPM.cmake/tree/master/examples) for complete examples with source code and check [below](#snippets) or in the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/More-Snippets) for example snippets.
47+
2448
## Usage
2549

2650
After `CPM.cmake` has been [added](#adding-cpm) to your project, the function `CPMAddPackage` can be used to fetch and configure a dependency.
@@ -78,27 +102,6 @@ For using CPM.cmake projects with external package managers, such as conan or vc
78102

79103
In rare cases, this behaviour may be desirable by default. The function `CPMFindPackage` will try to find a local dependency via CMake's `find_package` and fallback to `CPMAddPackage`, if the dependency is not found.
80104

81-
## Full CMakeLists Example
82-
83-
```cmake
84-
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
85-
86-
# create project
87-
project(MyProject)
88-
89-
# add executable
90-
add_executable(tests tests.cpp)
91-
92-
# add dependencies
93-
include(cmake/CPM.cmake)
94-
CPMAddPackage("gh:catchorg/Catch2@2.5.0")
95-
96-
# link dependencies
97-
target_link_libraries(tests Catch2)
98-
```
99-
100-
See the [examples directory](https://github.com/cpm-cmake/CPM.cmake/tree/master/examples) for complete examples with source code and check [below](#snippets) or in the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/More-Snippets) for example snippets.
101-
102105
## Adding CPM
103106

104107
To add CPM to your current project, simply add the [latest release](https://github.com/cpm-cmake/CPM.cmake/releases/latest) of `CPM.cmake` or `get_cpm.cmake` to your project's `cmake` directory.

0 commit comments

Comments
 (0)