mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-20 13:17:53 -05:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d75ed06a3 | ||
|
|
1e25367c8c | ||
|
|
9d2b5818c5 | ||
|
|
49e7903e19 | ||
|
|
4d3997d408 | ||
|
|
d74bcebfe8 | ||
|
|
db3111e07e | ||
|
|
840e2e2c40 | ||
|
|
4952fd3d48 | ||
|
|
3659fa581c | ||
|
|
4aeb1215bf | ||
|
|
13559c7137 | ||
|
|
e4f1ade459 | ||
|
|
7723e56dab | ||
|
|
8287799e79 | ||
|
|
cd91713d10 | ||
|
|
4967b841ad | ||
|
|
9c2c34f487 | ||
|
|
bd9143bfa0 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,3 +8,4 @@ install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
build
|
||||
.vscode
|
||||
@@ -44,5 +44,9 @@ before_install:
|
||||
- cmake --version
|
||||
|
||||
script:
|
||||
# unit tests
|
||||
- cmake -Htest -Bbuild/test
|
||||
- CTEST_OUTPUT_ON_FAILURE=1 cmake --build build/test --target test
|
||||
# examples
|
||||
- python3 examples/run_all.py
|
||||
|
||||
157
README.md
157
README.md
@@ -1,23 +1,29 @@
|
||||
[](https://travis-ci.com/TheLartians/CPM)
|
||||
|
||||
# CPM
|
||||
<p align="center">
|
||||
<img src="./logo/CPM.png" height="100" />
|
||||
</p>
|
||||
|
||||
CPM is a CMake script that adds dependency management capabilities to CMake.
|
||||
It's built as an extension of CMake's [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) module that adds version control and simpler usage.
|
||||
# Setup-free CMake dependency management
|
||||
|
||||
## Supported projects
|
||||
CPM is a CMake script that adds dependency management capabilities to CMake.
|
||||
It's built as a wrapper around CMake's [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) module that adds version control and a simple API.
|
||||
|
||||
Any project that you can add via `add_subdirectory` should already work with CPM.
|
||||
## Manage everything
|
||||
|
||||
Anything can be added as a version-controlled dependency though CPM, no packaging required.
|
||||
Projects using CMake are automatically configured and their targets can be used immediately.
|
||||
For everything else, a target can be created manually (see below).
|
||||
|
||||
## Usage
|
||||
|
||||
After `CPM.cmake` has been added to your project, the function `CPMAddPackage` can be used to fetch and configure all dependencies.
|
||||
Afterwards all targets defined in the dependencies can be used.
|
||||
`CPMAddPackage` takes the following named arguments.
|
||||
After `CPM.cmake` has been added to your project, the function `CPMAddPackage` can be used to fetch and configure a dependency.
|
||||
Afterwards, any targets defined in the dependency can be used directly.
|
||||
`CPMAddPackage` takes the following named paramters.
|
||||
|
||||
```cmake
|
||||
CPMAddPackage(
|
||||
NAME # The name of the dependency (should be chosen to match the main target's name)
|
||||
NAME # The unique name of the dependency (should be the main target's name)
|
||||
VERSION # The minimum version of the dependency (optional, defaults to 0)
|
||||
OPTIONS # Configuration options passed to the dependency (optional)
|
||||
DOWNLOAD_ONLY # If set, the project is downloaded, but not configured (optional)
|
||||
@@ -25,9 +31,9 @@ CPMAddPackage(
|
||||
)
|
||||
```
|
||||
|
||||
The origin is usually specified by a `GIT_REPOSITORY`, but [svn revisions and direct URLs are also supported](https://cmake.org/cmake/help/latest/module/FetchContent.html#declaring-content-details).
|
||||
If `GIT_TAG` hasn't been explicitly specified it defaults to `v(VERSION)`, a common convention for github projects.
|
||||
`GIT_TAG` can also be set to a branch name such as `master` to download the most recent version.
|
||||
The origin may be specified by a `GIT_REPOSITORY`, but other sources, such as direct URLs, are [also supported](https://cmake.org/cmake/help/v3.11/module/ExternalProject.html#external-project-definition).
|
||||
If `GIT_TAG` hasn't been explicitly specified it defaults to `v(VERSION)`, a common convention for git projects.
|
||||
`GIT_TAG` can also be set to a specific commit or a branch name such as `master` to download the most recent version.
|
||||
|
||||
Besides downloading and to configuring the dependency, the following variables are defined in the local scope, where `(DEPENDENCY)` is the name of the dependency.
|
||||
|
||||
@@ -35,7 +41,7 @@ Besides downloading and to configuring the dependency, the following variables a
|
||||
- `(DEPENDENCY)_BINARY_DIR` is the path to the build directory of the dependency.
|
||||
- `(DEPENDENCY)_ADDED` is set to `YES` if the dependency has not been added before, otherwise it is set to `NO`.
|
||||
|
||||
## Full Example
|
||||
## Full CMakeLists Example
|
||||
|
||||
```cmake
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
@@ -43,6 +49,10 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
# create project
|
||||
project(MyProject)
|
||||
|
||||
# add executable
|
||||
add_executable(myProject myProject.cpp)
|
||||
set_target_properties(myProject PROPERTIES CXX_STANDARD 17)
|
||||
|
||||
# add dependencies
|
||||
include(cmake/CPM.cmake)
|
||||
|
||||
@@ -54,9 +64,6 @@ CPMAddPackage(
|
||||
"LARS_PARSER_BUILD_GLUE_EXTENSION ON"
|
||||
)
|
||||
|
||||
# add executable
|
||||
add_executable(myProject myProject.cpp)
|
||||
set_target_properties(myProject PROPERTIES CXX_STANDARD 17)
|
||||
target_link_libraries(myProject LarsParser)
|
||||
```
|
||||
|
||||
@@ -67,6 +74,7 @@ See the [examples directory](https://github.com/TheLartians/CPM/tree/master/exam
|
||||
To add CPM to your current project, simply add `cmake/CPM.cmake` to your project's `cmake` directory. The command below will perform this automatically.
|
||||
|
||||
```bash
|
||||
mkdir -p cmake
|
||||
wget -O cmake/CPM.cmake https://raw.githubusercontent.com/TheLartians/CPM/master/cmake/CPM.cmake
|
||||
```
|
||||
|
||||
@@ -74,13 +82,35 @@ wget -O cmake/CPM.cmake https://raw.githubusercontent.com/TheLartians/CPM/master
|
||||
|
||||
To update CPM to the newest version, simply update the script in the project's cmake directory, for example by running the command above. Dependencies using CPM will automatically use the updated script of the outermost project.
|
||||
|
||||
## Advantages
|
||||
|
||||
- **Small and reusable projects** CPM takes care of all project dependencies, allowing developers to focus on creating small, well-tested frameworks.
|
||||
- **Cross-Plattform** CPM adds projects via `add_subdirectory`, which is compatible with all cmake toolchains and generators.
|
||||
- **Reproducable builds** By using versioning via git tags it is ensured that a project will always be in the same state everywhere.
|
||||
- **Recursive dependencies** Ensures that no dependency is added twice and is added in the minimum required version.
|
||||
- **Plug-and-play** No need to install anything. Just add the script to your project and you're good to go.
|
||||
- **No packaging required** There is a good chance your existing projects already work as CPM dependencies.
|
||||
- **Simple source distribution** CPM makes including projects with source files and dependencies easy, reducing the need for monolithic header files.
|
||||
|
||||
## Limitations
|
||||
|
||||
- **No pre-built binaries** For every new project, all dependencies must be downloaded and built from scratch. A possible workaround is to use CPM to fetch a pre-built binary or to enable local packages (see below).
|
||||
- **Dependent on good CMakeLists** Many libraries do not have CMakeLists that work well for subprojects. Luckily this is slowly changing, however, until then, some manual configuration may be required (see below).
|
||||
- **First version used** In diamond-shaped dependency graphs (e.g. `A` depends on `C`@1.1 and `B`, which itself depends on `C`@1.2 the first added dependency will be used (in this case `C`@1.1). In this case, B requires a newer version of `C` than `A`, so CPM will emit an error. This can be resolved by updating the outermost dependency version.
|
||||
|
||||
For projects with more complex needs and where an extra setup step doesn't matter, it is worth to check out fully featured C++ package managers such as [conan](https://conan.io), [vcpkg](https://github.com/microsoft/vcpkg) or [hunter](https://github.com/ruslo/hunter).
|
||||
Support for package managers is also [planned](https://github.com/TheLartians/CPM/issues/51) for a future version of CPM.
|
||||
|
||||
## Local packages
|
||||
|
||||
CPM can be configured to use `find_package` to search for locally installed dependencies first by setting the CMake option `CPM_USE_LOCAL_PACKAGES`.
|
||||
If the option `CPM_LOCAL_PACKAGES_ONLY` is set, CPM will emit an error if the dependency is not found locally.
|
||||
|
||||
## Snipplets
|
||||
|
||||
These examples demonstrate how to include some well-known projects with CPM.
|
||||
|
||||
### [Catch2](https://github.com/catchorg/Catch2.git)
|
||||
|
||||
Has a CMakeLists.txt that supports `add_subdirectory`.
|
||||
### [Catch2](https://github.com/catchorg/Catch2)
|
||||
|
||||
```cmake
|
||||
CPMAddPackage(
|
||||
@@ -90,12 +120,17 @@ CPMAddPackage(
|
||||
)
|
||||
```
|
||||
|
||||
See [here](https://github.com/TheLartians/CPM/blob/master/examples/doctest/CMakeLists.txt) for doctest example.
|
||||
Note that we can shorten Github and Gitlab URLs by using `GITHUB_REPOSITORY` or `GITLAB_REPOSITORY`, respectively.
|
||||
### [Doctest](https://github.com/onqtam/doctest)
|
||||
|
||||
### [google/benchmark](https://github.com/google/benchmark.git)
|
||||
```cmake
|
||||
CPMAddPackage(
|
||||
NAME doctest
|
||||
GITHUB_REPOSITORY onqtam/doctest
|
||||
GIT_TAG 2.3.2
|
||||
)
|
||||
```
|
||||
|
||||
Has a CMakeLists.txt that supports `add_subdirectory`, but needs some configuring to work without external dependencies.
|
||||
### [google/benchmark](https://github.com/google/benchmark)
|
||||
|
||||
```cmake
|
||||
CPMAddPackage(
|
||||
@@ -106,44 +141,77 @@ CPMAddPackage(
|
||||
"BENCHMARK_ENABLE_TESTING Off"
|
||||
)
|
||||
|
||||
# needed to compile with C++17
|
||||
set_target_properties(benchmark PROPERTIES CXX_STANDARD 17)
|
||||
if (benchmark_ADDED)
|
||||
# compile with C++17
|
||||
set_target_properties(benchmark PROPERTIES CXX_STANDARD 17)
|
||||
endif()
|
||||
```
|
||||
|
||||
### [nlohmann/json](https://github.com/nlohmann/json)
|
||||
|
||||
Header-only library with a huge git repositoy.
|
||||
Instead of downloading the whole repositoy, we fetch the zip included with the release and create our own target.
|
||||
|
||||
```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)
|
||||
add_library(nlohmann_json INTERFACE IMPORTED)
|
||||
target_include_directories(nlohmann_json INTERFACE ${nlohmann_json_SOURCE_DIR})
|
||||
endif()
|
||||
```
|
||||
|
||||
Adding large repos works as well, but takes a while for the initial clone.
|
||||
### [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()
|
||||
```
|
||||
|
||||
### [Yaml-cpp](https://github.com/jbeder/yaml-cpp)
|
||||
|
||||
```CMake
|
||||
CPMAddPackage(
|
||||
NAME yaml-cpp
|
||||
GITHUB_REPOSITORY jbeder/yaml-cpp
|
||||
# 0.6.2 uses depricated CMake syntax
|
||||
VERSION 0.6.3
|
||||
# 0.6.3 is not released yet, so use a recent commit
|
||||
GIT_TAG 012269756149ae99745b6dafefd415843d7420bb
|
||||
OPTIONS
|
||||
"YAML_CPP_BUILD_TESTS Off"
|
||||
"YAML_CPP_BUILD_CONTRIB Off"
|
||||
"YAML_CPP_BUILD_TOOLS Off"
|
||||
)
|
||||
```
|
||||
|
||||
### [Lua](https://www.lua.org)
|
||||
|
||||
Lua does not oficially support CMake, so we query the sources and create our own target.
|
||||
|
||||
```cmake
|
||||
CPMAddPackage(
|
||||
NAME lua
|
||||
GIT_REPOSITORY https://github.com/lua/lua.git
|
||||
VERSION 5-3-4
|
||||
GIT_TAG v5-3-4
|
||||
VERSION 5.3.4
|
||||
DOWNLOAD_ONLY YES
|
||||
)
|
||||
|
||||
if (lua_ADDED)
|
||||
# lua has no CMakeLists, so we create our own target
|
||||
|
||||
FILE(GLOB lua_sources ${lua_SOURCE_DIR}/*.c)
|
||||
add_library(lua STATIC ${lua_sources})
|
||||
|
||||
@@ -154,25 +222,8 @@ if (lua_ADDED)
|
||||
endif()
|
||||
```
|
||||
|
||||
## Local packages
|
||||
For a full example on using CPM to download and configure lua with sol2 see [here](examples/sol2).
|
||||
|
||||
CPM can be configured to use `find_package` to search for locally installed dependencies first.
|
||||
If `CPM_LOCAL_PACKAGES_ONLY` is set, CPM will error when dependency is not found locally.
|
||||
### Examples
|
||||
|
||||
## Advantages
|
||||
|
||||
- **Small and reusable projects** CPM takes care of project dependencies, allowing developers to focus on creating small, well-tested frameworks.
|
||||
- **Cross-Plattform** CPM adds projects via `add_subdirectory`, which is compatible with all cmake toolchains and generators.
|
||||
- **Reproducable builds** By using versioning via git tags it is ensured that a project will always be in the same state everywhere.
|
||||
- **Recursive dependencies** Ensures that no dependency is added twice and is added in the minimum required version.
|
||||
- **No installation required** No need to install anything. Just add the script to your project and you're good to go.
|
||||
- **No Setup required** There is a good chance your existing projects already work as CPM dependencies.
|
||||
- **Simple source distribution** CPM makes including projects with source files and dependencies easy, reducing the need for monolithic header files.
|
||||
|
||||
## Limitations
|
||||
|
||||
- **First version used** In diamond-shaped dependency graphs (e.g. `A` depends on `C`@1.1 and `B`, which itself depends on `C`@1.2 the first added dependency will be used (in this case `C`@1.1). In this case, B requires a newer version of `C` than `A`, so CPM will emit an error. This can be resolved by updating the outermost dependency version.
|
||||
- **No auto-update** To update a dependency, version must be adapted manually and there is no way for CPM to figure out the most recent version.
|
||||
- **No pre-built binaries** Unless they are installed or included in the linked repository.
|
||||
|
||||
For projects with more complex needs and where an extra setup step doesn't matter, it is worth to check out fully featured C++ package managers such as [conan](https://conan.io) or [hunter](https://github.com/ruslo/hunter).
|
||||
See the [examples directory](https://github.com/TheLartians/CPM/tree/master/examples) for more examples with source code.
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
set(CURRENT_CPM_VERSION 0.11)
|
||||
set(CURRENT_CPM_VERSION 0.12)
|
||||
|
||||
if(CPM_DIRECTORY)
|
||||
if(NOT ${CPM_DIRECTORY} MATCHES ${CMAKE_CURRENT_LIST_DIR})
|
||||
@@ -42,10 +42,12 @@ endif()
|
||||
set(CPM_VERSION ${CURRENT_CPM_VERSION} CACHE INTERNAL "")
|
||||
set(CPM_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL "")
|
||||
set(CPM_PACKAGES "" CACHE INTERNAL "")
|
||||
set(CPM_DRY_RUN OFF CACHE INTERNAL "Don't download or configure dependencies (for testing)")
|
||||
|
||||
option(CPM_USE_LOCAL_PACKAGES "Use locally installed packages (find_package)" OFF)
|
||||
option(CPM_LOCAL_PACKAGES_ONLY "Use only locally installed packages" OFF)
|
||||
|
||||
|
||||
include(FetchContent)
|
||||
include(CMakeParseArguments)
|
||||
|
||||
@@ -64,6 +66,7 @@ function(CPMAddPackage)
|
||||
DOWNLOAD_ONLY
|
||||
GITHUB_REPOSITORY
|
||||
GITLAB_REPOSITORY
|
||||
DRY # for testing
|
||||
)
|
||||
|
||||
set(multiValueArgs
|
||||
@@ -89,11 +92,16 @@ function(CPMAddPackage)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT CPM_ARGS_VERSION)
|
||||
set(CPM_ARGS_VERSION 0)
|
||||
if (NOT DEFINED CPM_ARGS_VERSION)
|
||||
if (DEFINED CPM_ARGS_GIT_TAG)
|
||||
CPM_GET_VERSION_FROM_GIT_TAG("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION)
|
||||
endif()
|
||||
if (NOT DEFINED CPM_ARGS_VERSION)
|
||||
set(CPM_ARGS_VERSION 0)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT CPM_ARGS_GIT_TAG)
|
||||
if (NOT DEFINED CPM_ARGS_GIT_TAG)
|
||||
set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION})
|
||||
endif()
|
||||
|
||||
@@ -110,11 +118,11 @@ function(CPMAddPackage)
|
||||
endif()
|
||||
|
||||
if (CPM_ARGS_GITLAB_REPOSITORY)
|
||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_REPOSITORY "https://gitlab.com/${CPM_ARGS_GITHUB_REPOSITORY}.git")
|
||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_REPOSITORY "https://gitlab.com/${CPM_ARGS_GITLAB_REPOSITORY}.git")
|
||||
endif()
|
||||
|
||||
if (${CPM_ARGS_NAME} IN_LIST CPM_PACKAGES)
|
||||
CPM_GET_PACKAGE_VERSION(${CPM_ARGS_NAME})
|
||||
CPM_GET_PACKAGE_VERSION(${CPM_ARGS_NAME} CPM_PACKAGE_VERSION)
|
||||
if(${CPM_PACKAGE_VERSION} VERSION_LESS ${CPM_ARGS_VERSION})
|
||||
message(WARNING "${CPM_INDENT} requires a newer version of ${CPM_ARGS_NAME} (${CPM_ARGS_VERSION}) than currently included (${CPM_PACKAGE_VERSION}).")
|
||||
endif()
|
||||
@@ -154,6 +162,11 @@ endfunction()
|
||||
function (CPM_DECLARE_PACKAGE PACKAGE VERSION GIT_TAG)
|
||||
message(STATUS "${CPM_INDENT} adding package ${PACKAGE}@${VERSION} (${GIT_TAG})")
|
||||
|
||||
if (${CPM_DRY_RUN})
|
||||
message(STATUS "${CPM_INDENT} package not declared (dry run)")
|
||||
return()
|
||||
endif()
|
||||
|
||||
FetchContent_Declare(
|
||||
${PACKAGE}
|
||||
${ARGN}
|
||||
@@ -161,6 +174,12 @@ function (CPM_DECLARE_PACKAGE PACKAGE VERSION GIT_TAG)
|
||||
endfunction()
|
||||
|
||||
function (CPM_FETCH_PACKAGE PACKAGE DOWNLOAD_ONLY)
|
||||
|
||||
if (${CPM_DRY_RUN})
|
||||
message(STATUS "${CPM_INDENT} package ${PACKAGE} not fetched (dry run)")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(CPM_OLD_INDENT "${CPM_INDENT}")
|
||||
set(CPM_INDENT "${CPM_INDENT} ${PACKAGE}:")
|
||||
if(${DOWNLOAD_ONLY})
|
||||
@@ -174,6 +193,9 @@ function (CPM_FETCH_PACKAGE PACKAGE DOWNLOAD_ONLY)
|
||||
endfunction()
|
||||
|
||||
function (CPMGetProperties PACKAGE)
|
||||
if (${CPM_DRY_RUN})
|
||||
return()
|
||||
endif()
|
||||
FetchContent_GetProperties(${PACKAGE})
|
||||
string(TOLOWER ${PACKAGE} lpackage)
|
||||
SET(${PACKAGE}_SOURCE_DIR "${${lpackage}_SOURCE_DIR}" PARENT_SCOPE)
|
||||
@@ -186,8 +208,8 @@ function(CPMRegisterPackage PACKAGE VERSION)
|
||||
set("CPM_PACKAGE_${PACKAGE}_VERSION" ${VERSION} CACHE INTERNAL "")
|
||||
endfunction()
|
||||
|
||||
function(CPM_GET_PACKAGE_VERSION PACKAGE)
|
||||
set(CPM_PACKAGE_VERSION "${CPM_PACKAGE_${PACKAGE}_VERSION}" PARENT_SCOPE)
|
||||
function(CPM_GET_PACKAGE_VERSION PACKAGE OUTPUT)
|
||||
set(${OUTPUT} "${CPM_PACKAGE_${PACKAGE}_VERSION}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(CPM_PARSE_OPTION OPTION)
|
||||
@@ -199,6 +221,11 @@ function(CPM_PARSE_OPTION OPTION)
|
||||
set(OPTION_VALUE "${OPTION_VALUE}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(CPM_GET_VERSION_FROM_GIT_TAG GIT_TAG RESULT)
|
||||
string(REGEX MATCH "v?([0123456789.]*).*" _ ${GIT_TAG})
|
||||
SET(${RESULT} ${CMAKE_MATCH_1} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function (CPM_HANDLE_OLD_VERSION NEW_CPM_VERSION)
|
||||
|
||||
message(AUTHOR_WARNING "${CPM_INDENT} \
|
||||
@@ -207,4 +234,4 @@ It is recommended to upgrade CPM to the most recent version. \
|
||||
See https://github.com/TheLartians/CPM for more information."
|
||||
)
|
||||
|
||||
endfunction()
|
||||
endfunction()
|
||||
|
||||
10
cmake/testing.cmake
Normal file
10
cmake/testing.cmake
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
function(ASSERT_EQUAL)
|
||||
if (NOT ARGC EQUAL 2)
|
||||
message(FATAL_ERROR "assertion failed: invalid argument count: ${ARGC}")
|
||||
endif()
|
||||
|
||||
if (NOT ${ARGV0} EQUAL ${ARGV1})
|
||||
message(FATAL_ERROR "assertion failed: '${ARGV0}' != '${ARGV1}'")
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -17,7 +17,6 @@ CPMAddPackage(
|
||||
CPMAddPackage(
|
||||
NAME doctest
|
||||
GITHUB_REPOSITORY onqtam/doctest
|
||||
VERSION 2.3.2
|
||||
GIT_TAG 2.3.2
|
||||
)
|
||||
|
||||
|
||||
24
examples/range-v3/CMakeLists.txt
Normal file
24
examples/range-v3/CMakeLists.txt
Normal file
@@ -0,0 +1,24 @@
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
# ---- Dependencies ----
|
||||
|
||||
include(../../cmake/CPM.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()
|
||||
|
||||
# ---- Executable ----
|
||||
|
||||
add_executable(CPMRangev3Example "main.cpp")
|
||||
set_target_properties(CPMRangev3Example PROPERTIES CXX_STANDARD 17)
|
||||
target_link_libraries(CPMRangev3Example range-v3)
|
||||
44
examples/range-v3/main.cpp
Normal file
44
examples/range-v3/main.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// Range v3 library
|
||||
//
|
||||
// Copyright Jeff Garland 2017
|
||||
//
|
||||
// Use, modification and distribution is subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Project home: https://github.com/ericniebler/range-v3
|
||||
//
|
||||
|
||||
//[any_all_none_of]]
|
||||
// Demonstrates any_of, all_of, none_of
|
||||
// output
|
||||
// vector: [6,2,3,4,5,6]
|
||||
// vector any_of is_six: true
|
||||
// vector all_of is_six: false
|
||||
// vector none_of is_six: false
|
||||
|
||||
#include <range/v3/algorithm/all_of.hpp>
|
||||
#include <range/v3/algorithm/any_of.hpp>
|
||||
#include <range/v3/algorithm/for_each.hpp>
|
||||
#include <range/v3/algorithm/none_of.hpp>
|
||||
#include <range/v3/view/all.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using std::cout;
|
||||
|
||||
auto is_six = [](int i) { return i == 6; };
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
std::vector<int> v{6, 2, 3, 4, 5, 6};
|
||||
cout << std::boolalpha;
|
||||
cout << "vector: " << ranges::view::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';
|
||||
cout << "vector none_of is_six: " << ranges::none_of(v, is_six) << '\n';
|
||||
}
|
||||
//[any_all_none_of]]
|
||||
46
examples/sol2/CMakeLists.txt
Normal file
46
examples/sol2/CMakeLists.txt
Normal file
@@ -0,0 +1,46 @@
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
# ---- Dependencies ----
|
||||
|
||||
include(../../cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME lua
|
||||
GIT_REPOSITORY https://github.com/lua/lua.git
|
||||
VERSION 5.3.4
|
||||
GIT_TAG v5-3-4
|
||||
DOWNLOAD_ONLY YES
|
||||
)
|
||||
|
||||
if (lua_ADDED)
|
||||
# lua has no CMakeLists, so we create our own target
|
||||
|
||||
FILE(GLOB lua_sources ${lua_SOURCE_DIR}/*.c)
|
||||
add_library(lua STATIC ${lua_sources})
|
||||
|
||||
target_include_directories(lua
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${lua_SOURCE_DIR}>
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
CPMAddPackage(
|
||||
NAME sol2
|
||||
URL https://github.com/ThePhD/sol2/archive/v3.0.2.zip
|
||||
VERSION 3.0.2
|
||||
DOWNLOAD_ONLY YES
|
||||
)
|
||||
|
||||
if (sol2_ADDED)
|
||||
add_library(sol2 INTERFACE IMPORTED)
|
||||
target_include_directories(sol2 INTERFACE ${sol2_SOURCE_DIR}/include)
|
||||
target_link_libraries(sol2 INTERFACE lua)
|
||||
endif()
|
||||
|
||||
# ---- Executable ----
|
||||
|
||||
add_executable(CPMSol2Example "main.cpp")
|
||||
set_target_properties(CPMSol2Example PROPERTIES CXX_STANDARD 17)
|
||||
target_link_libraries(CPMSol2Example sol2)
|
||||
|
||||
16
examples/sol2/main.cpp
Normal file
16
examples/sol2/main.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <sol/sol.hpp>
|
||||
#include <cassert>
|
||||
|
||||
struct vars {
|
||||
int boop = 0;
|
||||
};
|
||||
|
||||
int main() {
|
||||
sol::state lua;
|
||||
lua.open_libraries( sol::lib::base );
|
||||
lua.new_usertype<vars>("vars", "boop", &vars::boop);
|
||||
lua.script("beep = vars.new()\n"
|
||||
"beep.boop = 1\n"
|
||||
"print('beep boop')");
|
||||
assert(lua.get<vars>("beep").boop == 1);
|
||||
}
|
||||
BIN
logo/CPM.afdesign
Normal file
BIN
logo/CPM.afdesign
Normal file
Binary file not shown.
BIN
logo/CPM.png
Normal file
BIN
logo/CPM.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
14
test/CMakeLists.txt
Normal file
14
test/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
file(GLOB tests "${CMAKE_CURRENT_SOURCE_DIR}/unit/*.cmake")
|
||||
|
||||
enable_testing()
|
||||
|
||||
foreach(test ${tests})
|
||||
message(STATUS "adding test: ${test}")
|
||||
add_test(
|
||||
NAME ${test}
|
||||
COMMAND ${CMAKE_COMMAND} -DCPM_PATH=${CMAKE_CURRENT_SOURCE_DIR}/../cmake -P "${test}"
|
||||
)
|
||||
|
||||
endforeach()
|
||||
30
test/unit/dependency_properties.cmake
Normal file
30
test/unit/dependency_properties.cmake
Normal file
@@ -0,0 +1,30 @@
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
include(${CPM_PATH}/CPM.cmake)
|
||||
include(${CPM_PATH}/testing.cmake)
|
||||
|
||||
set(CPM_DRY_RUN ON)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME A
|
||||
GIT_TAG 1.2.3
|
||||
)
|
||||
|
||||
CPM_GET_PACKAGE_VERSION(A VERSION)
|
||||
ASSERT_EQUAL(${VERSION} "1.2.3")
|
||||
|
||||
CPMAddPackage(
|
||||
NAME B
|
||||
GIT_TAG v2.3.1
|
||||
)
|
||||
|
||||
CPM_GET_PACKAGE_VERSION(B VERSION)
|
||||
ASSERT_EQUAL(${VERSION} "2.3.1")
|
||||
|
||||
CPMAddPackage(
|
||||
NAME C
|
||||
GIT_TAG v3.1.2-a
|
||||
)
|
||||
|
||||
CPM_GET_PACKAGE_VERSION(C VERSION)
|
||||
ASSERT_EQUAL(${VERSION} "3.1.2")
|
||||
16
test/unit/version_from_git_tag.cmake
Normal file
16
test/unit/version_from_git_tag.cmake
Normal file
@@ -0,0 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
include(${CPM_PATH}/CPM.cmake)
|
||||
include(${CPM_PATH}/testing.cmake)
|
||||
|
||||
CPM_GET_VERSION_FROM_GIT_TAG("1.2.3" VERSION)
|
||||
ASSERT_EQUAL("1.2.3" ${VERSION})
|
||||
|
||||
CPM_GET_VERSION_FROM_GIT_TAG("v1.2.3" VERSION)
|
||||
ASSERT_EQUAL("1.2.3" ${VERSION})
|
||||
|
||||
CPM_GET_VERSION_FROM_GIT_TAG("1.2.3-a" VERSION)
|
||||
ASSERT_EQUAL("1.2.3" ${VERSION})
|
||||
|
||||
CPM_GET_VERSION_FROM_GIT_TAG("v1.2.3-a" VERSION)
|
||||
ASSERT_EQUAL("1.2.3" ${VERSION})
|
||||
Reference in New Issue
Block a user