mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-25 21:57:48 -05:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
939123d1b4 | ||
|
|
22078d5e0d | ||
|
|
96c268827b | ||
|
|
dad37fbe4e | ||
|
|
fed5f8e8a2 | ||
|
|
d65613e860 | ||
|
|
718ea71759 | ||
|
|
6491382204 | ||
|
|
634800c619 |
32
README.md
32
README.md
@@ -1,4 +1,3 @@
|
|||||||
[](https://travis-ci.com/cpm-cmake/CPM.cmake)
|
|
||||||
[](https://github.com/cpm-cmake/CPM.cmake/actions)
|
[](https://github.com/cpm-cmake/CPM.cmake/actions)
|
||||||
[](https://github.com/cpm-cmake/CPM.cmake/actions)
|
[](https://github.com/cpm-cmake/CPM.cmake/actions)
|
||||||
[](https://github.com/cpm-cmake/CPM.cmake/actions)
|
[](https://github.com/cpm-cmake/CPM.cmake/actions)
|
||||||
@@ -196,6 +195,11 @@ These options can also be set as environmental variables.
|
|||||||
|
|
||||||
In the case that `find_package` requires additional arguments, the parameter `FIND_PACKAGE_ARGUMENTS` may be specified in the `CPMAddPackage` call. The value of this parameter will be forwarded to `find_package`.
|
In the case that `find_package` requires additional arguments, the parameter `FIND_PACKAGE_ARGUMENTS` may be specified in the `CPMAddPackage` call. The value of this parameter will be forwarded to `find_package`.
|
||||||
|
|
||||||
|
### CPM_USE_NAMED_CACHE_DIRECTORIES
|
||||||
|
|
||||||
|
If set, CPM use additional directory level in cache to improve readability of packages names in IDEs like CLion. It changes cache structure, so all dependencies are downloaded again. There is no problem to mix both structures in one cache directory but then there may be 2 copies of some dependencies.
|
||||||
|
This can also be set as an environmental variable.
|
||||||
|
|
||||||
## Local package override
|
## Local package override
|
||||||
|
|
||||||
Library developers are often in the situation where they work on a locally checked out dependency at the same time as on a consumer project.
|
Library developers are often in the situation where they work on a locally checked out dependency at the same time as on a consumer project.
|
||||||
@@ -270,11 +274,10 @@ See the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/More-Snippets) for mo
|
|||||||
CPMAddPackage("gh:catchorg/Catch2@2.5.0")
|
CPMAddPackage("gh:catchorg/Catch2@2.5.0")
|
||||||
```
|
```
|
||||||
|
|
||||||
### [Boost (via boost-cmake)](https://github.com/Orphis/boost-cmake)
|
### [Range-v3](https://github.com/ericniebler/range-v3)
|
||||||
|
|
||||||
```CMake
|
```Cmake
|
||||||
# boost-cmake currently doesn't tag versions, so we use the according boost version
|
CPMAddPackage("gh:ericniebler/range-v3#0.11.0")
|
||||||
CPMAddPackage("gh:Orphis/boost-cmake#7f97a08b64bd5d2e53e932ddf80c40544cf45edf@1.71.0")
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### [Yaml-cpp](https://github.com/jbeder/yaml-cpp)
|
### [Yaml-cpp](https://github.com/jbeder/yaml-cpp)
|
||||||
@@ -284,12 +287,6 @@ CPMAddPackage("gh:Orphis/boost-cmake#7f97a08b64bd5d2e53e932ddf80c40544cf45edf@1.
|
|||||||
CPMAddPackage("gh:jbeder/yaml-cpp#yaml-cpp-0.6.3@0.6.3")
|
CPMAddPackage("gh:jbeder/yaml-cpp#yaml-cpp-0.6.3@0.6.3")
|
||||||
```
|
```
|
||||||
|
|
||||||
### [Range-v3](https://github.com/ericniebler/range-v3)
|
|
||||||
|
|
||||||
```Cmake
|
|
||||||
CPMAddPackage("gh:ericniebler/range-v3#0.11.0")
|
|
||||||
```
|
|
||||||
|
|
||||||
### [nlohmann/json](https://github.com/nlohmann/json)
|
### [nlohmann/json](https://github.com/nlohmann/json)
|
||||||
|
|
||||||
```cmake
|
```cmake
|
||||||
@@ -301,6 +298,19 @@ CPMAddPackage(
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### [Boost ](https://github.com/boostorg/boost)
|
||||||
|
|
||||||
|
```CMake
|
||||||
|
# boost is a huge project and will take a while to download
|
||||||
|
# using `CPM_SOURCE_CACHE` is strongly recommended
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME Boost
|
||||||
|
VERSION 1.77.0
|
||||||
|
GITHUB_REPOSITORY "boostorg/boost"
|
||||||
|
GIT_TAG "boost-1.77.0"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
### [cxxopts](https://github.com/jarro2783/cxxopts)
|
### [cxxopts](https://github.com/jarro2783/cxxopts)
|
||||||
|
|
||||||
```cmake
|
```cmake
|
||||||
|
|||||||
@@ -57,6 +57,13 @@ See https://github.com/cpm-cmake/CPM.cmake for more information."
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(CURRENT_CPM_VERSION MATCHES "development-version")
|
||||||
|
message(WARNING "Your project is using an unstable development version of CPM.cmake. \
|
||||||
|
Please update to a recent release if possible. \
|
||||||
|
See https://github.com/cpm-cmake/CPM.cmake for details."
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
set_property(GLOBAL PROPERTY CPM_INITIALIZED true)
|
set_property(GLOBAL PROPERTY CPM_INITIALIZED true)
|
||||||
|
|
||||||
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"
|
||||||
@@ -76,6 +83,10 @@ option(CPM_INCLUDE_ALL_IN_PACKAGE_LOCK
|
|||||||
"Add all packages added through CPM.cmake to the package lock"
|
"Add all packages added through CPM.cmake to the package lock"
|
||||||
$ENV{CPM_INCLUDE_ALL_IN_PACKAGE_LOCK}
|
$ENV{CPM_INCLUDE_ALL_IN_PACKAGE_LOCK}
|
||||||
)
|
)
|
||||||
|
option(CPM_USE_NAMED_CACHE_DIRECTORIES
|
||||||
|
"Use additional directory of package name in cache on the most nested level."
|
||||||
|
$ENV{CPM_USE_NAMED_CACHE_DIRECTORIES}
|
||||||
|
)
|
||||||
|
|
||||||
set(CPM_VERSION
|
set(CPM_VERSION
|
||||||
${CURRENT_CPM_VERSION}
|
${CURRENT_CPM_VERSION}
|
||||||
@@ -537,6 +548,7 @@ function(CPMAddPackage)
|
|||||||
EXCLUDE_FROM_ALL "${CPM_ARGS_EXCLUDE_FROM_ALL}"
|
EXCLUDE_FROM_ALL "${CPM_ARGS_EXCLUDE_FROM_ALL}"
|
||||||
OPTIONS "${CPM_ARGS_OPTIONS}"
|
OPTIONS "${CPM_ARGS_OPTIONS}"
|
||||||
SOURCE_SUBDIR "${CPM_ARGS_SOURCE_SUBDIR}"
|
SOURCE_SUBDIR "${CPM_ARGS_SOURCE_SUBDIR}"
|
||||||
|
DOWNLOAD_ONLY "${DOWNLOAD_ONLY}"
|
||||||
FORCE True
|
FORCE True
|
||||||
)
|
)
|
||||||
cpm_export_variables(${CPM_ARGS_NAME})
|
cpm_export_variables(${CPM_ARGS_NAME})
|
||||||
@@ -595,17 +607,23 @@ function(CPMAddPackage)
|
|||||||
string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
|
string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
|
||||||
set(origin_parameters ${CPM_ARGS_UNPARSED_ARGUMENTS})
|
set(origin_parameters ${CPM_ARGS_UNPARSED_ARGUMENTS})
|
||||||
list(SORT origin_parameters)
|
list(SORT origin_parameters)
|
||||||
|
if(CPM_USE_NAMED_CACHE_DIRECTORIES)
|
||||||
|
string(SHA1 origin_hash "${origin_parameters};NEW_CACHE_STRUCTURE_TAG")
|
||||||
|
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash}/${CPM_ARGS_NAME})
|
||||||
|
else()
|
||||||
string(SHA1 origin_hash "${origin_parameters}")
|
string(SHA1 origin_hash "${origin_parameters}")
|
||||||
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash})
|
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash})
|
||||||
|
endif()
|
||||||
# Expand `download_directory` relative path. This is important because EXISTS doesn't work for
|
# Expand `download_directory` relative path. This is important because EXISTS doesn't work for
|
||||||
# relative paths.
|
# relative paths.
|
||||||
get_filename_component(download_directory ${download_directory} ABSOLUTE)
|
get_filename_component(download_directory ${download_directory} ABSOLUTE)
|
||||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${download_directory})
|
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${download_directory})
|
||||||
if(EXISTS ${download_directory})
|
if(EXISTS ${download_directory})
|
||||||
# avoid FetchContent modules to improve performance
|
cpm_store_fetch_properties(
|
||||||
set(${CPM_ARGS_NAME}_BINARY_DIR ${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build)
|
${CPM_ARGS_NAME} "${download_directory}"
|
||||||
set(${CPM_ARGS_NAME}_ADDED YES)
|
"${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build"
|
||||||
set(${CPM_ARGS_NAME}_SOURCE_DIR ${download_directory})
|
)
|
||||||
|
cpm_get_fetch_properties("${CPM_ARGS_NAME}")
|
||||||
|
|
||||||
if(DEFINED CPM_ARGS_GIT_TAG)
|
if(DEFINED CPM_ARGS_GIT_TAG)
|
||||||
# warn if cache has been changed since checkout
|
# warn if cache has been changed since checkout
|
||||||
@@ -638,7 +656,7 @@ function(CPMAddPackage)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
cpm_create_module_file(${CPM_ARGS_NAME} "CPMAddPackage(${ARGN})")
|
cpm_create_module_file(${CPM_ARGS_NAME} "CPMAddPackage(\"${ARGN}\")")
|
||||||
|
|
||||||
if(CPM_PACKAGE_LOCK_ENABLED)
|
if(CPM_PACKAGE_LOCK_ENABLED)
|
||||||
if((CPM_ARGS_VERSION AND NOT CPM_ARGS_SOURCE_DIR) OR CPM_INCLUDE_ALL_IN_PACKAGE_LOCK)
|
if((CPM_ARGS_VERSION AND NOT CPM_ARGS_SOURCE_DIR) OR CPM_INCLUDE_ALL_IN_PACKAGE_LOCK)
|
||||||
@@ -776,18 +794,32 @@ function(cpm_get_fetch_properties PACKAGE)
|
|||||||
if(${CPM_DRY_RUN})
|
if(${CPM_DRY_RUN})
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
FetchContent_GetProperties(${PACKAGE})
|
|
||||||
string(TOLOWER ${PACKAGE} lpackage)
|
|
||||||
set(${PACKAGE}_SOURCE_DIR
|
set(${PACKAGE}_SOURCE_DIR
|
||||||
"${${lpackage}_SOURCE_DIR}"
|
"${CPM_PACKAGE_${PACKAGE}_SOURCE_DIR}"
|
||||||
PARENT_SCOPE
|
PARENT_SCOPE
|
||||||
)
|
)
|
||||||
set(${PACKAGE}_BINARY_DIR
|
set(${PACKAGE}_BINARY_DIR
|
||||||
"${${lpackage}_BINARY_DIR}"
|
"${CPM_PACKAGE_${PACKAGE}_BINARY_DIR}"
|
||||||
PARENT_SCOPE
|
PARENT_SCOPE
|
||||||
)
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(cpm_store_fetch_properties PACKAGE source_dir binary_dir)
|
||||||
|
if(${CPM_DRY_RUN})
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CPM_PACKAGE_${PACKAGE}_SOURCE_DIR
|
||||||
|
"${source_dir}"
|
||||||
|
CACHE INTERNAL ""
|
||||||
|
)
|
||||||
|
set(CPM_PACKAGE_${PACKAGE}_BINARY_DIR
|
||||||
|
"${binary_dir}"
|
||||||
|
CACHE INTERNAL ""
|
||||||
|
)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# adds a package as a subdirectory if viable, according to provided options
|
# adds a package as a subdirectory if viable, according to provided options
|
||||||
function(
|
function(
|
||||||
cpm_add_subdirectory
|
cpm_add_subdirectory
|
||||||
@@ -810,8 +842,8 @@ function(
|
|||||||
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
|
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
|
||||||
|
|
||||||
foreach(OPTION ${OPTIONS})
|
foreach(OPTION ${OPTIONS})
|
||||||
cpm_parse_option(${OPTION})
|
cpm_parse_option("${OPTION}")
|
||||||
set(${OPTION_KEY} ${OPTION_VALUE})
|
set(${OPTION_KEY} "${OPTION_VALUE}")
|
||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
set(CPM_OLD_INDENT "${CPM_INDENT}")
|
set(CPM_OLD_INDENT "${CPM_INDENT}")
|
||||||
@@ -845,6 +877,10 @@ function(cpm_fetch_package PACKAGE populated)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
cpm_store_fetch_properties(
|
||||||
|
${CPM_ARGS_NAME} ${${lower_case_name}_SOURCE_DIR} ${${lower_case_name}_BINARY_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
set(${PACKAGE}_SOURCE_DIR
|
set(${PACKAGE}_SOURCE_DIR
|
||||||
${${lower_case_name}_SOURCE_DIR}
|
${${lower_case_name}_SOURCE_DIR}
|
||||||
PARENT_SCOPE
|
PARENT_SCOPE
|
||||||
@@ -857,15 +893,15 @@ endfunction()
|
|||||||
|
|
||||||
# splits a package option
|
# splits a package option
|
||||||
function(cpm_parse_option OPTION)
|
function(cpm_parse_option OPTION)
|
||||||
string(REGEX MATCH "^[^ ]+" OPTION_KEY ${OPTION})
|
string(REGEX MATCH "^[^ ]+" OPTION_KEY "${OPTION}")
|
||||||
string(LENGTH ${OPTION} OPTION_LENGTH)
|
string(LENGTH "${OPTION}" OPTION_LENGTH)
|
||||||
string(LENGTH ${OPTION_KEY} OPTION_KEY_LENGTH)
|
string(LENGTH "${OPTION_KEY}" OPTION_KEY_LENGTH)
|
||||||
if(OPTION_KEY_LENGTH STREQUAL OPTION_LENGTH)
|
if(OPTION_KEY_LENGTH STREQUAL OPTION_LENGTH)
|
||||||
# no value for key provided, assume user wants to set option to "ON"
|
# no value for key provided, assume user wants to set option to "ON"
|
||||||
set(OPTION_VALUE "ON")
|
set(OPTION_VALUE "ON")
|
||||||
else()
|
else()
|
||||||
math(EXPR OPTION_KEY_LENGTH "${OPTION_KEY_LENGTH}+1")
|
math(EXPR OPTION_KEY_LENGTH "${OPTION_KEY_LENGTH}+1")
|
||||||
string(SUBSTRING ${OPTION} "${OPTION_KEY_LENGTH}" "-1" OPTION_VALUE)
|
string(SUBSTRING "${OPTION}" "${OPTION_KEY_LENGTH}" "-1" OPTION_VALUE)
|
||||||
endif()
|
endif()
|
||||||
set(OPTION_KEY
|
set(OPTION_KEY
|
||||||
"${OPTION_KEY}"
|
"${OPTION_KEY}"
|
||||||
|
|||||||
@@ -11,9 +11,11 @@ target_compile_features(CPMExampleBoost PRIVATE cxx_std_17)
|
|||||||
|
|
||||||
include(../../cmake/CPM.cmake)
|
include(../../cmake/CPM.cmake)
|
||||||
|
|
||||||
# boost-cmake currently doesn't tag versions, so we use the according boost version
|
CPMAddPackage(
|
||||||
CPMAddPackage("gh:Orphis/boost-cmake#7f97a08b64bd5d2e53e932ddf80c40544cf45edf@1.71.0")
|
NAME Boost
|
||||||
|
VERSION 1.77.0
|
||||||
|
GITHUB_REPOSITORY "boostorg/boost"
|
||||||
|
GIT_TAG "boost-1.77.0"
|
||||||
|
)
|
||||||
|
|
||||||
find_package(Threads REQUIRED)
|
target_link_libraries(CPMExampleBoost PRIVATE Boost::asio)
|
||||||
|
|
||||||
target_link_libraries(CPMExampleBoost PRIVATE Boost::system Threads::Threads)
|
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ include(@CPM_PATH@/CPM.cmake)
|
|||||||
CPMAddPackage(
|
CPMAddPackage(
|
||||||
NAME Dependency
|
NAME Dependency
|
||||||
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/dependency
|
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/dependency
|
||||||
OPTIONS "DEFINE_ALTERNATIVE_FUNCTION YES"
|
OPTIONS
|
||||||
|
"DEFINE_ALTERNATIVE_FUNCTION YES"
|
||||||
|
"LIST_ARGUMENT a\\\\;b\\\\;c"
|
||||||
EXCLUDE_FROM_ALL YES
|
EXCLUDE_FROM_ALL YES
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ if(NOT DEFINE_ALTERNATIVE_FUNCTION)
|
|||||||
message("called external method")
|
message("called external method")
|
||||||
endfunction()
|
endfunction()
|
||||||
else()
|
else()
|
||||||
|
|
||||||
|
# check if list was passed correctly
|
||||||
|
if(NOT "${LIST_ARGUMENT}" STREQUAL "a;b;c")
|
||||||
|
message(FATAL_ERROR "list argument not properly passed to dependency: '${LIST_ARGUMENT}'")
|
||||||
|
endif()
|
||||||
|
|
||||||
function(alternative_dependency_function)
|
function(alternative_dependency_function)
|
||||||
message("called alternative external method")
|
message("called alternative external method")
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|||||||
Reference in New Issue
Block a user