Compare commits

...

15 Commits

Author SHA1 Message Date
Robert Maynard
63d0de7114 Don't warn about dirty source trees when a PATCH_COMMAND is provided (#401)
The patch command will always cause a dirty source tree, which
is expected and not a cause for concern.
2022-09-13 23:21:12 +02:00
Kamil Kisiel
65c760a840 Expand absolute path later in get_cpm.cmake (#397)
* Expand absolute path later in get_cpm.cmake

Supports expanding tildes in the environment.

* Apply cmake-format to get_cpm.cmake

* Use .cmake-format file
2022-09-13 20:54:57 +00:00
Robert Maynard
b5e60e72e8 cpm_find_package Use found package version when possible (#396) 2022-09-13 22:44:24 +02:00
Robert Maynard
10bf25a811 Restore policy changes in CPMAddPackage (#388)
* Restore policy changes in CPMAddPackage

Fixes #387

* Correct style issues found by CI
2022-08-11 19:12:21 +00:00
Lars Melchior
18b6cbf233 perform policy changes only in top-level CPM.cmake script (#386) 2022-08-09 12:56:46 +02:00
Olivier Le Doeuff
698741ff7c Fix a very confusing typo (#384) 2022-08-04 10:34:33 +03:00
Borislav Stanimirov
1f09de0d9b Document policies being set to NEW when including CPM.cmake (#383) 2022-08-04 08:32:05 +02:00
Robert Maynard
b224ce280d Timestamps for URL downloads match the download time (#372)
* Timestamps for URL downloads match the download time

By enabling CMake policy 135 we ensure that extracted files
timestamp match that of the download time, instead of when the
archive is created. This makes sure that if the URL changes to
an older version we still rebuild everything as the timestamp
stays newer.

* Introduce CPM_SET_RECOMMENDED_CMAKE_POLICIES

Enabling CPM_SET_RECOMMENDED_CMAKE_POLICIES will establish defaults
for all CMake policies so that both CPM and added projects
operate inline with CPM recommended best practices.

* Fix style issues found by ci

* Update README.md

Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>

* Update cmake/CPM.cmake

Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>

* Set policies when CPM.cmake is included

* CPM_SET_RECOMMENDED_CMAKE_POLICIES default is ON

* Correct failing CI tests

* CPM.cmake always sets policies to on

Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
2022-08-04 00:22:50 +02:00
Lars Melchior
49af958fb4 Use 3 column layout in showcase (#381) 2022-08-03 10:55:32 +03:00
Evgeny Gorodetskiy
90c763532a Add Methane Kit project to showcase table in ReadMe (#380)
* Add MethaneKit project to the showcase table

* Shorten description, wrap to new line in table
2022-08-01 20:55:03 +02:00
Robert Maynard
4605d32f0e CPM_DIRECTORY always stores absolute non symlink paths (#379)
* CPM_DIRECTORY always stores absolute non symlink paths

When CPM is brought into a project via downloading it will be placed
in the build directory. When the build directory is a symlink the
CPM_DIRECTORY value will hold the symlink value. This means that
trying to run CMake via the real build directory will cause CPM
to fail since it considers the current CMAKE_CURRENT_LIST_DIR
to be different and will early exit.

This resolves the issue be always getting CMake to resolve symlinks
before comparing paths for CPM_DIRECTORY.

* Refactor logic based on PR review
2022-07-31 21:51:27 +02:00
Thomas Mosegaard Pedersen
ede60451a9 CPMAddPackage fails if the SOURCE_DIR directory is deleted. (#370)
* Fixed: Deleted SOURCE_DIR directory would abort just after git stash save --quiet;--include-untracked

* Fixed: Review comments

* Added: Integration test for deleted SOURCE_DIR with FetchContent

* Fixed: Review comments

* Fixed: Review comments
2022-07-26 07:15:11 +00:00
David Fong
5961f9f9fb bump example range-v3 to 0.12.0 (#366)
* bump range-v3 to 0.12.0

* bump range-v3 to 0.12.0
2022-07-02 12:56:11 +00:00
Anton Filimonov
69e9ff3766 Klogg switched to CPM for dependency management (#363)
Klogg used to vendor all external dependencies, and now we switched to CPM, and this makes using local dependencies and packaging much easier. Thanks for all you effort!
2022-06-27 23:39:13 +02:00
Olivier Le Doeuff
3fee69c894 Add readme "Customize repository URL" with git-config (#353) 2022-05-17 08:17:14 +02:00
5 changed files with 121 additions and 18 deletions

View File

@@ -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)

View File

@@ -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}")

View File

@@ -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

View File

@@ -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 ----

View 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