mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-26 06:07:26 -05:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10bf25a811 | ||
|
|
18b6cbf233 | ||
|
|
698741ff7c | ||
|
|
1f09de0d9b | ||
|
|
b224ce280d | ||
|
|
49af958fb4 | ||
|
|
90c763532a | ||
|
|
4605d32f0e |
15
README.md
15
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.
|
- **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).
|
- **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).
|
- **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).
|
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.
|
||||||
@@ -274,6 +277,8 @@ If you know others, feel free to add them here through a PR.
|
|||||||
<p align="center"><b>ModernCppStarter</b></p>
|
<p align="center"><b>ModernCppStarter</b></p>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a href="https://git.io/liblava">
|
<a href="https://git.io/liblava">
|
||||||
<p align="center">
|
<p align="center">
|
||||||
@@ -290,6 +295,14 @@ If you know others, feel free to add them here through a PR.
|
|||||||
<p align="center"><b>klogg - fast advanced log explorer</b></p>
|
<p align="center"><b>klogg - fast advanced log explorer</b></p>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</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>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@@ -324,7 +337,7 @@ CPMAddPackage(
|
|||||||
NAME nlohmann_json
|
NAME nlohmann_json
|
||||||
VERSION 3.9.1
|
VERSION 3.9.1
|
||||||
GITHUB_REPOSITORY nlohmann/json
|
GITHUB_REPOSITORY nlohmann/json
|
||||||
OPTIONS
|
OPTIONS
|
||||||
"JSON_BuildTests OFF"
|
"JSON_BuildTests OFF"
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -30,8 +30,9 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
|||||||
|
|
||||||
set(CURRENT_CPM_VERSION 1.0.0-development-version)
|
set(CURRENT_CPM_VERSION 1.0.0-development-version)
|
||||||
|
|
||||||
|
get_filename_component(CPM_CURRENT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
|
||||||
if(CPM_DIRECTORY)
|
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)
|
if(CPM_VERSION VERSION_LESS CURRENT_CPM_VERSION)
|
||||||
message(
|
message(
|
||||||
AUTHOR_WARNING
|
AUTHOR_WARNING
|
||||||
@@ -66,6 +67,26 @@ endif()
|
|||||||
|
|
||||||
set_property(GLOBAL PROPERTY CPM_INITIALIZED true)
|
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"
|
option(CPM_USE_LOCAL_PACKAGES "Always try to use `find_package` to get dependencies"
|
||||||
$ENV{CPM_USE_LOCAL_PACKAGES}
|
$ENV{CPM_USE_LOCAL_PACKAGES}
|
||||||
)
|
)
|
||||||
@@ -93,7 +114,7 @@ set(CPM_VERSION
|
|||||||
CACHE INTERNAL ""
|
CACHE INTERNAL ""
|
||||||
)
|
)
|
||||||
set(CPM_DIRECTORY
|
set(CPM_DIRECTORY
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CPM_CURRENT_DIRECTORY}
|
||||||
CACHE INTERNAL ""
|
CACHE INTERNAL ""
|
||||||
)
|
)
|
||||||
set(CPM_FILE
|
set(CPM_FILE
|
||||||
@@ -476,6 +497,8 @@ endfunction()
|
|||||||
|
|
||||||
# Download and add a package from source
|
# Download and add a package from source
|
||||||
function(CPMAddPackage)
|
function(CPMAddPackage)
|
||||||
|
cpm_set_policies()
|
||||||
|
|
||||||
list(LENGTH ARGN argnLength)
|
list(LENGTH ARGN argnLength)
|
||||||
if(argnLength EQUAL 1)
|
if(argnLength EQUAL 1)
|
||||||
cpm_parse_add_package_single_arg("${ARGN}" ARGN)
|
cpm_parse_add_package_single_arg("${ARGN}" ARGN)
|
||||||
@@ -905,16 +928,6 @@ function(
|
|||||||
set(addSubdirectoryExtraArgs "")
|
set(addSubdirectoryExtraArgs "")
|
||||||
endif()
|
endif()
|
||||||
if(OPTIONS)
|
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})
|
foreach(OPTION ${OPTIONS})
|
||||||
cpm_parse_option("${OPTION}")
|
cpm_parse_option("${OPTION}")
|
||||||
set(${OPTION_KEY} "${OPTION_VALUE}")
|
set(${OPTION_KEY} "${OPTION_VALUE}")
|
||||||
|
|||||||
Reference in New Issue
Block a user