From 310efb9b17d0befe9ccd4f5bf2e39942869777fc Mon Sep 17 00:00:00 2001 From: Lars Melchior Date: Fri, 26 Mar 2021 17:31:35 +0100 Subject: [PATCH] Update more examples from the readme (#241) * update examples from the readme * add explainations to the examples --- README.md | 65 ++++++++++++-------------------- examples/json/CMakeLists.txt | 16 +------- examples/range-v3/CMakeLists.txt | 13 +------ examples/range-v3/main.cpp | 2 +- 4 files changed, 29 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 82544b7..e3a5ffb 100644 --- a/README.md +++ b/README.md @@ -276,9 +276,34 @@ CPMAddPackage("gh:catchorg/Catch2@2.5.0") CPMAddPackage("gh:Orphis/boost-cmake@1.67.0") ``` +### [Yaml-cpp](https://github.com/jbeder/yaml-cpp) + +```CMake +# as the tag is in an unusual format, we need to explicitly specify the version +CPMAddPackage("gh:jbeder/yaml-cpp#yaml-cpp-0.6.3@0.6.3") +``` + +### [Range-v3](https://github.com/ericniebler/range-v3) + +```Cmake +CPMAddPackage("gh:ericniebler/range-v3#0.11.0") +``` + +### [nlohmann/json](https://github.com/nlohmann/json) + +```cmake +CPMAddPackage( + NAME nlohmann_json + VERSION 3.9.1 + OPTIONS + "JSON_BuildTests OFF" +) +``` + ### [cxxopts](https://github.com/jarro2783/cxxopts) ```cmake +# the install option has to be explicitly set to allow installation CPMAddPackage( GITHUB_REPOSITORY jarro2783/cxxopts VERSION 2.2.1 @@ -286,12 +311,6 @@ CPMAddPackage( ) ``` -### [Yaml-cpp](https://github.com/jbeder/yaml-cpp) - -```CMake -CPMAddPackage("gh:jbeder/yaml-cpp#yaml-cpp-0.6.3@0.6.3") -``` - ### [google/benchmark](https://github.com/google/benchmark) ```cmake @@ -308,40 +327,6 @@ if(benchmark_ADDED) endif() ``` -### [nlohmann/json](https://github.com/nlohmann/json) - -```cmake -CPMAddPackage( - NAME nlohmann_json - VERSION 3.6.1 - # the git repo is incredibly large, so we download the archived include directory - URL https://github.com/nlohmann/json/releases/download/v3.6.1/include.zip - URL_HASH SHA256=69cc88207ce91347ea530b227ff0776db82dcb8de6704e1a3d74f4841bc651cf -) - -if (nlohmann_json_ADDED) - add_library(nlohmann_json INTERFACE IMPORTED) - target_include_directories(nlohmann_json INTERFACE ${nlohmann_json_SOURCE_DIR}) -endif() -``` - -### [Range-v3](https://github.com/ericniebler/range-v3) - -```Cmake -CPMAddPackage( - NAME range-v3 - URL https://github.com/ericniebler/range-v3/archive/0.5.0.zip - VERSION 0.5.0 - # the range-v3 CMakeLists screws with configuration options - DOWNLOAD_ONLY True -) - -if(range-v3_ADDED) - add_library(range-v3 INTERFACE IMPORTED) - target_include_directories(range-v3 INTERFACE "${range-v3_SOURCE_DIR}/include") -endif() -``` - ### [Lua](https://www.lua.org) ```cmake diff --git a/examples/json/CMakeLists.txt b/examples/json/CMakeLists.txt index 201fdfc..d2bd8db 100644 --- a/examples/json/CMakeLists.txt +++ b/examples/json/CMakeLists.txt @@ -5,22 +5,10 @@ project(CPMJSONExample) # ---- Dependencies ---- include(../../cmake/CPM.cmake) - -CPMAddPackage( - NAME nlohmann_json - VERSION 3.9.1 - # not using the repo as it takes forever to clone - URL https://github.com/nlohmann/json/releases/download/v3.9.1/include.zip - URL_HASH SHA256=6bea5877b1541d353bd77bdfbdb2696333ae5ed8f9e8cc22df657192218cad91 -) - -if(nlohmann_json_ADDED) - add_library(nlohmann_json INTERFACE) - target_include_directories(nlohmann_json SYSTEM INTERFACE ${nlohmann_json_SOURCE_DIR}/include) -endif() +CPMAddPackage("gh:nlohmann/json@3.9.1") # ---- Executable ---- add_executable(CPMJSONExample main.cpp) target_compile_features(CPMJSONExample PRIVATE cxx_std_17) -target_link_libraries(CPMJSONExample nlohmann_json) +target_link_libraries(CPMJSONExample nlohmann_json::nlohmann_json) diff --git a/examples/range-v3/CMakeLists.txt b/examples/range-v3/CMakeLists.txt index 3d3ac91..506817a 100644 --- a/examples/range-v3/CMakeLists.txt +++ b/examples/range-v3/CMakeLists.txt @@ -6,18 +6,7 @@ project(CPMRangev3Example) include(../../cmake/CPM.cmake) -CPMAddPackage( - NAME range-v3 - URL https://github.com/ericniebler/range-v3/archive/0.11.0.zip - VERSION 0.11.0 - # the range-v3 CMakeLists screws with configuration options - DOWNLOAD_ONLY True -) - -if(range-v3_ADDED) - add_library(range-v3 INTERFACE IMPORTED) - target_include_directories(range-v3 SYSTEM INTERFACE "${range-v3_SOURCE_DIR}/include") -endif() +CPMAddPackage("gh:ericniebler/range-v3#0.11.0") # ---- Executable ---- diff --git a/examples/range-v3/main.cpp b/examples/range-v3/main.cpp index 8d56c9e..ca9128c 100644 --- a/examples/range-v3/main.cpp +++ b/examples/range-v3/main.cpp @@ -32,7 +32,7 @@ auto is_six = [](int i) { return i == 6; }; int main() { std::vector v{6, 2, 3, 4, 5, 6}; cout << std::boolalpha; - cout << "vector: " << ranges::view::all(v) << '\n'; + cout << "vector: " << ranges::views::all(v) << '\n'; cout << "vector any_of is_six: " << ranges::any_of(v, is_six) << '\n'; cout << "vector all_of is_six: " << ranges::all_of(v, is_six) << '\n';