From f00ccd89c49a9c80623ddab4cb2d218997c7be09 Mon Sep 17 00:00:00 2001 From: Lars Melchior Date: Wed, 28 Sep 2022 21:31:15 +0200 Subject: [PATCH] Update example in readme (#413) * update readme example * Update README.md --- README.md | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 2fd49a6..b7027fd 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,30 @@ For everything else, the targets can be created manually after the dependency ha - [CPM: An Awesome Dependency Manager for C++ with CMake](https://medium.com/swlh/cpm-an-awesome-dependency-manager-for-c-with-cmake-3c53f4376766) - [CMake and the Future of C++ Package Management](https://ibob.github.io/blog/2020/01/13/cmake-package-management/) +## Full CMakeLists Example + +```cmake +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) + +# create project +project(MyProject) + +# add executable +add_executable(main main.cpp) + +# add dependencies +include(cmake/CPM.cmake) + +CPMAddPackage("gh:fmtlib/fmt#7.1.3") +CPMAddPackage("gh:nlohmann/json@3.10.5") +CPMAddPackage("gh:catchorg/Catch2@2.5.0") + +# link dependencies +target_link_libraries(main fmt::fmt nlohmann_json::nlohmann_json Catch2::Catch2) +``` + +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. + ## Usage 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 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. -## Full CMakeLists Example - -```cmake -cmake_minimum_required(VERSION 3.14 FATAL_ERROR) - -# create project -project(MyProject) - -# add executable -add_executable(tests tests.cpp) - -# add dependencies -include(cmake/CPM.cmake) -CPMAddPackage("gh:catchorg/Catch2@2.5.0") - -# link dependencies -target_link_libraries(tests Catch2) -``` - -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. - ## Adding CPM 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.