mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-18 15:17:30 -05:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4605d32f0e | ||
|
|
ede60451a9 | ||
|
|
5961f9f9fb | ||
|
|
69e9ff3766 | ||
|
|
3fee69c894 | ||
|
|
a575ab57b7 | ||
|
|
ca421f0e0c |
34
README.md
34
README.md
@@ -227,6 +227,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 +274,22 @@ If you know others, feel free to add them here through a PR.
|
||||
<p align="center"><b>ModernCppStarter</b></p>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="https://git.io/liblava">
|
||||
<p align="center">
|
||||
<img src="https://github.com/liblava.png" alt="liblava" width="100pt" />
|
||||
</p>
|
||||
<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>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -275,7 +307,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
|
||||
@@ -93,7 +94,7 @@ set(CPM_VERSION
|
||||
CACHE INTERNAL ""
|
||||
)
|
||||
set(CPM_DIRECTORY
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CPM_CURRENT_DIRECTORY}
|
||||
CACHE INTERNAL ""
|
||||
)
|
||||
set(CPM_FILE
|
||||
@@ -433,6 +434,47 @@ function(cpm_check_git_working_dir_is_clean repoPath gitTag isClean)
|
||||
|
||||
endfunction()
|
||||
|
||||
# method to overwrite internal FetchContent properties, to allow using CPM.cmake to overload
|
||||
# FetchContent calls. As these are internal cmake properties, this method should be used carefully
|
||||
# and may need modification in future CMake versions. Source:
|
||||
# https://github.com/Kitware/CMake/blob/dc3d0b5a0a7d26d43d6cfeb511e224533b5d188f/Modules/FetchContent.cmake#L1152
|
||||
function(cpm_override_fetchcontent contentName)
|
||||
cmake_parse_arguments(PARSE_ARGV 1 arg "" "SOURCE_DIR;BINARY_DIR" "")
|
||||
if(NOT "${arg_UNPARSED_ARGUMENTS}" STREQUAL "")
|
||||
message(FATAL_ERROR "Unsupported arguments: ${arg_UNPARSED_ARGUMENTS}")
|
||||
endif()
|
||||
|
||||
string(TOLOWER ${contentName} contentNameLower)
|
||||
set(prefix "_FetchContent_${contentNameLower}")
|
||||
|
||||
set(propertyName "${prefix}_sourceDir")
|
||||
define_property(
|
||||
GLOBAL
|
||||
PROPERTY ${propertyName}
|
||||
BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
|
||||
FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
|
||||
)
|
||||
set_property(GLOBAL PROPERTY ${propertyName} "${arg_SOURCE_DIR}")
|
||||
|
||||
set(propertyName "${prefix}_binaryDir")
|
||||
define_property(
|
||||
GLOBAL
|
||||
PROPERTY ${propertyName}
|
||||
BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
|
||||
FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
|
||||
)
|
||||
set_property(GLOBAL PROPERTY ${propertyName} "${arg_BINARY_DIR}")
|
||||
|
||||
set(propertyName "${prefix}_populated")
|
||||
define_property(
|
||||
GLOBAL
|
||||
PROPERTY ${propertyName}
|
||||
BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
|
||||
FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
|
||||
)
|
||||
set_property(GLOBAL PROPERTY ${propertyName} TRUE)
|
||||
endfunction()
|
||||
|
||||
# Download and add a package from source
|
||||
function(CPMAddPackage)
|
||||
list(LENGTH ARGN argnLength)
|
||||
@@ -609,6 +651,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})
|
||||
@@ -644,8 +700,15 @@ function(CPMAddPackage)
|
||||
"${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}" "${${CPM_ARGS_NAME}_BINARY_DIR}"
|
||||
"${CPM_ARGS_EXCLUDE_FROM_ALL}" "${CPM_ARGS_OPTIONS}"
|
||||
)
|
||||
set(CPM_SKIP_FETCH TRUE)
|
||||
set(PACKAGE_INFO "${PACKAGE_INFO} at ${download_directory}")
|
||||
|
||||
# As the source dir is already cached/populated, we override the call to FetchContent.
|
||||
set(CPM_SKIP_FETCH TRUE)
|
||||
cpm_override_fetchcontent(
|
||||
"${lower_case_name}" SOURCE_DIR "${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}"
|
||||
BINARY_DIR "${${CPM_ARGS_NAME}_BINARY_DIR}"
|
||||
)
|
||||
|
||||
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.
|
||||
|
||||
@@ -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 ----
|
||||
|
||||
|
||||
43
test/integration/test_fetchcontent_compatibility.rb
Normal file
43
test/integration/test_fetchcontent_compatibility.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
require_relative './lib'
|
||||
|
||||
# Tests FetchContent overriding with CPM
|
||||
|
||||
class FetchContentCompatibility < IntegrationTest
|
||||
def setup
|
||||
@cache_dir = File.join(cur_test_dir, 'cpmcache')
|
||||
ENV['CPM_SOURCE_CACHE'] = @cache_dir
|
||||
end
|
||||
|
||||
def test_add_dependency_cpm_and_fetchcontent
|
||||
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"
|
||||
)
|
||||
|
||||
# should have no effect, as we added the dependency using CPM
|
||||
FetchContent_Declare(
|
||||
testpack-adder
|
||||
GIT_REPOSITORY https://github.com/cpm-cmake/testpack-adder
|
||||
GIT_TAG v1.0.0
|
||||
)
|
||||
FetchContent_MakeAvailable(testpack-adder)
|
||||
PACK
|
||||
|
||||
# configure with unpopulated cache
|
||||
assert_success prj.configure
|
||||
assert_success prj.build
|
||||
|
||||
# cache is populated
|
||||
assert_true File.exist?(File.join(@cache_dir, "testpack-adder"))
|
||||
|
||||
# configure with populated cache
|
||||
assert_success prj.configure
|
||||
assert_success prj.build
|
||||
end
|
||||
|
||||
end
|
||||
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