mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-18 07:07:47 -05:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63d0de7114 | ||
|
|
65c760a840 | ||
|
|
b5e60e72e8 | ||
|
|
10bf25a811 | ||
|
|
18b6cbf233 | ||
|
|
698741ff7c | ||
|
|
1f09de0d9b | ||
|
|
b224ce280d | ||
|
|
49af958fb4 | ||
|
|
90c763532a | ||
|
|
4605d32f0e | ||
|
|
ede60451a9 | ||
|
|
5961f9f9fb | ||
|
|
69e9ff3766 | ||
|
|
3fee69c894 |
39
README.md
39
README.md
@@ -131,6 +131,9 @@ Dependencies using CPM will automatically use the updated script of the outermos
|
||||
- **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/cpm-cmake/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 easily resolved by adding a new version of the dependency in the outermost project, or by introducing a [package lock file](#package-lock).
|
||||
- **Some CMake policies set to `NEW`** Including CPM.cmake will lead to several CMake policies being set to `NEW`. Users which need the old behavior will need to manually modify their CMake code to ensure they're set to `OLD` at the appropriate places. The policies are:
|
||||
- [CMP0077](https://cmake.org/cmake/help/latest/policy/CMP0077.html) and [CMP0126](https://cmake.org/cmake/help/latest/policy/CMP0126.html). They make setting package options from `CMPAddPackage` possible.
|
||||
- [CMP0135](https://cmake.org/cmake/help/latest/policy/CMP0135.html) It allows for proper package rebuilds of packages which are archives, source cache is not used, and the package URL is changed to an older version.
|
||||
|
||||
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.
|
||||
@@ -227,6 +230,22 @@ cmake --build build --target cpm-update-package-lock
|
||||
|
||||
See the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/Package-lock) for more info.
|
||||
|
||||
## Private repositories and CI
|
||||
|
||||
When using CPM.cmake with private repositories, there may be a need to provide an [access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) to be able to clone other projects. Instead of providing the token in CMake, we recommend to provide the regular URL and use [git-config](https://git-scm.com/docs/git-config) to rewrite the URLs to include the token.
|
||||
|
||||
As an example, you could include one of the following in your CI script.
|
||||
|
||||
```bash
|
||||
# Github
|
||||
git config --global url."https://${USERNAME}:${TOKEN}@github.com".insteadOf "https://github.com"
|
||||
```
|
||||
|
||||
```bash
|
||||
# GitLab
|
||||
git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com".insteadOf "https://gitlab.com"
|
||||
```
|
||||
|
||||
## Built with CPM.cmake
|
||||
|
||||
Some amazing projects that are built using the CPM.cmake package manager.
|
||||
@@ -258,6 +277,8 @@ If you know others, feel free to add them here through a PR.
|
||||
<p align="center"><b>ModernCppStarter</b></p>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="https://git.io/liblava">
|
||||
<p align="center">
|
||||
@@ -266,6 +287,22 @@ If you know others, feel free to add them here through a PR.
|
||||
<p align="center"><b>liblava - Modern Vulkan library</b></p>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="https://github.com/variar/klogg">
|
||||
<p align="center">
|
||||
<img src="https://github.com/variar/klogg/blob/master/src/app/images/hicolor/scalable/klogg.svg" alt="klogg" width="100pt" />
|
||||
</p>
|
||||
<p align="center"><b>klogg - fast advanced log explorer</b></p>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="https://github.com/MethanePowered/MethaneKit">
|
||||
<p align="center">
|
||||
<img src="https://github.com/MethanePowered/MethaneKit/raw/master/Docs/Images/Logo/MethaneLogoSmall.png" alt="MethaneKit" width="100pt" />
|
||||
</p>
|
||||
<p align="center"><b>Methane Kit - modern 3D graphics rendering framework</b></p>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -283,7 +320,7 @@ CPMAddPackage("gh:catchorg/Catch2@2.5.0")
|
||||
### [Range-v3](https://github.com/ericniebler/range-v3)
|
||||
|
||||
```Cmake
|
||||
CPMAddPackage("gh:ericniebler/range-v3#0.11.0")
|
||||
CPMAddPackage("gh:ericniebler/range-v3#0.12.0")
|
||||
```
|
||||
|
||||
### [Yaml-cpp](https://github.com/jbeder/yaml-cpp)
|
||||
|
||||
@@ -30,8 +30,9 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
set(CURRENT_CPM_VERSION 1.0.0-development-version)
|
||||
|
||||
get_filename_component(CPM_CURRENT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
|
||||
if(CPM_DIRECTORY)
|
||||
if(NOT CPM_DIRECTORY STREQUAL CMAKE_CURRENT_LIST_DIR)
|
||||
if(NOT CPM_DIRECTORY STREQUAL CPM_CURRENT_DIRECTORY)
|
||||
if(CPM_VERSION VERSION_LESS CURRENT_CPM_VERSION)
|
||||
message(
|
||||
AUTHOR_WARNING
|
||||
@@ -66,6 +67,26 @@ endif()
|
||||
|
||||
set_property(GLOBAL PROPERTY CPM_INITIALIZED true)
|
||||
|
||||
macro(cpm_set_policies)
|
||||
# the policy allows us to change options without caching
|
||||
cmake_policy(SET CMP0077 NEW)
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
|
||||
|
||||
# the policy allows us to change set(CACHE) without caching
|
||||
if(POLICY CMP0126)
|
||||
cmake_policy(SET CMP0126 NEW)
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0126 NEW)
|
||||
endif()
|
||||
|
||||
# The policy uses the download time for timestamp, instead of the timestamp in the archive. This
|
||||
# allows for proper rebuilds when a projects url changes
|
||||
if(POLICY CMP0135)
|
||||
cmake_policy(SET CMP0135 NEW)
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0135 NEW)
|
||||
endif()
|
||||
endmacro()
|
||||
cpm_set_policies()
|
||||
|
||||
option(CPM_USE_LOCAL_PACKAGES "Always try to use `find_package` to get dependencies"
|
||||
$ENV{CPM_USE_LOCAL_PACKAGES}
|
||||
)
|
||||
@@ -93,7 +114,7 @@ set(CPM_VERSION
|
||||
CACHE INTERNAL ""
|
||||
)
|
||||
set(CPM_DIRECTORY
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CPM_CURRENT_DIRECTORY}
|
||||
CACHE INTERNAL ""
|
||||
)
|
||||
set(CPM_FILE
|
||||
@@ -214,6 +235,9 @@ function(cpm_find_package NAME VERSION)
|
||||
string(REPLACE " " ";" EXTRA_ARGS "${ARGN}")
|
||||
find_package(${NAME} ${VERSION} ${EXTRA_ARGS} QUIET)
|
||||
if(${CPM_ARGS_NAME}_FOUND)
|
||||
if(DEFINED ${CPM_ARGS_NAME}_VERSION)
|
||||
set(VERSION ${${CPM_ARGS_NAME}_VERSION})
|
||||
endif()
|
||||
message(STATUS "${CPM_INDENT} using local package ${CPM_ARGS_NAME}@${VERSION}")
|
||||
CPMRegisterPackage(${CPM_ARGS_NAME} "${VERSION}")
|
||||
set(CPM_PACKAGE_FOUND
|
||||
@@ -476,6 +500,8 @@ endfunction()
|
||||
|
||||
# Download and add a package from source
|
||||
function(CPMAddPackage)
|
||||
cpm_set_policies()
|
||||
|
||||
list(LENGTH ARGN argnLength)
|
||||
if(argnLength EQUAL 1)
|
||||
cpm_parse_add_package_single_arg("${ARGN}" ARGN)
|
||||
@@ -650,6 +676,20 @@ function(CPMAddPackage)
|
||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS DOWNLOAD_COMMAND ${CPM_ARGS_DOWNLOAD_COMMAND})
|
||||
elseif(DEFINED CPM_ARGS_SOURCE_DIR)
|
||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${CPM_ARGS_SOURCE_DIR})
|
||||
if(NOT IS_ABSOLUTE ${CPM_ARGS_SOURCE_DIR})
|
||||
# Expand `CPM_ARGS_SOURCE_DIR` relative path. This is important because EXISTS doesn't work
|
||||
# for relative paths.
|
||||
get_filename_component(
|
||||
source_directory ${CPM_ARGS_SOURCE_DIR} REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
else()
|
||||
set(source_directory ${CPM_ARGS_SOURCE_DIR})
|
||||
endif()
|
||||
if(NOT EXISTS ${source_directory})
|
||||
string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
|
||||
# remove timestamps so CMake will re-download the dependency
|
||||
file(REMOVE_RECURSE "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild")
|
||||
endif()
|
||||
elseif(CPM_SOURCE_CACHE AND NOT CPM_ARGS_NO_CACHE)
|
||||
string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
|
||||
set(origin_parameters ${CPM_ARGS_UNPARSED_ARGUMENTS})
|
||||
@@ -672,7 +712,7 @@ function(CPMAddPackage)
|
||||
)
|
||||
cpm_get_fetch_properties("${CPM_ARGS_NAME}")
|
||||
|
||||
if(DEFINED CPM_ARGS_GIT_TAG)
|
||||
if(DEFINED CPM_ARGS_GIT_TAG AND NOT (PATCH_COMMAND IN_LIST CPM_ARGS_UNPARSED_ARGUMENTS))
|
||||
# warn if cache has been changed since checkout
|
||||
cpm_check_git_working_dir_is_clean(${download_directory} ${CPM_ARGS_GIT_TAG} IS_CLEAN)
|
||||
if(NOT ${IS_CLEAN})
|
||||
@@ -891,16 +931,6 @@ function(
|
||||
set(addSubdirectoryExtraArgs "")
|
||||
endif()
|
||||
if(OPTIONS)
|
||||
# the policy allows us to change options without caching
|
||||
cmake_policy(SET CMP0077 NEW)
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
|
||||
|
||||
# the policy allows us to change set(CACHE) without caching
|
||||
if(POLICY CMP0126)
|
||||
cmake_policy(SET CMP0126 NEW)
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0126 NEW)
|
||||
endif()
|
||||
|
||||
foreach(OPTION ${OPTIONS})
|
||||
cpm_parse_option("${OPTION}")
|
||||
set(${OPTION_KEY} "${OPTION_VALUE}")
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
set(CPM_DOWNLOAD_VERSION 1.0.0-development-version)
|
||||
|
||||
if(CPM_SOURCE_CACHE)
|
||||
# Expand relative path. This is important if the provided path contains a tilde (~)
|
||||
get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE)
|
||||
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
|
||||
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
@@ -10,6 +8,8 @@ else()
|
||||
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
endif()
|
||||
|
||||
# Expand relative path. This is important if the provided path contains a tilde (~)
|
||||
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
|
||||
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
|
||||
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
|
||||
file(DOWNLOAD
|
||||
|
||||
@@ -6,7 +6,7 @@ project(CPMRangev3Example)
|
||||
|
||||
include(../../cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage("gh:ericniebler/range-v3#0.11.0")
|
||||
CPMAddPackage("gh:ericniebler/range-v3#0.12.0")
|
||||
|
||||
# ---- Executable ----
|
||||
|
||||
|
||||
36
test/integration/test_remove_source_dir.rb
Normal file
36
test/integration/test_remove_source_dir.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require_relative './lib'
|
||||
|
||||
class RemoveSourceDir < IntegrationTest
|
||||
def test_remove_source_dir
|
||||
prj = make_project 'using-adder'
|
||||
|
||||
prj.create_lists_from_default_template package: <<~PACK
|
||||
CPMAddPackage(
|
||||
NAME testpack-adder
|
||||
GITHUB_REPOSITORY cpm-cmake/testpack-adder
|
||||
VERSION 1.0.0
|
||||
OPTIONS "ADDER_BUILD_TESTS OFF"
|
||||
SOURCE_DIR testpack-adder
|
||||
)
|
||||
PACK
|
||||
|
||||
# configure and build
|
||||
assert_success prj.configure
|
||||
assert_success prj.build
|
||||
|
||||
# source_dir is populated
|
||||
assert_true File.exist?(File.join(prj.bin_dir, 'testpack-adder'))
|
||||
|
||||
# source_dir is deleted by user
|
||||
FileUtils.remove_dir(File.join(prj.bin_dir, 'testpack-adder'), true)
|
||||
assert_false File.exist?(File.join(prj.bin_dir, 'testpack-adder'))
|
||||
|
||||
# configure and build with missing source_dir to fetch new content
|
||||
assert_success prj.configure
|
||||
assert_success prj.build
|
||||
|
||||
# source_dir is populated
|
||||
assert_true File.exist?(File.join(prj.bin_dir, 'testpack-adder'))
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user