mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-18 15:17:30 -05:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10bf25a811 | ||
|
|
18b6cbf233 | ||
|
|
698741ff7c | ||
|
|
1f09de0d9b |
@@ -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.
|
||||
@@ -334,7 +337,7 @@ CPMAddPackage(
|
||||
NAME nlohmann_json
|
||||
VERSION 3.9.1
|
||||
GITHUB_REPOSITORY nlohmann/json
|
||||
OPTIONS
|
||||
OPTIONS
|
||||
"JSON_BuildTests OFF"
|
||||
)
|
||||
```
|
||||
|
||||
@@ -28,23 +28,6 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
# 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()
|
||||
|
||||
set(CURRENT_CPM_VERSION 1.0.0-development-version)
|
||||
|
||||
get_filename_component(CPM_CURRENT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
|
||||
@@ -84,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}
|
||||
)
|
||||
@@ -494,6 +497,7 @@ endfunction()
|
||||
|
||||
# Download and add a package from source
|
||||
function(CPMAddPackage)
|
||||
cpm_set_policies()
|
||||
|
||||
list(LENGTH ARGN argnLength)
|
||||
if(argnLength EQUAL 1)
|
||||
|
||||
Reference in New Issue
Block a user