mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-19 16:57:56 -05:00
Compare commits
29 Commits
v0.16
...
v0.27.2-au
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab15c5f75e | ||
|
|
f97a7c61fc | ||
|
|
ac872f6908 | ||
|
|
bd14ccbd5a | ||
|
|
f8afae6eb3 | ||
|
|
9ec279c75f | ||
|
|
392b2a864b | ||
|
|
139d3cacba | ||
|
|
b31063d2ae | ||
|
|
4425bd38cf | ||
|
|
6da5c38dae | ||
|
|
76d7b27459 | ||
|
|
54a2d80d1e | ||
|
|
829262cbd3 | ||
|
|
4aeea1d31d | ||
|
|
58365446f5 | ||
|
|
4937617ef1 | ||
|
|
6f053907f5 | ||
|
|
84b31b560a | ||
|
|
3fff3ca70d | ||
|
|
ca33abc236 | ||
|
|
119eaee84d | ||
|
|
00b5e80f88 | ||
|
|
618cdefa0d | ||
|
|
464ba554c2 | ||
|
|
90558aa9cb | ||
|
|
95c5426d25 | ||
|
|
cea81872cf | ||
|
|
01b69aad82 |
10
.github/workflows/macos.yml
vendored
10
.github/workflows/macos.yml
vendored
@@ -1,11 +1,17 @@
|
|||||||
name: MacOS
|
name: MacOS
|
||||||
|
|
||||||
on: [push]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
||||||
runs-on: macOS-10.14
|
runs-on: macos-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
|
|||||||
25
.github/workflows/publish.yaml
vendored
Normal file
25
.github/workflows/publish.yaml
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
name: Publish
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Publish CPM.cmake
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: Set CPM version by tag
|
||||||
|
run: sed "s/0.27.2-development-version/${GITHUB_REF/refs\/tags\/v}/g" cmake/CPM.cmake > CPM.cmake
|
||||||
|
|
||||||
|
- name: Upload CPM.cmake to release
|
||||||
|
uses: svenstaro/upload-release-action@v1-release
|
||||||
|
with:
|
||||||
|
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
file: CPM.cmake
|
||||||
|
asset_name: CPM.cmake
|
||||||
|
tag: ${{ github.ref }}
|
||||||
|
overwrite: true
|
||||||
10
.github/workflows/ubuntu.yml
vendored
10
.github/workflows/ubuntu.yml
vendored
@@ -1,11 +1,17 @@
|
|||||||
name: Ubuntu
|
name: Ubuntu
|
||||||
|
|
||||||
on: [push]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
||||||
runs-on: ubuntu-18.04
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
|
|||||||
10
.github/workflows/windows.yml
vendored
10
.github/workflows/windows.yml
vendored
@@ -1,11 +1,17 @@
|
|||||||
name: Windows
|
name: Windows
|
||||||
|
|
||||||
on: [push]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
||||||
runs-on: windows-2019
|
runs-on: windows-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
|
|||||||
48
README.md
48
README.md
@@ -36,6 +36,7 @@ CPMAddPackage(
|
|||||||
|
|
||||||
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).
|
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.
|
If `GIT_TAG` hasn't been explicitly specified it defaults to `v(VERSION)`, a common convention for git projects.
|
||||||
|
On the other hand, if `VERSION` hasn't been explicitly specified, CPM can automatically identify the version from the git tag in some common cases.
|
||||||
`GIT_TAG` can also be set to a specific commit or a branch name such as `master` to always download the most recent version.
|
`GIT_TAG` can also be set to a specific commit or a branch name such as `master` to always download the most recent version.
|
||||||
The optional argument `FIND_PACKAGE_ARGUMENTS` can be specified to a string of parameters that will be passed to `find_package` if enabled (see below).
|
The optional argument `FIND_PACKAGE_ARGUMENTS` can be specified to a string of parameters that will be passed to `find_package` if enabled (see below).
|
||||||
|
|
||||||
@@ -72,7 +73,7 @@ CPMAddPackage(
|
|||||||
target_link_libraries(tests Catch2)
|
target_link_libraries(tests Catch2)
|
||||||
```
|
```
|
||||||
|
|
||||||
See the [examples directory](https://github.com/TheLartians/CPM/tree/master/examples) for complete examples with source code or the [wiki](https://github.com/TheLartians/CPM/wiki/More-Snippets) for example snippets.
|
See the [examples directory](https://github.com/TheLartians/CPM.cmake/tree/master/examples) for complete examples with source code or the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/More-Snippets) for example snippets.
|
||||||
|
|
||||||
## Adding CPM
|
## Adding CPM
|
||||||
|
|
||||||
@@ -80,10 +81,10 @@ To add CPM to your current project, simply add `cmake/CPM.cmake` to your project
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
mkdir -p cmake
|
mkdir -p cmake
|
||||||
wget -O cmake/CPM.cmake https://raw.githubusercontent.com/TheLartians/CPM.cmake/master/cmake/CPM.cmake
|
wget -O cmake/CPM.cmake https://github.com/TheLartians/CPM.cmake/releases/latest/download/CPM.cmake
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also use CMake to download CPM for you. See the [wiki](https://github.com/TheLartians/CPM/wiki/Adding-CPM) for more details.
|
You can also use CMake to download CPM for you. See the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/Downloading-CPM.cmake-in-CMake) for more details.
|
||||||
|
|
||||||
## Updating CPM
|
## Updating CPM
|
||||||
|
|
||||||
@@ -94,7 +95,7 @@ Dependencies using CPM will automatically use the updated script of the outermos
|
|||||||
|
|
||||||
- **Small and reusable projects** CPM takes care of all project dependencies, allowing developers to focus on creating small, well-tested libraries.
|
- **Small and reusable projects** CPM takes care of all project dependencies, allowing developers to focus on creating small, well-tested libraries.
|
||||||
- **Cross-Platform** CPM adds projects directly at the configure stage and is compatible with all CMake toolchains and generators.
|
- **Cross-Platform** CPM adds projects directly at the configure stage and is compatible with all CMake toolchains and generators.
|
||||||
- **Reproducable builds** By versioning dependencies via git commits or tags it is ensured that a project will always be buildable.
|
- **Reproducible builds** By versioning dependencies via git commits or tags it is ensured that a project will always be buildable.
|
||||||
- **Recursive dependencies** Ensures that no dependency is added twice and all are added in the minimum required version.
|
- **Recursive dependencies** Ensures that no dependency is added twice and all are 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.
|
- **Plug-and-play** No need to install anything. Just add the script to your project and you're good to go.
|
||||||
- **No packaging required** Simply add all external sources as a dependency.
|
- **No packaging required** Simply add all external sources as a dependency.
|
||||||
@@ -102,9 +103,9 @@ Dependencies using CPM will automatically use the updated script of the outermos
|
|||||||
|
|
||||||
## Limitations
|
## Limitations
|
||||||
|
|
||||||
- **No pre-built binaries** For every new build directory, all dependencies are initially downloaded and built from scratch. To avoid extra downloads it is recommend to set the [`CPM_SOURCE_CACHE`](#CPM_SOURCE_CACHE) environmental variable. Using a caching compiler such as [ccahe](https://github.com/TheLartians/Ccache.cmake) can drastically reduce build time.
|
- **No pre-built binaries** For every new build directory, all dependencies are initially downloaded and built from scratch. To avoid extra downloads it is recommend to set the [`CPM_SOURCE_CACHE`](#CPM_SOURCE_CACHE) environmental variable. Using a caching compiler such as [ccache](https://github.com/TheLartians/Ccache.cmake) can drastically reduce build time.
|
||||||
- **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 the snippets [below](#snippets) for examples). For best practices on preparing projects for CPM, see the [wiki](https://github.com/TheLartians/CPM/wiki/Preparing-projects-for-CPM).
|
- **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 the snippets [below](#snippets) for examples). For best practices on preparing projects for CPM, see the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/Preparing-projects-for-CPM.cmake).
|
||||||
- **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 a warning. This can be resolved by adding a new version of the dependency in the outermost project.
|
- **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 a warning. This can be easily resolved by adding a new version of the dependency in the outermost project, or by introducing a [package lock file](#package-lock).
|
||||||
|
|
||||||
For projects with more complex needs and where an extra setup step doesn't matter, it may be worth to check out an external C++ package manager such as [vcpkg](https://github.com/microsoft/vcpkg), [conan](https://conan.io) or [hunter](https://github.com/ruslo/hunter).
|
For projects with more complex needs and where an extra setup step doesn't matter, it may be worth to check out an external C++ package manager such as [vcpkg](https://github.com/microsoft/vcpkg), [conan](https://conan.io) or [hunter](https://github.com/ruslo/hunter).
|
||||||
Dependencies added with `CPMFindPackage` should work with external package managers.
|
Dependencies added with `CPMFindPackage` should work with external package managers.
|
||||||
@@ -136,10 +137,39 @@ CPM can be configured to use `find_package` to search for locally installed depe
|
|||||||
If the option `CPM_LOCAL_PACKAGES_ONLY` is set, CPM will emit an error if the dependency is not found locally.
|
If the option `CPM_LOCAL_PACKAGES_ONLY` is set, CPM will emit an error if the dependency is not found locally.
|
||||||
These options can also be set as environmental variables.
|
These options can also be set as environmental variables.
|
||||||
|
|
||||||
|
## Local package override
|
||||||
|
|
||||||
|
Library developers are often in the situation where they work on a locally checked out dependency at the same time as on a consumer project.
|
||||||
|
It is possible to override the consumer's dependency with the version by supplying the CMake option `CPM_<dependency name>_SOURCE` set to the absolute path of the local library.
|
||||||
|
For example, to use the local version of the dependency `Dep` at the path `/path/to/dep`, the consumer can be built with the following command.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cmake -Bbuild -DCPM_Dep_SOURCE=/path/to/dep
|
||||||
|
```
|
||||||
|
|
||||||
|
## Package lock
|
||||||
|
|
||||||
|
In large projects with many transitive dependencies, it can be useful to introduce a package lock file.
|
||||||
|
This will list all CPM.cmake dependencies and can be used to update dependencies without modifying the original `CMakeLists.txt`.
|
||||||
|
To use a package lock, add the following line directly after including CPM.cmake.
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
CPMUsePackageLock(package-lock.cmake)
|
||||||
|
```
|
||||||
|
|
||||||
|
To create or update the package lock file, build the `cpm-update-package-lock` target.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cmake -Bbuild
|
||||||
|
cmake --build build --target cpm-update-package-lock
|
||||||
|
```
|
||||||
|
|
||||||
|
See the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/Package-lock) for more info.
|
||||||
|
|
||||||
## Snippets
|
## Snippets
|
||||||
|
|
||||||
These examples demonstrate how to include some well-known projects with CPM.
|
These examples demonstrate how to include some well-known projects with CPM.
|
||||||
See the [wiki](https://github.com/TheLartians/CPM/wiki/More-Snippets) for more snippets.
|
See the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/More-Snippets) for more snippets.
|
||||||
|
|
||||||
### [Catch2](https://github.com/catchorg/Catch2)
|
### [Catch2](https://github.com/catchorg/Catch2)
|
||||||
|
|
||||||
@@ -269,4 +299,4 @@ For a full example on using CPM to download and configure lua with sol2 see [her
|
|||||||
|
|
||||||
### Full Examples
|
### Full Examples
|
||||||
|
|
||||||
See the [examples directory](https://github.com/TheLartians/CPM/tree/master/examples) for full examples with source code and check out the [wiki](https://github.com/TheLartians/CPM/wiki/More-Snippets) for many more example snippets.
|
See the [examples directory](https://github.com/TheLartians/CPM.cmake/tree/master/examples) for full examples with source code and check out the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/More-Snippets) for many more example snippets.
|
||||||
|
|||||||
352
cmake/CPM.cmake
352
cmake/CPM.cmake
@@ -1,6 +1,6 @@
|
|||||||
# TheLartians/CPM - A simple Git dependency manager
|
# CPM.cmake - CMake's missing package manager
|
||||||
# =================================================
|
# ===========================================
|
||||||
# See https://github.com/TheLartians/CPM for usage and update instructions.
|
# See https://github.com/TheLartians/CPM.cmake for usage and update instructions.
|
||||||
#
|
#
|
||||||
# MIT License
|
# MIT License
|
||||||
# -----------
|
# -----------
|
||||||
@@ -28,11 +28,11 @@
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||||
|
|
||||||
set(CURRENT_CPM_VERSION 0.16)
|
set(CURRENT_CPM_VERSION 0.27.2-development-version)
|
||||||
|
|
||||||
if(CPM_DIRECTORY)
|
if(CPM_DIRECTORY)
|
||||||
if(NOT ${CPM_DIRECTORY} MATCHES ${CMAKE_CURRENT_LIST_DIR})
|
if(NOT CPM_DIRECTORY STREQUAL CMAKE_CURRENT_LIST_DIR)
|
||||||
if (${CPM_VERSION} VERSION_LESS ${CURRENT_CPM_VERSION})
|
if (CPM_VERSION VERSION_LESS CURRENT_CPM_VERSION)
|
||||||
message(AUTHOR_WARNING "${CPM_INDENT} \
|
message(AUTHOR_WARNING "${CPM_INDENT} \
|
||||||
A dependency is using a more recent CPM version (${CURRENT_CPM_VERSION}) than the current project (${CPM_VERSION}). \
|
A dependency is using a more recent CPM version (${CURRENT_CPM_VERSION}) than the current project (${CPM_VERSION}). \
|
||||||
It is recommended to upgrade CPM to the most recent version. \
|
It is recommended to upgrade CPM to the most recent version. \
|
||||||
@@ -41,14 +41,25 @@ See https://github.com/TheLartians/CPM.cmake for more information."
|
|||||||
endif()
|
endif()
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
get_property(CPM_INITIALIZED GLOBAL "" PROPERTY CPM_INITIALIZED SET)
|
||||||
|
if (CPM_INITIALIZED)
|
||||||
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_property(GLOBAL PROPERTY CPM_INITIALIZED true)
|
||||||
|
|
||||||
option(CPM_USE_LOCAL_PACKAGES "Always try to use `find_package` to get dependencies" $ENV{CPM_USE_LOCAL_PACKAGES})
|
option(CPM_USE_LOCAL_PACKAGES "Always try to use `find_package` to get dependencies" $ENV{CPM_USE_LOCAL_PACKAGES})
|
||||||
option(CPM_LOCAL_PACKAGES_ONLY "Only use `find_package` to get dependencies" $ENV{CPM_LOCAL_PACKAGES_ONLY})
|
option(CPM_LOCAL_PACKAGES_ONLY "Only use `find_package` to get dependencies" $ENV{CPM_LOCAL_PACKAGES_ONLY})
|
||||||
option(CPM_DOWNLOAD_ALL "Always download dependencies from source" $ENV{CPM_DOWNLOAD_ALL})
|
option(CPM_DOWNLOAD_ALL "Always download dependencies from source" $ENV{CPM_DOWNLOAD_ALL})
|
||||||
|
option(CPM_DONT_UPDATE_MODULE_PATH "Don't update the module path to allow using find_package" $ENV{CPM_DONT_UPDATE_MODULE_PATH})
|
||||||
|
option(CPM_DONT_CREATE_PACKAGE_LOCK "Don't create a package lock file in the binary path" $ENV{CPM_DONT_CREATE_PACKAGE_LOCK})
|
||||||
|
option(CPM_INCLUDE_ALL_IN_PACKAGE_LOCK "Add all packages added through CPM.cmake to the package lock" $ENV{CPM_INCLUDE_ALL_IN_PACKAGE_LOCK})
|
||||||
|
|
||||||
set(CPM_VERSION ${CURRENT_CPM_VERSION} CACHE INTERNAL "")
|
set(CPM_VERSION ${CURRENT_CPM_VERSION} CACHE INTERNAL "")
|
||||||
set(CPM_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL "")
|
set(CPM_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL "")
|
||||||
|
set(CPM_FILE ${CMAKE_CURRENT_LIST_FILE} CACHE INTERNAL "")
|
||||||
set(CPM_PACKAGES "" CACHE INTERNAL "")
|
set(CPM_PACKAGES "" CACHE INTERNAL "")
|
||||||
set(CPM_DRY_RUN OFF CACHE INTERNAL "Don't download or configure dependencies (for testing)")
|
set(CPM_DRY_RUN OFF CACHE INTERNAL "Don't download or configure dependencies (for testing)")
|
||||||
|
|
||||||
@@ -60,6 +71,20 @@ endif()
|
|||||||
|
|
||||||
set(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE_DEFAULT} CACHE PATH "Directory to downlaod CPM dependencies")
|
set(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE_DEFAULT} CACHE PATH "Directory to downlaod CPM dependencies")
|
||||||
|
|
||||||
|
if (NOT CPM_DONT_UPDATE_MODULE_PATH)
|
||||||
|
set(CPM_MODULE_PATH "${CMAKE_BINARY_DIR}/CPM_modules" CACHE INTERNAL "")
|
||||||
|
# remove old modules
|
||||||
|
FILE(REMOVE_RECURSE ${CPM_MODULE_PATH})
|
||||||
|
file(MAKE_DIRECTORY ${CPM_MODULE_PATH})
|
||||||
|
# locally added CPM modules should override global packages
|
||||||
|
set(CMAKE_MODULE_PATH "${CPM_MODULE_PATH};${CMAKE_MODULE_PATH}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT CPM_DONT_CREATE_PACKAGE_LOCK)
|
||||||
|
set(CPM_PACKAGE_LOCK_FILE "${CMAKE_BINARY_DIR}/cpm-package-lock.cmake" CACHE INTERNAL "")
|
||||||
|
file(WRITE ${CPM_PACKAGE_LOCK_FILE} "# CPM Package Lock\n# This file should be committed to version control\n\n")
|
||||||
|
endif()
|
||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
include(CMakeParseArguments)
|
include(CMakeParseArguments)
|
||||||
|
|
||||||
@@ -70,16 +95,25 @@ endif()
|
|||||||
|
|
||||||
function(cpm_find_package NAME VERSION)
|
function(cpm_find_package NAME VERSION)
|
||||||
string(REPLACE " " ";" EXTRA_ARGS "${ARGN}")
|
string(REPLACE " " ";" EXTRA_ARGS "${ARGN}")
|
||||||
find_package(${NAME} ${VERSION} ${EXTRA_ARGS})
|
find_package(${NAME} ${VERSION} ${EXTRA_ARGS} QUIET)
|
||||||
if(${CPM_ARGS_NAME}_FOUND)
|
if(${CPM_ARGS_NAME}_FOUND)
|
||||||
message(STATUS "${CPM_INDENT} using local package ${CPM_ARGS_NAME}@${${CPM_ARGS_NAME}_VERSION}")
|
message(STATUS "${CPM_INDENT} using local package ${CPM_ARGS_NAME}@${VERSION}")
|
||||||
CPMRegisterPackage(${CPM_ARGS_NAME} "${${CPM_ARGS_NAME}_VERSION}")
|
CPMRegisterPackage(${CPM_ARGS_NAME} "${VERSION}")
|
||||||
set(CPM_PACKAGE_FOUND YES PARENT_SCOPE)
|
set(CPM_PACKAGE_FOUND YES PARENT_SCOPE)
|
||||||
else()
|
else()
|
||||||
set(CPM_PACKAGE_FOUND NO PARENT_SCOPE)
|
set(CPM_PACKAGE_FOUND NO PARENT_SCOPE)
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
# Create a custom FindXXX.cmake module for a CPM package
|
||||||
|
# This prevents `find_package(NAME)` from finding the system library
|
||||||
|
function(CPMCreateModuleFile Name)
|
||||||
|
if (NOT CPM_DONT_UPDATE_MODULE_PATH)
|
||||||
|
# erase any previous modules
|
||||||
|
FILE(WRITE ${CPM_MODULE_PATH}/Find${Name}.cmake "include(${CPM_FILE})\n${ARGN}\nset(${Name}_FOUND TRUE)")
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# Find a package locally or fallback to CPMAddPackage
|
# Find a package locally or fallback to CPMAddPackage
|
||||||
function(CPMFindPackage)
|
function(CPMFindPackage)
|
||||||
set(oneValueArgs
|
set(oneValueArgs
|
||||||
@@ -90,9 +124,21 @@ function(CPMFindPackage)
|
|||||||
|
|
||||||
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "" ${ARGN})
|
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "" ${ARGN})
|
||||||
|
|
||||||
|
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()
|
||||||
|
endif()
|
||||||
|
|
||||||
if (CPM_DOWNLOAD_ALL)
|
if (CPM_DOWNLOAD_ALL)
|
||||||
CPMAddPackage(${ARGN})
|
CPMAddPackage(${ARGN})
|
||||||
cpm_export_variables()
|
cpm_export_variables(${CPM_ARGS_NAME})
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
CPMCheckIfPackageAlreadyAdded(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" "${CPM_ARGS_OPTIONS}")
|
||||||
|
if (CPM_PACKAGE_ALREADY_ADDED)
|
||||||
|
cpm_export_variables(${CPM_ARGS_NAME})
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -100,36 +146,133 @@ function(CPMFindPackage)
|
|||||||
|
|
||||||
if(NOT CPM_PACKAGE_FOUND)
|
if(NOT CPM_PACKAGE_FOUND)
|
||||||
CPMAddPackage(${ARGN})
|
CPMAddPackage(${ARGN})
|
||||||
cpm_export_variables()
|
cpm_export_variables(${CPM_ARGS_NAME})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
# checks if a package has been added before
|
||||||
|
function(CPMCheckIfPackageAlreadyAdded CPM_ARGS_NAME CPM_ARGS_VERSION CPM_ARGS_OPTIONS)
|
||||||
|
if ("${CPM_ARGS_NAME}" IN_LIST CPM_PACKAGES)
|
||||||
|
CPMGetPackageVersion(${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()
|
||||||
|
if (CPM_ARGS_OPTIONS)
|
||||||
|
foreach(OPTION ${CPM_ARGS_OPTIONS})
|
||||||
|
cpm_parse_option(${OPTION})
|
||||||
|
if(NOT "${${OPTION_KEY}}" STREQUAL "${OPTION_VALUE}")
|
||||||
|
message(WARNING "${CPM_INDENT} ignoring package option for ${CPM_ARGS_NAME}: ${OPTION_KEY} = ${OPTION_VALUE} (${${OPTION_KEY}})")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
cpm_get_fetch_properties(${CPM_ARGS_NAME})
|
||||||
|
SET(${CPM_ARGS_NAME}_ADDED NO)
|
||||||
|
SET(CPM_PACKAGE_ALREADY_ADDED YES PARENT_SCOPE)
|
||||||
|
cpm_export_variables(${CPM_ARGS_NAME})
|
||||||
|
else()
|
||||||
|
SET(CPM_PACKAGE_ALREADY_ADDED NO PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# Download and add a package from source
|
# Download and add a package from source
|
||||||
function(CPMAddPackage)
|
function(CPMAddPackage)
|
||||||
|
|
||||||
set(oneValueArgs
|
set(oneValueArgs
|
||||||
NAME
|
NAME
|
||||||
|
FORCE
|
||||||
VERSION
|
VERSION
|
||||||
GIT_TAG
|
GIT_TAG
|
||||||
DOWNLOAD_ONLY
|
DOWNLOAD_ONLY
|
||||||
GITHUB_REPOSITORY
|
GITHUB_REPOSITORY
|
||||||
GITLAB_REPOSITORY
|
GITLAB_REPOSITORY
|
||||||
|
GIT_REPOSITORY
|
||||||
SOURCE_DIR
|
SOURCE_DIR
|
||||||
DOWNLOAD_COMMAND
|
DOWNLOAD_COMMAND
|
||||||
FIND_PACKAGE_ARGUMENTS
|
FIND_PACKAGE_ARGUMENTS
|
||||||
|
NO_CACHE
|
||||||
|
GIT_SHALLOW
|
||||||
)
|
)
|
||||||
|
|
||||||
set(multiValueArgs
|
set(multiValueArgs
|
||||||
OPTIONS
|
OPTIONS
|
||||||
)
|
)
|
||||||
|
|
||||||
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
|
||||||
|
|
||||||
|
# Set default values for arguments
|
||||||
|
|
||||||
|
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()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CPM_ARGS_DOWNLOAD_ONLY)
|
||||||
|
set(DOWNLOAD_ONLY ${CPM_ARGS_DOWNLOAD_ONLY})
|
||||||
|
else()
|
||||||
|
set(DOWNLOAD_ONLY NO)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (DEFINED CPM_ARGS_GITHUB_REPOSITORY)
|
||||||
|
set(CPM_ARGS_GIT_REPOSITORY "https://github.com/${CPM_ARGS_GITHUB_REPOSITORY}.git")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (DEFINED CPM_ARGS_GITLAB_REPOSITORY)
|
||||||
|
set(CPM_ARGS_GIT_REPOSITORY "https://gitlab.com/${CPM_ARGS_GITLAB_REPOSITORY}.git")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (DEFINED CPM_ARGS_GIT_REPOSITORY)
|
||||||
|
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_REPOSITORY ${CPM_ARGS_GIT_REPOSITORY})
|
||||||
|
if (NOT DEFINED CPM_ARGS_GIT_TAG)
|
||||||
|
set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (DEFINED CPM_ARGS_GIT_TAG)
|
||||||
|
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_TAG ${CPM_ARGS_GIT_TAG})
|
||||||
|
# If GIT_SHALLOW is explicitly specified, honor the value.
|
||||||
|
if (DEFINED CPM_ARGS_GIT_SHALLOW)
|
||||||
|
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_SHALLOW ${CPM_ARGS_GIT_SHALLOW})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Check if package has been added before
|
||||||
|
CPMCheckIfPackageAlreadyAdded(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" "${CPM_ARGS_OPTIONS}")
|
||||||
|
if (CPM_PACKAGE_ALREADY_ADDED)
|
||||||
|
cpm_export_variables(${CPM_ARGS_NAME})
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Check for manual overrides
|
||||||
|
if (NOT CPM_ARGS_FORCE AND NOT "${CPM_${CPM_ARGS_NAME}_SOURCE}" STREQUAL "")
|
||||||
|
set(PACKAGE_SOURCE ${CPM_${CPM_ARGS_NAME}_SOURCE})
|
||||||
|
set(CPM_${CPM_ARGS_NAME}_SOURCE "")
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME ${CPM_ARGS_NAME}
|
||||||
|
SOURCE_DIR ${PACKAGE_SOURCE}
|
||||||
|
FORCE True
|
||||||
|
)
|
||||||
|
cpm_export_variables(${CPM_ARGS_NAME})
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Check for available declaration
|
||||||
|
if (NOT CPM_ARGS_FORCE AND NOT "${CPM_DECLARATION_${CPM_ARGS_NAME}}" STREQUAL "")
|
||||||
|
set(declaration ${CPM_DECLARATION_${CPM_ARGS_NAME}})
|
||||||
|
set(CPM_DECLARATION_${CPM_ARGS_NAME} "")
|
||||||
|
CPMAddPackage(${declaration})
|
||||||
|
cpm_export_variables(${CPM_ARGS_NAME})
|
||||||
|
# checking again to ensure version and option compatibility
|
||||||
|
CPMCheckIfPackageAlreadyAdded(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" "${CPM_ARGS_OPTIONS}")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
if(CPM_USE_LOCAL_PACKAGES OR CPM_LOCAL_PACKAGES_ONLY)
|
if(CPM_USE_LOCAL_PACKAGES OR CPM_LOCAL_PACKAGES_ONLY)
|
||||||
cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS})
|
cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS})
|
||||||
|
|
||||||
if(CPM_PACKAGE_FOUND)
|
if(CPM_PACKAGE_FOUND)
|
||||||
|
cpm_export_variables(${CPM_ARGS_NAME})
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -138,58 +281,7 @@ function(CPMAddPackage)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT DEFINED CPM_ARGS_VERSION)
|
CPMRegisterPackage("${CPM_ARGS_NAME}" "${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 DEFINED CPM_ARGS_GIT_TAG)
|
|
||||||
set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_TAG ${CPM_ARGS_GIT_TAG})
|
|
||||||
|
|
||||||
if(CPM_ARGS_DOWNLOAD_ONLY)
|
|
||||||
set(DOWNLOAD_ONLY ${CPM_ARGS_DOWNLOAD_ONLY})
|
|
||||||
else()
|
|
||||||
set(DOWNLOAD_ONLY NO)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (CPM_ARGS_GITHUB_REPOSITORY)
|
|
||||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_REPOSITORY "https://github.com/${CPM_ARGS_GITHUB_REPOSITORY}.git")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (CPM_ARGS_GITLAB_REPOSITORY)
|
|
||||||
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)
|
|
||||||
CPMGetPackageVersion(${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()
|
|
||||||
if (CPM_ARGS_OPTIONS)
|
|
||||||
foreach(OPTION ${CPM_ARGS_OPTIONS})
|
|
||||||
cpm_parse_option(${OPTION})
|
|
||||||
if(NOT "${${OPTION_KEY}}" STREQUAL ${OPTION_VALUE})
|
|
||||||
message(WARNING "${CPM_INDENT} ignoring package option for ${CPM_ARGS_NAME}: ${OPTION_KEY} = ${OPTION_VALUE} (${${OPTION_KEY}})")
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
cpm_fetch_package(${CPM_ARGS_NAME} ${DOWNLOAD_ONLY})
|
|
||||||
cpm_get_fetch_properties(${CPM_ARGS_NAME})
|
|
||||||
SET(${CPM_ARGS_NAME}_SOURCE_DIR "${${CPM_ARGS_NAME}_SOURCE_DIR}")
|
|
||||||
SET(${CPM_ARGS_NAME}_BINARY_DIR "${${CPM_ARGS_NAME}_BINARY_DIR}")
|
|
||||||
SET(${CPM_ARGS_NAME}_ADDED NO)
|
|
||||||
cpm_export_variables()
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
CPMRegisterPackage(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION})
|
|
||||||
|
|
||||||
if (CPM_ARGS_OPTIONS)
|
if (CPM_ARGS_OPTIONS)
|
||||||
foreach(OPTION ${CPM_ARGS_OPTIONS})
|
foreach(OPTION ${CPM_ARGS_OPTIONS})
|
||||||
@@ -198,51 +290,121 @@ function(CPMAddPackage)
|
|||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(FETCH_CONTENT_DECLARE_EXTRA_OPTS "")
|
|
||||||
|
|
||||||
if (DEFINED CPM_ARGS_GIT_TAG)
|
if (DEFINED CPM_ARGS_GIT_TAG)
|
||||||
set(PACKAGE_INFO "${CPM_ARGS_GIT_TAG}")
|
set(PACKAGE_INFO "${CPM_ARGS_GIT_TAG}")
|
||||||
|
elseif (DEFINED CPM_ARGS_SOURCE_DIR)
|
||||||
|
set(PACKAGE_INFO "${CPM_ARGS_SOURCE_DIR}")
|
||||||
else()
|
else()
|
||||||
set(PACKAGE_INFO "${CPM_ARGS_VERSION}")
|
set(PACKAGE_INFO "${CPM_ARGS_VERSION}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (DEFINED CPM_ARGS_DOWNLOAD_COMMAND)
|
if (DEFINED CPM_ARGS_DOWNLOAD_COMMAND)
|
||||||
set(FETCH_CONTENT_DECLARE_EXTRA_OPTS DOWNLOAD_COMMAND ${CPM_ARGS_DOWNLOAD_COMMAND})
|
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS DOWNLOAD_COMMAND ${CPM_ARGS_DOWNLOAD_COMMAND})
|
||||||
else()
|
elseif (DEFINED CPM_ARGS_SOURCE_DIR)
|
||||||
if (CPM_SOURCE_CACHE AND NOT DEFINED CPM_ARGS_SOURCE_DIR)
|
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${CPM_ARGS_SOURCE_DIR})
|
||||||
|
elseif (CPM_SOURCE_CACHE AND NOT CPM_ARGS_NO_CACHE)
|
||||||
string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
|
string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
|
||||||
set(origin_parameters ${CPM_ARGS_UNPARSED_ARGUMENTS})
|
set(origin_parameters ${CPM_ARGS_UNPARSED_ARGUMENTS})
|
||||||
list(SORT origin_parameters)
|
list(SORT origin_parameters)
|
||||||
string(SHA1 origin_hash "${origin_parameters}")
|
string(SHA1 origin_hash "${origin_parameters}")
|
||||||
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash})
|
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash})
|
||||||
list(APPEND FETCH_CONTENT_DECLARE_EXTRA_OPTS SOURCE_DIR ${download_directory})
|
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${download_directory})
|
||||||
if (EXISTS ${download_directory})
|
if (EXISTS ${download_directory})
|
||||||
list(APPEND FETCH_CONTENT_DECLARE_EXTRA_OPTS DOWNLOAD_COMMAND ":")
|
# disable the download command to allow offline builds
|
||||||
|
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS DOWNLOAD_COMMAND "${CMAKE_COMMAND}")
|
||||||
set(PACKAGE_INFO "${download_directory}")
|
set(PACKAGE_INFO "${download_directory}")
|
||||||
else()
|
else()
|
||||||
|
# Enable shallow clone when GIT_TAG is not a commit hash.
|
||||||
|
# Our guess may not be accurate, but it should guarantee no commit hash get mis-detected.
|
||||||
|
if (NOT DEFINED CPM_ARGS_GIT_SHALLOW)
|
||||||
|
cpm_is_git_tag_commit_hash("${CPM_ARGS_GIT_TAG}" IS_HASH)
|
||||||
|
if (NOT ${IS_HASH})
|
||||||
|
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_SHALLOW TRUE)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
# remove timestamps so CMake will re-download the dependency
|
# remove timestamps so CMake will re-download the dependency
|
||||||
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/_deps/${lower_case_name}-subbuild)
|
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/_deps/${lower_case_name}-subbuild)
|
||||||
set(PACKAGE_INFO "${PACKAGE_INFO} -> ${download_directory}")
|
set(PACKAGE_INFO "${PACKAGE_INFO} -> ${download_directory}")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
CPMCreateModuleFile(${CPM_ARGS_NAME} "CPMAddPackage(${ARGN})")
|
||||||
|
|
||||||
|
if (CPM_PACKAGE_LOCK_ENABLED)
|
||||||
|
if ((CPM_ARGS_VERSION AND NOT CPM_ARGS_SOURCE_DIR) OR CPM_INCLUDE_ALL_IN_PACKAGE_LOCK)
|
||||||
|
cpm_add_to_package_lock(${CPM_ARGS_NAME} "${ARGN}")
|
||||||
|
elseif(CPM_ARGS_SOURCE_DIR)
|
||||||
|
cpm_add_comment_to_package_lock(${CPM_ARGS_NAME} "local directory")
|
||||||
|
else()
|
||||||
|
cpm_add_comment_to_package_lock(${CPM_ARGS_NAME} "${ARGN}")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
cpm_declare_fetch(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION} ${PACKAGE_INFO} "${CPM_ARGS_UNPARSED_ARGUMENTS}" ${FETCH_CONTENT_DECLARE_EXTRA_OPTS})
|
cpm_declare_fetch("${CPM_ARGS_NAME}" "${CPM_ARGS_VERSION}" "${PACKAGE_INFO}" "${CPM_ARGS_UNPARSED_ARGUMENTS}")
|
||||||
cpm_fetch_package(${CPM_ARGS_NAME} ${DOWNLOAD_ONLY})
|
cpm_fetch_package("${CPM_ARGS_NAME}" "${DOWNLOAD_ONLY}")
|
||||||
cpm_get_fetch_properties(${CPM_ARGS_NAME})
|
cpm_get_fetch_properties("${CPM_ARGS_NAME}")
|
||||||
|
|
||||||
SET(${CPM_ARGS_NAME}_ADDED YES)
|
SET(${CPM_ARGS_NAME}_ADDED YES)
|
||||||
cpm_export_variables()
|
cpm_export_variables("${CPM_ARGS_NAME}")
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
# Fetch a previously declared package
|
||||||
|
macro(CPMGetPackage Name)
|
||||||
|
if (DEFINED "CPM_DECLARATION_${Name}")
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME ${Name}
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
message(SEND_ERROR "Cannot retrieve package ${Name}: no declaration available")
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
# export variables available to the caller to the parent scope
|
# export variables available to the caller to the parent scope
|
||||||
# expects ${CPM_ARGS_NAME} to be set
|
# expects ${CPM_ARGS_NAME} to be set
|
||||||
macro(cpm_export_variables)
|
macro(cpm_export_variables name)
|
||||||
SET(${CPM_ARGS_NAME}_SOURCE_DIR "${${CPM_ARGS_NAME}_SOURCE_DIR}" PARENT_SCOPE)
|
SET(${name}_SOURCE_DIR "${${name}_SOURCE_DIR}" PARENT_SCOPE)
|
||||||
SET(${CPM_ARGS_NAME}_BINARY_DIR "${${CPM_ARGS_NAME}_BINARY_DIR}" PARENT_SCOPE)
|
SET(${name}_BINARY_DIR "${${name}_BINARY_DIR}" PARENT_SCOPE)
|
||||||
SET(${CPM_ARGS_NAME}_ADDED "${${CPM_ARGS_NAME}_ADDED}" PARENT_SCOPE)
|
SET(${name}_ADDED "${${name}_ADDED}" PARENT_SCOPE)
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
# declares that a package has been added to CPM
|
# declares a package, so that any call to CPMAddPackage for the
|
||||||
|
# package name will use these arguments instead.
|
||||||
|
# Previous declarations will not be overriden.
|
||||||
|
macro(CPMDeclarePackage Name)
|
||||||
|
if (NOT DEFINED "CPM_DECLARATION_${Name}")
|
||||||
|
set("CPM_DECLARATION_${Name}" "${ARGN}")
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
function(cpm_add_to_package_lock Name)
|
||||||
|
if (NOT CPM_DONT_CREATE_PACKAGE_LOCK)
|
||||||
|
file(APPEND ${CPM_PACKAGE_LOCK_FILE} "# ${Name}\nCPMDeclarePackage(${Name} \"${ARGN}\")\n")
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(cpm_add_comment_to_package_lock Name)
|
||||||
|
if (NOT CPM_DONT_CREATE_PACKAGE_LOCK)
|
||||||
|
file(APPEND ${CPM_PACKAGE_LOCK_FILE} "# ${Name} (unversioned)\n# CPMDeclarePackage(${Name} \"${ARGN}\")\n")
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# includes the package lock file if it exists and creates a target
|
||||||
|
# `cpm-write-package-lock` to update it
|
||||||
|
macro(CPMUsePackageLock file)
|
||||||
|
if (NOT CPM_DONT_CREATE_PACKAGE_LOCK)
|
||||||
|
get_filename_component(CPM_ABSOLUTE_PACKAGE_LOCK_PATH ${file} ABSOLUTE)
|
||||||
|
if(EXISTS ${CPM_ABSOLUTE_PACKAGE_LOCK_PATH})
|
||||||
|
include(${CPM_ABSOLUTE_PACKAGE_LOCK_PATH})
|
||||||
|
endif()
|
||||||
|
if (NOT TARGET cpm-update-package-lock)
|
||||||
|
add_custom_target(cpm-update-package-lock COMMAND ${CMAKE_COMMAND} -E copy ${CPM_PACKAGE_LOCK_FILE} ${CPM_ABSOLUTE_PACKAGE_LOCK_PATH})
|
||||||
|
endif()
|
||||||
|
set(CPM_PACKAGE_LOCK_ENABLED true)
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
# registers a package that has been added to CPM
|
||||||
function(CPMRegisterPackage PACKAGE VERSION)
|
function(CPMRegisterPackage PACKAGE VERSION)
|
||||||
list(APPEND CPM_PACKAGES ${PACKAGE})
|
list(APPEND CPM_PACKAGES ${PACKAGE})
|
||||||
set(CPM_PACKAGES ${CPM_PACKAGES} CACHE INTERNAL "")
|
set(CPM_PACKAGES ${CPM_PACKAGES} CACHE INTERNAL "")
|
||||||
@@ -263,8 +425,7 @@ function (cpm_declare_fetch PACKAGE VERSION INFO)
|
|||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(${PACKAGE}
|
||||||
${PACKAGE}
|
|
||||||
${ARGN}
|
${ARGN}
|
||||||
)
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
@@ -282,22 +443,22 @@ endfunction()
|
|||||||
|
|
||||||
# downloads a previously declared package via FetchContent
|
# downloads a previously declared package via FetchContent
|
||||||
function (cpm_fetch_package PACKAGE DOWNLOAD_ONLY)
|
function (cpm_fetch_package PACKAGE DOWNLOAD_ONLY)
|
||||||
|
|
||||||
if (${CPM_DRY_RUN})
|
if (${CPM_DRY_RUN})
|
||||||
message(STATUS "${CPM_INDENT} package ${PACKAGE} not fetched (dry run)")
|
message(STATUS "${CPM_INDENT} package ${PACKAGE} not fetched (dry run)")
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CPM_OLD_INDENT "${CPM_INDENT}")
|
if(DOWNLOAD_ONLY)
|
||||||
set(CPM_INDENT "${CPM_INDENT} ${PACKAGE}:")
|
FetchContent_GetProperties(${PACKAGE})
|
||||||
if(${DOWNLOAD_ONLY})
|
if(NOT ${PACKAGE}_POPULATED)
|
||||||
if(NOT "${PACKAGE}_POPULATED")
|
|
||||||
FetchContent_Populate(${PACKAGE})
|
FetchContent_Populate(${PACKAGE})
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
|
set(CPM_OLD_INDENT "${CPM_INDENT}")
|
||||||
|
set(CPM_INDENT "${CPM_INDENT} ${PACKAGE}:")
|
||||||
FetchContent_MakeAvailable(${PACKAGE})
|
FetchContent_MakeAvailable(${PACKAGE})
|
||||||
endif()
|
|
||||||
set(CPM_INDENT "${CPM_OLD_INDENT}")
|
set(CPM_INDENT "${CPM_OLD_INDENT}")
|
||||||
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
# splits a package option
|
# splits a package option
|
||||||
@@ -327,3 +488,18 @@ function(cpm_get_version_from_git_tag GIT_TAG RESULT)
|
|||||||
SET(${RESULT} ${CMAKE_MATCH_1} PARENT_SCOPE)
|
SET(${RESULT} ${CMAKE_MATCH_1} PARENT_SCOPE)
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
# guesses if the git tag is a commit hash or an actual tag or a branch nane.
|
||||||
|
function(cpm_is_git_tag_commit_hash GIT_TAG RESULT)
|
||||||
|
string(LENGTH "${GIT_TAG}" length)
|
||||||
|
# full hash has 40 characters, and short hash has at least 7 characters.
|
||||||
|
if (length LESS 7 OR length GREATER 40)
|
||||||
|
SET(${RESULT} 0 PARENT_SCOPE)
|
||||||
|
else()
|
||||||
|
if (${GIT_TAG} MATCHES "^[a-fA-F0-9]+$")
|
||||||
|
SET(${RESULT} 1 PARENT_SCOPE)
|
||||||
|
else()
|
||||||
|
SET(${RESULT} 0 PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|||||||
@@ -20,3 +20,15 @@ endfunction()
|
|||||||
function(ASSERTION_FAILED)
|
function(ASSERTION_FAILED)
|
||||||
message(FATAL_ERROR "assertion failed: ${ARGN}")
|
message(FATAL_ERROR "assertion failed: ${ARGN}")
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(ASSERT_EXISTS file)
|
||||||
|
if (NOT EXISTS ${file})
|
||||||
|
message(FATAL_ERROR "assertion failed: file ${file} does not exist")
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(ASSERT_NOT_EXISTS file)
|
||||||
|
if (EXISTS ${file})
|
||||||
|
message(FATAL_ERROR "assertion failed: file ${file} exists")
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|||||||
79
examples/asio-standalone/CMakeLists.txt
Normal file
79
examples/asio-standalone/CMakeLists.txt
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||||
|
|
||||||
|
project(CPMExampleASIOStandalone)
|
||||||
|
|
||||||
|
# ---- Dependencies ----
|
||||||
|
|
||||||
|
include(../../cmake/CPM.cmake)
|
||||||
|
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME asio
|
||||||
|
VERSION 1.16.1
|
||||||
|
GITHUB_REPOSITORY chriskohlhoff/asio
|
||||||
|
GIT_TAG asio-1-16-1 # asio uses non-standard version tag, we must specify GIT_TAG
|
||||||
|
)
|
||||||
|
|
||||||
|
# ASIO doesn't use CMake, we have to configure it manually.
|
||||||
|
# Extra notes for using on Windows:
|
||||||
|
# 1) If _WIN32_WINNT is not set, ASIO assumes _WIN32_WINNT=0x0501, i.e. Windows XP target,
|
||||||
|
# which is definitely not the platform which most users target.
|
||||||
|
# 2) WIN32_LEAN_AND_MEAN is defined to make Winsock2 work.
|
||||||
|
if(asio_ADDED)
|
||||||
|
add_library(asio INTERFACE)
|
||||||
|
|
||||||
|
target_include_directories(asio
|
||||||
|
INTERFACE ${asio_SOURCE_DIR}/asio/include
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(asio
|
||||||
|
INTERFACE
|
||||||
|
ASIO_STANDALONE
|
||||||
|
ASIO_NO_DEPRECATED
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(asio
|
||||||
|
INTERFACE
|
||||||
|
Threads::Threads
|
||||||
|
)
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
# macro see @ https://stackoverflow.com/a/40217291/1746503
|
||||||
|
macro(get_win32_winnt version)
|
||||||
|
if (CMAKE_SYSTEM_VERSION)
|
||||||
|
set(ver ${CMAKE_SYSTEM_VERSION})
|
||||||
|
string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver})
|
||||||
|
string(REGEX MATCH "^([0-9]+)" verMajor ${ver})
|
||||||
|
# Check for Windows 10, b/c we'll need to convert to hex 'A'.
|
||||||
|
if ("${verMajor}" MATCHES "10")
|
||||||
|
set(verMajor "A")
|
||||||
|
string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver})
|
||||||
|
endif ("${verMajor}" MATCHES "10")
|
||||||
|
# Remove all remaining '.' characters.
|
||||||
|
string(REPLACE "." "" ver ${ver})
|
||||||
|
# Prepend each digit with a zero.
|
||||||
|
string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver})
|
||||||
|
set(${version} "0x${ver}")
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
if(NOT DEFINED _WIN32_WINNT)
|
||||||
|
get_win32_winnt(ver)
|
||||||
|
set(_WIN32_WINNT ${ver})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "Set _WIN32_WINNET=${_WIN32_WINNT}")
|
||||||
|
|
||||||
|
target_compile_definitions(asio
|
||||||
|
INTERFACE
|
||||||
|
_WIN32_WINNT=${_WIN32_WINNT}
|
||||||
|
WIN32_LEAN_AND_MEAN
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# ---- Executable ----
|
||||||
|
|
||||||
|
add_executable(CPMExampleASIOStandalone main.cpp)
|
||||||
|
target_link_libraries(CPMExampleASIOStandalone asio)
|
||||||
118
examples/asio-standalone/main.cpp
Normal file
118
examples/asio-standalone/main.cpp
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
//
|
||||||
|
// async_tcp_echo_server.cpp
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
//
|
||||||
|
// Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// (See http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "asio.hpp"
|
||||||
|
|
||||||
|
// An asynchronous tcp echo server.
|
||||||
|
// See https://think-async.com/Asio/asio-1.16.1/src/examples/cpp11/echo/async_tcp_echo_server.cpp
|
||||||
|
|
||||||
|
using asio::ip::tcp;
|
||||||
|
|
||||||
|
class session
|
||||||
|
: public std::enable_shared_from_this<session>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
session(tcp::socket socket)
|
||||||
|
: socket_(std::move(socket))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void start()
|
||||||
|
{
|
||||||
|
do_read();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void do_read()
|
||||||
|
{
|
||||||
|
auto self(shared_from_this());
|
||||||
|
socket_.async_read_some(asio::buffer(data_, max_length),
|
||||||
|
[this, self](std::error_code ec, std::size_t length)
|
||||||
|
{
|
||||||
|
if (!ec)
|
||||||
|
{
|
||||||
|
do_write(length);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void do_write(std::size_t length)
|
||||||
|
{
|
||||||
|
auto self(shared_from_this());
|
||||||
|
asio::async_write(socket_, asio::buffer(data_, length),
|
||||||
|
[this, self](std::error_code ec, std::size_t /*length*/)
|
||||||
|
{
|
||||||
|
if (!ec)
|
||||||
|
{
|
||||||
|
do_read();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
tcp::socket socket_;
|
||||||
|
enum { max_length = 1024 };
|
||||||
|
char data_[max_length];
|
||||||
|
};
|
||||||
|
|
||||||
|
class server
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
server(asio::io_context& io_context, short port)
|
||||||
|
: acceptor_(io_context, tcp::endpoint(tcp::v4(), port))
|
||||||
|
{
|
||||||
|
do_accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void do_accept()
|
||||||
|
{
|
||||||
|
acceptor_.async_accept(
|
||||||
|
[this](std::error_code ec, tcp::socket socket)
|
||||||
|
{
|
||||||
|
if (!ec)
|
||||||
|
{
|
||||||
|
std::make_shared<session>(std::move(socket))->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
do_accept();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
tcp::acceptor acceptor_;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (argc != 2)
|
||||||
|
{
|
||||||
|
std::cerr << "Usage: async_tcp_echo_server <port>\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
asio::io_context io_context;
|
||||||
|
|
||||||
|
server s(io_context, std::atoi(argv[1]));
|
||||||
|
|
||||||
|
io_context.run();
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << "Exception: " << e.what() << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ include(../../cmake/CPM.cmake)
|
|||||||
|
|
||||||
CPMAddPackage(
|
CPMAddPackage(
|
||||||
NAME fibonacci
|
NAME fibonacci
|
||||||
GIT_REPOSITORY https://github.com/TheLartians/Fibonacci.git
|
GITLAB_REPOSITORY TheLartians/Fibonacci
|
||||||
VERSION 2.0
|
VERSION 2.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
0
examples/build_all.py
Normal file → Executable file
0
examples/build_all.py
Normal file → Executable file
@@ -2,17 +2,13 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
|||||||
|
|
||||||
project(CPMExampleCatch2)
|
project(CPMExampleCatch2)
|
||||||
|
|
||||||
# ---- Options ----
|
|
||||||
|
|
||||||
option(ENABLE_TEST_COVERAGE "Enable test coverage" OFF)
|
|
||||||
|
|
||||||
# ---- Dependencies ----
|
# ---- Dependencies ----
|
||||||
|
|
||||||
include(../../cmake/CPM.cmake)
|
include(../../cmake/CPM.cmake)
|
||||||
|
|
||||||
CPMAddPackage(
|
CPMAddPackage(
|
||||||
NAME fibonacci
|
NAME fibonacci
|
||||||
GIT_REPOSITORY https://github.com/TheLartians/Fibonacci.git
|
GITHUB_REPOSITORY TheLartians/Fibonacci
|
||||||
VERSION 2.0
|
VERSION 2.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,16 +22,9 @@ CPMAddPackage(
|
|||||||
|
|
||||||
add_executable(CPMExampleCatch2 main.cpp)
|
add_executable(CPMExampleCatch2 main.cpp)
|
||||||
target_link_libraries(CPMExampleCatch2 fibonacci Catch2)
|
target_link_libraries(CPMExampleCatch2 fibonacci Catch2)
|
||||||
set_target_properties(CPMExampleCatch2 PROPERTIES CXX_STANDARD 17 COMPILE_FLAGS "-Wall -pedantic -Wextra -Werror")
|
set_target_properties(CPMExampleCatch2 PROPERTIES CXX_STANDARD 17)
|
||||||
|
|
||||||
# ---- Enable testing ----
|
# ---- Enable testing ----
|
||||||
|
|
||||||
ENABLE_TESTING()
|
ENABLE_TESTING()
|
||||||
ADD_TEST(CPMExampleCatch2 CPMExampleCatch2)
|
ADD_TEST(CPMExampleCatch2 CPMExampleCatch2)
|
||||||
|
|
||||||
# ---- Add code coverage ----
|
|
||||||
|
|
||||||
if (${ENABLE_TEST_COVERAGE})
|
|
||||||
set_target_properties(CPMExampleCatch2 PROPERTIES CXX_STANDARD 17 COMPILE_FLAGS "-O0 -g -fprofile-arcs -ftest-coverage --coverage")
|
|
||||||
target_link_options(CPMExampleCatch2 PUBLIC "--coverage")
|
|
||||||
endif()
|
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
|||||||
|
|
||||||
project(CPMExampleCXXOpts)
|
project(CPMExampleCXXOpts)
|
||||||
|
|
||||||
# ---- Options ----
|
|
||||||
|
|
||||||
option(ENABLE_TEST_COVERAGE "Enable test coverage" OFF)
|
|
||||||
|
|
||||||
# ---- Dependencies ----
|
# ---- Dependencies ----
|
||||||
|
|
||||||
include(../../cmake/CPM.cmake)
|
include(../../cmake/CPM.cmake)
|
||||||
@@ -23,4 +19,4 @@ CPMAddPackage(
|
|||||||
|
|
||||||
add_executable(CPMExampleCXXOpts main.cpp)
|
add_executable(CPMExampleCXXOpts main.cpp)
|
||||||
target_link_libraries(CPMExampleCXXOpts cxxopts)
|
target_link_libraries(CPMExampleCXXOpts cxxopts)
|
||||||
set_target_properties(CPMExampleCXXOpts PROPERTIES CXX_STANDARD 17 COMPILE_FLAGS "-Wall -pedantic -Wextra -Werror")
|
set_target_properties(CPMExampleCXXOpts PROPERTIES CXX_STANDARD 17)
|
||||||
|
|||||||
@@ -2,17 +2,13 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
|||||||
|
|
||||||
project(CPMExampleDoctest)
|
project(CPMExampleDoctest)
|
||||||
|
|
||||||
# ---- Options ----
|
|
||||||
|
|
||||||
option(ENABLE_TEST_COVERAGE "Enable test coverage" OFF)
|
|
||||||
|
|
||||||
# ---- Dependencies ----
|
# ---- Dependencies ----
|
||||||
|
|
||||||
include(../../cmake/CPM.cmake)
|
include(../../cmake/CPM.cmake)
|
||||||
|
|
||||||
CPMAddPackage(
|
CPMAddPackage(
|
||||||
NAME fibonacci
|
NAME fibonacci
|
||||||
GIT_REPOSITORY https://github.com/TheLartians/Fibonacci.git
|
GITLAB_REPOSITORY TheLartians/Fibonacci
|
||||||
VERSION 2.0
|
VERSION 2.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,16 +22,9 @@ CPMAddPackage(
|
|||||||
|
|
||||||
add_executable(CPMExampleDoctest main.cpp)
|
add_executable(CPMExampleDoctest main.cpp)
|
||||||
target_link_libraries(CPMExampleDoctest fibonacci doctest)
|
target_link_libraries(CPMExampleDoctest fibonacci doctest)
|
||||||
set_target_properties(CPMExampleDoctest PROPERTIES CXX_STANDARD 17 COMPILE_FLAGS "-Wall -pedantic -Wextra -Werror")
|
set_target_properties(CPMExampleDoctest PROPERTIES CXX_STANDARD 17)
|
||||||
|
|
||||||
# ---- Enable testing ----
|
# ---- Enable testing ----
|
||||||
|
|
||||||
ENABLE_TESTING()
|
ENABLE_TESTING()
|
||||||
ADD_TEST(CPMExampleDoctest CPMExampleDoctest)
|
ADD_TEST(CPMExampleDoctest CPMExampleDoctest)
|
||||||
|
|
||||||
# ---- Add code coverage ----
|
|
||||||
|
|
||||||
if (${ENABLE_TEST_COVERAGE})
|
|
||||||
set_target_properties(CPMExampleDoctest PROPERTIES CXX_STANDARD 17 COMPILE_FLAGS "-O0 -g -fprofile-arcs -ftest-coverage --coverage")
|
|
||||||
target_link_options(CPMExampleDoctest PUBLIC "--coverage")
|
|
||||||
endif()
|
|
||||||
|
|||||||
19
examples/fmt/CMakeLists.txt
Normal file
19
examples/fmt/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||||
|
|
||||||
|
project(CPMJSONExample)
|
||||||
|
|
||||||
|
# ---- Dependencies ----
|
||||||
|
|
||||||
|
include(../../cmake/CPM.cmake)
|
||||||
|
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME fmt
|
||||||
|
GIT_TAG 6.1.2
|
||||||
|
GITHUB_REPOSITORY fmtlib/fmt
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- Executable ----
|
||||||
|
|
||||||
|
add_executable(CPMFmtExample "main.cpp")
|
||||||
|
set_target_properties(CPMFmtExample PROPERTIES CXX_STANDARD 17)
|
||||||
|
target_link_libraries(CPMFmtExample fmt)
|
||||||
6
examples/fmt/main.cpp
Normal file
6
examples/fmt/main.cpp
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
fmt::print("Hello, {}!\n", "world");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -2,17 +2,13 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
|||||||
|
|
||||||
project(CPMExampleGtest)
|
project(CPMExampleGtest)
|
||||||
|
|
||||||
# ---- Options ----
|
|
||||||
|
|
||||||
option(ENABLE_TEST_COVERAGE "Enable test coverage" OFF)
|
|
||||||
|
|
||||||
# ---- Dependencies ----
|
# ---- Dependencies ----
|
||||||
|
|
||||||
include(../../cmake/CPM.cmake)
|
include(../../cmake/CPM.cmake)
|
||||||
|
|
||||||
CPMAddPackage(
|
CPMAddPackage(
|
||||||
NAME fibonacci
|
NAME fibonacci
|
||||||
GIT_REPOSITORY https://github.com/TheLartians/Fibonacci.git
|
GITLAB_REPOSITORY TheLartians/Fibonacci
|
||||||
VERSION 2.0
|
VERSION 2.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -36,10 +32,3 @@ set_target_properties(CPMExampleGtest PROPERTIES CXX_STANDARD 17)
|
|||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
add_test(CPMExampleGtest CPMExampleGtest)
|
add_test(CPMExampleGtest CPMExampleGtest)
|
||||||
|
|
||||||
# ---- Add code coverage ----
|
|
||||||
|
|
||||||
if (${ENABLE_TEST_COVERAGE})
|
|
||||||
set_target_properties(CPMExampleGtest PROPERTIES CXX_STANDARD 17 COMPILE_FLAGS "-O0 -g -fprofile-arcs -ftest-coverage --coverage")
|
|
||||||
target_link_options(CPMExampleGtest PUBLIC "--coverage")
|
|
||||||
endif()
|
|
||||||
|
|||||||
@@ -3,22 +3,19 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
|||||||
include(${CPM_PATH}/testing.cmake)
|
include(${CPM_PATH}/testing.cmake)
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
|
|
||||||
set(CPM_SOURCE_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/CPM")
|
set(CPM_SOURCE_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/CPM")
|
||||||
set(TEST_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/cache)
|
set(TEST_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/remote_dependency)
|
||||||
|
|
||||||
function(clear_cache)
|
function(clear_cache)
|
||||||
|
message(STATUS "clearing CPM cache")
|
||||||
FILE(REMOVE_RECURSE ${CPM_SOURCE_CACHE_DIR})
|
FILE(REMOVE_RECURSE ${CPM_SOURCE_CACHE_DIR})
|
||||||
|
ASSERT_NOT_EXISTS("${CPM_SOURCE_CACHE_DIR}")
|
||||||
if (EXISTS "${CPM_SOURCE_CACHE_DIR}")
|
|
||||||
ASSERTION_FAILED("cache not cleared")
|
|
||||||
endif()
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(update_cmake_lists)
|
function(update_cmake_lists)
|
||||||
configure_package_config_file(
|
configure_package_config_file(
|
||||||
"${CMAKE_CURRENT_LIST_DIR}/cache/CMakeLists.txt.in"
|
"${CMAKE_CURRENT_LIST_DIR}/remote_dependency/CMakeLists.txt.in"
|
||||||
"${CMAKE_CURRENT_LIST_DIR}/cache/CMakeLists.txt"
|
"${CMAKE_CURRENT_LIST_DIR}/remote_dependency/CMakeLists.txt"
|
||||||
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/junk
|
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/junk
|
||||||
)
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
@@ -37,15 +34,12 @@ reset_test()
|
|||||||
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND
|
COMMAND
|
||||||
${CMAKE_COMMAND} "-H${CMAKE_CURRENT_LIST_DIR}/cache" "-B${TEST_BUILD_DIR}" "-DCPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}"
|
${CMAKE_COMMAND} "-H${CMAKE_CURRENT_LIST_DIR}/remote_dependency" "-B${TEST_BUILD_DIR}" "-DCPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}"
|
||||||
RESULT_VARIABLE ret
|
RESULT_VARIABLE ret
|
||||||
)
|
)
|
||||||
|
|
||||||
ASSERT_EQUAL(${ret} "0")
|
ASSERT_EQUAL(${ret} "0")
|
||||||
|
ASSERT_EXISTS("${CPM_SOURCE_CACHE_DIR}/fibonacci")
|
||||||
if (NOT EXISTS "${CPM_SOURCE_CACHE_DIR}/fibonacci")
|
|
||||||
ASSERTION_FAILED("fibonacci not in cache")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
FILE(GLOB FIBONACCI_VERSIONs "${CPM_SOURCE_CACHE_DIR}/fibonacci/*")
|
FILE(GLOB FIBONACCI_VERSIONs "${CPM_SOURCE_CACHE_DIR}/fibonacci/*")
|
||||||
list(LENGTH FIBONACCI_VERSIONs FIBONACCI_VERSION_count)
|
list(LENGTH FIBONACCI_VERSIONs FIBONACCI_VERSION_count)
|
||||||
@@ -83,10 +77,7 @@ execute_process(
|
|||||||
)
|
)
|
||||||
|
|
||||||
ASSERT_EQUAL(${ret} "0")
|
ASSERT_EQUAL(${ret} "0")
|
||||||
|
ASSERT_EXISTS("${CPM_SOURCE_CACHE_DIR}/fibonacci")
|
||||||
if (NOT EXISTS "${CPM_SOURCE_CACHE_DIR}/fibonacci")
|
|
||||||
ASSERTION_FAILED("fibonacci not in cache")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
## Read CPM_SOURCE_CACHE from environment
|
## Read CPM_SOURCE_CACHE from environment
|
||||||
|
|
||||||
@@ -94,15 +85,22 @@ reset_test()
|
|||||||
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND
|
COMMAND
|
||||||
${CMAKE_COMMAND} -E env "CPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}" ${CMAKE_COMMAND} "-H${CMAKE_CURRENT_LIST_DIR}/cache" "-B${TEST_BUILD_DIR}"
|
${CMAKE_COMMAND} -E env "CPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}" ${CMAKE_COMMAND} "-H${CMAKE_CURRENT_LIST_DIR}/remote_dependency" "-B${TEST_BUILD_DIR}"
|
||||||
RESULT_VARIABLE ret
|
RESULT_VARIABLE ret
|
||||||
)
|
)
|
||||||
|
|
||||||
ASSERT_EQUAL(${ret} "0")
|
ASSERT_EQUAL(${ret} "0")
|
||||||
|
ASSERT_EXISTS("${CPM_SOURCE_CACHE_DIR}/fibonacci")
|
||||||
|
|
||||||
if (NOT EXISTS "${CPM_SOURCE_CACHE_DIR}/fibonacci")
|
## Reuse cached packages for other build
|
||||||
ASSERTION_FAILED("fibonacci not in cache")
|
|
||||||
endif()
|
execute_process(
|
||||||
|
COMMAND
|
||||||
|
${CMAKE_COMMAND} -E env "CPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}" ${CMAKE_COMMAND} "-H${CMAKE_CURRENT_LIST_DIR}/remote_dependency" "-B${TEST_BUILD_DIR}-2"
|
||||||
|
RESULT_VARIABLE ret
|
||||||
|
)
|
||||||
|
|
||||||
|
ASSERT_EQUAL(${ret} "0")
|
||||||
|
|
||||||
## Overwrite CPM_SOURCE_CACHE with argument
|
## Overwrite CPM_SOURCE_CACHE with argument
|
||||||
|
|
||||||
@@ -110,12 +108,40 @@ reset_test()
|
|||||||
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND
|
COMMAND
|
||||||
${CMAKE_COMMAND} -E env "CPM_SOURCE_CACHE=${CMAKE_CURRENT_BINARY_DIR}/junk" ${CMAKE_COMMAND} "-H${CMAKE_CURRENT_LIST_DIR}/cache" "-B${TEST_BUILD_DIR}" "-DCPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}"
|
${CMAKE_COMMAND} -E env "CPM_SOURCE_CACHE=${CMAKE_CURRENT_BINARY_DIR}/junk" ${CMAKE_COMMAND} "-H${CMAKE_CURRENT_LIST_DIR}/remote_dependency" "-B${TEST_BUILD_DIR}" "-DCPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}"
|
||||||
RESULT_VARIABLE ret
|
RESULT_VARIABLE ret
|
||||||
)
|
)
|
||||||
|
|
||||||
ASSERT_EQUAL(${ret} "0")
|
ASSERT_EQUAL(${ret} "0")
|
||||||
|
ASSERT_EXISTS("${CPM_SOURCE_CACHE_DIR}/fibonacci")
|
||||||
|
|
||||||
if (NOT EXISTS "${CPM_SOURCE_CACHE_DIR}/fibonacci")
|
## Use NO_CACHE option
|
||||||
ASSERTION_FAILED("fibonacci not in cache")
|
|
||||||
endif()
|
set(FIBONACCI_PACKAGE_ARGS "NO_CACHE YES")
|
||||||
|
set(FIBONACCI_VERSION 1.0)
|
||||||
|
update_cmake_lists()
|
||||||
|
reset_test()
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND
|
||||||
|
${CMAKE_COMMAND} -E env "CPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}" ${CMAKE_COMMAND} "-H${CMAKE_CURRENT_LIST_DIR}/remote_dependency" "-B${TEST_BUILD_DIR}"
|
||||||
|
RESULT_VARIABLE ret
|
||||||
|
)
|
||||||
|
|
||||||
|
ASSERT_EQUAL(${ret} "0")
|
||||||
|
ASSERT_NOT_EXISTS("${CPM_SOURCE_CACHE_DIR}/fibonacci")
|
||||||
|
|
||||||
|
## Use commit hash after version
|
||||||
|
|
||||||
|
set(FIBONACCI_PACKAGE_ARGS "NO_CACHE YES GIT_TAG e9ebf168ca0fffaa4ef8c6fefc6346aaa22f6ed5")
|
||||||
|
set(FIBONACCI_VERSION 1.1)
|
||||||
|
update_cmake_lists()
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND
|
||||||
|
${CMAKE_COMMAND} -E env "CPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}" ${CMAKE_COMMAND} "-H${CMAKE_CURRENT_LIST_DIR}/remote_dependency" "-B${TEST_BUILD_DIR}"
|
||||||
|
RESULT_VARIABLE ret
|
||||||
|
)
|
||||||
|
|
||||||
|
ASSERT_EQUAL(${ret} "0")
|
||||||
|
ASSERT_NOT_EXISTS("${CPM_SOURCE_CACHE_DIR}/fibonacci")
|
||||||
|
|||||||
22
test/unit/is_git_tag_commit_hash.cmake
Normal file
22
test/unit/is_git_tag_commit_hash.cmake
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||||
|
|
||||||
|
include(${CPM_PATH}/CPM.cmake)
|
||||||
|
include(${CPM_PATH}/testing.cmake)
|
||||||
|
|
||||||
|
CPM_IS_GIT_TAG_COMMIT_HASH("v1.2.3" RESULT)
|
||||||
|
ASSERT_EQUAL("0" ${RESULT})
|
||||||
|
|
||||||
|
CPM_IS_GIT_TAG_COMMIT_HASH("asio-1-12-1" RESULT)
|
||||||
|
ASSERT_EQUAL("0" ${RESULT})
|
||||||
|
|
||||||
|
CPM_IS_GIT_TAG_COMMIT_HASH("513039e3cba83284cec71287fd829865b9f423bc" RESULT)
|
||||||
|
ASSERT_EQUAL("1" ${RESULT})
|
||||||
|
|
||||||
|
CPM_IS_GIT_TAG_COMMIT_HASH("513039E3CBA83284CEC71287FD829865B9F423BC" RESULT)
|
||||||
|
ASSERT_EQUAL("1" ${RESULT})
|
||||||
|
|
||||||
|
CPM_IS_GIT_TAG_COMMIT_HASH("513039E" RESULT)
|
||||||
|
ASSERT_EQUAL("1" ${RESULT})
|
||||||
|
|
||||||
|
CPM_IS_GIT_TAG_COMMIT_HASH("513039E3CBA8" RESULT)
|
||||||
|
ASSERT_EQUAL("1" ${RESULT})
|
||||||
2
test/unit/local_dependency/.gitignore
vendored
Normal file
2
test/unit/local_dependency/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/CMakeLists.txt
|
||||||
|
/package-lock.cmake
|
||||||
26
test/unit/local_dependency/ModuleCMakeLists.txt.in
Normal file
26
test/unit/local_dependency/ModuleCMakeLists.txt.in
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||||
|
|
||||||
|
project(CPMTest)
|
||||||
|
|
||||||
|
# ---- Options ----
|
||||||
|
|
||||||
|
option(ENABLE_TEST_COVERAGE "Enable test coverage" OFF)
|
||||||
|
|
||||||
|
# ---- Dependencies ----
|
||||||
|
|
||||||
|
include(@CPM_PATH@/CPM.cmake)
|
||||||
|
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME @TEST_DEPENDENCY_NAME@
|
||||||
|
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/dependency
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- check if generated modules override find_package ----
|
||||||
|
|
||||||
|
if (@test_check_find_package@)
|
||||||
|
find_package(@TEST_DEPENDENCY_NAME@ REQUIRED)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# ---- Call dependency method to validate correct addition of directory ----
|
||||||
|
|
||||||
|
dependency_function()
|
||||||
19
test/unit/local_dependency/OverrideCMakeLists.txt.in
Normal file
19
test/unit/local_dependency/OverrideCMakeLists.txt.in
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||||
|
|
||||||
|
project(CPMTest)
|
||||||
|
|
||||||
|
# ---- Options ----
|
||||||
|
|
||||||
|
option(ENABLE_TEST_COVERAGE "Enable test coverage" OFF)
|
||||||
|
|
||||||
|
# ---- Dependencies ----
|
||||||
|
|
||||||
|
include(@CPM_PATH@/CPM.cmake)
|
||||||
|
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME Dependency
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- Call dependency method to validate correct addition of directory ----
|
||||||
|
|
||||||
|
dependency_function()
|
||||||
20
test/unit/local_dependency/PackageLockCMakeLists.txt.in
Normal file
20
test/unit/local_dependency/PackageLockCMakeLists.txt.in
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||||
|
|
||||||
|
project(CPMTest)
|
||||||
|
|
||||||
|
# ---- Options ----
|
||||||
|
|
||||||
|
option(ENABLE_TEST_COVERAGE "Enable test coverage" OFF)
|
||||||
|
|
||||||
|
# ---- Dependencies ----
|
||||||
|
|
||||||
|
include(@CPM_PATH@/CPM.cmake)
|
||||||
|
CPMUsePackageLock(package-lock.cmake)
|
||||||
|
|
||||||
|
@PREPARE_CODE@
|
||||||
|
|
||||||
|
CPMGetPackage(Dependency)
|
||||||
|
|
||||||
|
# ---- Call dependency method to validate correct addition of directory ----
|
||||||
|
|
||||||
|
dependency_function()
|
||||||
4
test/unit/local_dependency/dependency/CMakeLists.txt
Normal file
4
test/unit/local_dependency/dependency/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
function(dependency_function)
|
||||||
|
message("called external method")
|
||||||
|
endfunction()
|
||||||
30
test/unit/modules.cmake
Normal file
30
test/unit/modules.cmake
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
include(${CPM_PATH}/testing.cmake)
|
||||||
|
|
||||||
|
set(TEST_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/modules)
|
||||||
|
|
||||||
|
function(initProjectWithDependency TEST_DEPENDENCY_NAME)
|
||||||
|
configure_package_config_file(
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/local_dependency/ModuleCMakeLists.txt.in"
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/local_dependency/CMakeLists.txt"
|
||||||
|
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/junk
|
||||||
|
)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND
|
||||||
|
${CMAKE_COMMAND} "-H${CMAKE_CURRENT_LIST_DIR}/local_dependency" "-B${TEST_BUILD_DIR}"
|
||||||
|
RESULT_VARIABLE ret
|
||||||
|
)
|
||||||
|
|
||||||
|
ASSERT_EQUAL(${ret} "0")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
initProjectWithDependency(A)
|
||||||
|
ASSERT_EXISTS(${TEST_BUILD_DIR}/CPM_modules)
|
||||||
|
ASSERT_EXISTS(${TEST_BUILD_DIR}/CPM_modules/FindA.cmake)
|
||||||
|
ASSERT_NOT_EXISTS(${TEST_BUILD_DIR}/CPM_modules/FindB.cmake)
|
||||||
|
|
||||||
|
initProjectWithDependency(B)
|
||||||
|
ASSERT_NOT_EXISTS(${TEST_BUILD_DIR}/CPM_modules/FindA.cmake)
|
||||||
|
ASSERT_EXISTS(${TEST_BUILD_DIR}/CPM_modules/FindB.cmake)
|
||||||
49
test/unit/package-lock.cmake
Normal file
49
test/unit/package-lock.cmake
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
include(${CPM_PATH}/testing.cmake)
|
||||||
|
|
||||||
|
set(TEST_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/package-lock)
|
||||||
|
|
||||||
|
function(configureWithDeclare DECLARE_DEPENDENCY)
|
||||||
|
execute_process(COMMAND ${CMAKE_COMMAND} -E rm -rf ${TEST_BUILD_DIR})
|
||||||
|
|
||||||
|
if (DECLARE_DEPENDENCY)
|
||||||
|
set(PREPARE_CODE "CPMDeclarePackage(Dependency
|
||||||
|
NAME Dependency
|
||||||
|
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/local_dependency/dependency
|
||||||
|
)")
|
||||||
|
else()
|
||||||
|
set(PREPARE_CODE "")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
configure_package_config_file(
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/local_dependency/PackageLockCMakeLists.txt.in"
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/local_dependency/CMakeLists.txt"
|
||||||
|
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/junk
|
||||||
|
)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${CMAKE_COMMAND} -H${CMAKE_CURRENT_LIST_DIR}/local_dependency -B${TEST_BUILD_DIR} -DCPM_INCLUDE_ALL_IN_PACKAGE_LOCK=1
|
||||||
|
RESULT_VARIABLE ret
|
||||||
|
)
|
||||||
|
|
||||||
|
ASSERT_EQUAL(${ret} "0")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(updatePackageLock)
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${CMAKE_COMMAND} --build ${TEST_BUILD_DIR} --target cpm-update-package-lock
|
||||||
|
RESULT_VARIABLE ret
|
||||||
|
)
|
||||||
|
|
||||||
|
ASSERT_EQUAL(${ret} "0")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
execute_process(COMMAND ${CMAKE_COMMAND} -E rm -f ${CMAKE_CURRENT_LIST_DIR}/local_dependency/package-lock.cmake)
|
||||||
|
configureWithDeclare(YES)
|
||||||
|
ASSERT_NOT_EXISTS(${CMAKE_CURRENT_LIST_DIR}/local_dependency/package-lock.cmake)
|
||||||
|
updatePackageLock()
|
||||||
|
ASSERT_EXISTS(${CMAKE_CURRENT_LIST_DIR}/local_dependency/package-lock.cmake)
|
||||||
|
configureWithDeclare(NO)
|
||||||
|
execute_process(COMMAND ${CMAKE_COMMAND} -E rm -f ${CMAKE_CURRENT_LIST_DIR}/local_dependency/package-lock.cmake)
|
||||||
|
|
||||||
20
test/unit/package-override.cmake
Normal file
20
test/unit/package-override.cmake
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
include(${CPM_PATH}/testing.cmake)
|
||||||
|
|
||||||
|
set(TEST_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/project-override)
|
||||||
|
|
||||||
|
execute_process(COMMAND ${CMAKE_COMMAND} -E rm -rf ${TEST_BUILD_DIR})
|
||||||
|
|
||||||
|
configure_package_config_file(
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/local_dependency/OverrideCMakeLists.txt.in"
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/local_dependency/CMakeLists.txt"
|
||||||
|
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/junk
|
||||||
|
)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${CMAKE_COMMAND} -H${CMAKE_CURRENT_LIST_DIR}/local_dependency -B${TEST_BUILD_DIR} -DCPM_Dependency_SOURCE=${CMAKE_CURRENT_LIST_DIR}/local_dependency/dependency
|
||||||
|
RESULT_VARIABLE ret
|
||||||
|
)
|
||||||
|
|
||||||
|
ASSERT_EQUAL(${ret} "0")
|
||||||
@@ -14,6 +14,7 @@ CPMAddPackage(
|
|||||||
NAME fibonacci
|
NAME fibonacci
|
||||||
GIT_REPOSITORY https://github.com/TheLartians/Fibonacci.git
|
GIT_REPOSITORY https://github.com/TheLartians/Fibonacci.git
|
||||||
VERSION @FIBONACCI_VERSION@
|
VERSION @FIBONACCI_VERSION@
|
||||||
|
@FIBONACCI_PACKAGE_ARGS@
|
||||||
)
|
)
|
||||||
|
|
||||||
# ---- Create binary ----
|
# ---- Create binary ----
|
||||||
21
test/unit/source_dir.cmake
Normal file
21
test/unit/source_dir.cmake
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
include(${CPM_PATH}/testing.cmake)
|
||||||
|
|
||||||
|
set(TEST_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/source_dir)
|
||||||
|
|
||||||
|
set(TEST_DEPENDENCY_NAME Dependency)
|
||||||
|
|
||||||
|
configure_package_config_file(
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/local_dependency/ModuleCMakeLists.txt.in"
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/local_dependency/CMakeLists.txt"
|
||||||
|
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/junk
|
||||||
|
)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND
|
||||||
|
${CMAKE_COMMAND} "-H${CMAKE_CURRENT_LIST_DIR}/local_dependency" "-B${TEST_BUILD_DIR}"
|
||||||
|
RESULT_VARIABLE ret
|
||||||
|
)
|
||||||
|
|
||||||
|
ASSERT_EQUAL(${ret} "0")
|
||||||
Reference in New Issue
Block a user