Compare commits

...

8 Commits

Author SHA1 Message Date
DNKpp
939123d1b4 Fix <package>_SOURCE_DIR and _BINARY_DIR handling when caching is active (#314)
* fix: use CACHE variables instead relying on FetchContents mechanism

* apply cmake-format

Signed-off-by: DNKpp <DNKpp2011@gmail.com>
2021-12-30 16:20:37 +01:00
Lars Melchior
22078d5e0d add quotes around module arguments (#313) 2021-12-30 15:20:16 +02:00
Pavel Sokolov
96c268827b Pass DOWNLOAD_ONLY flag when CPM_pkg_SOURCE is set. (#308)
https://github.com/cpm-cmake/CPM.cmake/issues/307
2021-12-15 21:23:18 +01:00
Lars Melchior
dad37fbe4e Change example ordering and add note on boost (#305)
Reorders examples from simple to more complex. Also adds note on using `CPM_SOURCE_CACHE` for boost.
2021-12-12 15:09:50 +01:00
Lars Melchior
fed5f8e8a2 use official boost release (#304) 2021-12-05 16:08:47 +01:00
Lars Melchior
d65613e860 add warning when not using release version of CPM.cmake (#303) 2021-12-05 16:08:02 +01:00
Lars Melchior
718ea71759 Allow passing lists in the options (#302)
* allow list options by passing option parameter as string, not value

* add test

* remove debug message

* run formatter
2021-12-05 16:07:20 +01:00
Lars Melchior
6491382204 Remove travis badge from readme (#289)
Follow up on #283 to remove the now obsolete travis badge.
2021-09-29 13:48:40 +03:00
5 changed files with 74 additions and 32 deletions

View File

@@ -1,4 +1,3 @@
[![Build Status](https://travis-ci.com/cpm-cmake/CPM.cmake.svg?branch=master)](https://travis-ci.com/cpm-cmake/CPM.cmake)
[![Actions Status](https://github.com/cpm-cmake/CPM.cmake/workflows/MacOS/badge.svg)](https://github.com/cpm-cmake/CPM.cmake/actions)
[![Actions Status](https://github.com/cpm-cmake/CPM.cmake/workflows/Windows/badge.svg)](https://github.com/cpm-cmake/CPM.cmake/actions)
[![Actions Status](https://github.com/cpm-cmake/CPM.cmake/workflows/Ubuntu/badge.svg)](https://github.com/cpm-cmake/CPM.cmake/actions)
@@ -275,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")
```
### [Boost (via boost-cmake)](https://github.com/Orphis/boost-cmake)
### [Range-v3](https://github.com/ericniebler/range-v3)
```CMake
# boost-cmake currently doesn't tag versions, so we use the according boost version
CPMAddPackage("gh:Orphis/boost-cmake#7f97a08b64bd5d2e53e932ddf80c40544cf45edf@1.71.0")
```Cmake
CPMAddPackage("gh:ericniebler/range-v3#0.11.0")
```
### [Yaml-cpp](https://github.com/jbeder/yaml-cpp)
@@ -289,12 +287,6 @@ CPMAddPackage("gh:Orphis/boost-cmake#7f97a08b64bd5d2e53e932ddf80c40544cf45edf@1.
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)
```cmake
@@ -306,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)
```cmake

View File

@@ -57,6 +57,13 @@ See https://github.com/cpm-cmake/CPM.cmake for more information."
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)
option(CPM_USE_LOCAL_PACKAGES "Always try to use `find_package` to get dependencies"
@@ -541,6 +548,7 @@ function(CPMAddPackage)
EXCLUDE_FROM_ALL "${CPM_ARGS_EXCLUDE_FROM_ALL}"
OPTIONS "${CPM_ARGS_OPTIONS}"
SOURCE_SUBDIR "${CPM_ARGS_SOURCE_SUBDIR}"
DOWNLOAD_ONLY "${DOWNLOAD_ONLY}"
FORCE True
)
cpm_export_variables(${CPM_ARGS_NAME})
@@ -611,10 +619,11 @@ function(CPMAddPackage)
get_filename_component(download_directory ${download_directory} ABSOLUTE)
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${download_directory})
if(EXISTS ${download_directory})
# avoid FetchContent modules to improve performance
set(${CPM_ARGS_NAME}_BINARY_DIR ${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build)
set(${CPM_ARGS_NAME}_ADDED YES)
set(${CPM_ARGS_NAME}_SOURCE_DIR ${download_directory})
cpm_store_fetch_properties(
${CPM_ARGS_NAME} "${download_directory}"
"${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build"
)
cpm_get_fetch_properties("${CPM_ARGS_NAME}")
if(DEFINED CPM_ARGS_GIT_TAG)
# warn if cache has been changed since checkout
@@ -647,7 +656,7 @@ function(CPMAddPackage)
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_ARGS_VERSION AND NOT CPM_ARGS_SOURCE_DIR) OR CPM_INCLUDE_ALL_IN_PACKAGE_LOCK)
@@ -785,18 +794,32 @@ function(cpm_get_fetch_properties PACKAGE)
if(${CPM_DRY_RUN})
return()
endif()
FetchContent_GetProperties(${PACKAGE})
string(TOLOWER ${PACKAGE} lpackage)
set(${PACKAGE}_SOURCE_DIR
"${${lpackage}_SOURCE_DIR}"
"${CPM_PACKAGE_${PACKAGE}_SOURCE_DIR}"
PARENT_SCOPE
)
set(${PACKAGE}_BINARY_DIR
"${${lpackage}_BINARY_DIR}"
"${CPM_PACKAGE_${PACKAGE}_BINARY_DIR}"
PARENT_SCOPE
)
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
function(
cpm_add_subdirectory
@@ -819,8 +842,8 @@ function(
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
foreach(OPTION ${OPTIONS})
cpm_parse_option(${OPTION})
set(${OPTION_KEY} ${OPTION_VALUE})
cpm_parse_option("${OPTION}")
set(${OPTION_KEY} "${OPTION_VALUE}")
endforeach()
endif()
set(CPM_OLD_INDENT "${CPM_INDENT}")
@@ -854,6 +877,10 @@ function(cpm_fetch_package PACKAGE populated)
)
endif()
cpm_store_fetch_properties(
${CPM_ARGS_NAME} ${${lower_case_name}_SOURCE_DIR} ${${lower_case_name}_BINARY_DIR}
)
set(${PACKAGE}_SOURCE_DIR
${${lower_case_name}_SOURCE_DIR}
PARENT_SCOPE
@@ -866,15 +893,15 @@ endfunction()
# splits a package option
function(cpm_parse_option OPTION)
string(REGEX MATCH "^[^ ]+" OPTION_KEY ${OPTION})
string(LENGTH ${OPTION} OPTION_LENGTH)
string(LENGTH ${OPTION_KEY} OPTION_KEY_LENGTH)
string(REGEX MATCH "^[^ ]+" OPTION_KEY "${OPTION}")
string(LENGTH "${OPTION}" OPTION_LENGTH)
string(LENGTH "${OPTION_KEY}" OPTION_KEY_LENGTH)
if(OPTION_KEY_LENGTH STREQUAL OPTION_LENGTH)
# no value for key provided, assume user wants to set option to "ON"
set(OPTION_VALUE "ON")
else()
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()
set(OPTION_KEY
"${OPTION_KEY}"

View File

@@ -11,9 +11,11 @@ target_compile_features(CPMExampleBoost PRIVATE cxx_std_17)
include(../../cmake/CPM.cmake)
# boost-cmake currently doesn't tag versions, so we use the according boost version
CPMAddPackage("gh:Orphis/boost-cmake#7f97a08b64bd5d2e53e932ddf80c40544cf45edf@1.71.0")
CPMAddPackage(
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::system Threads::Threads)
target_link_libraries(CPMExampleBoost PRIVATE Boost::asio)

View File

@@ -13,7 +13,9 @@ include(@CPM_PATH@/CPM.cmake)
CPMAddPackage(
NAME 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
)

View File

@@ -8,6 +8,12 @@ if(NOT DEFINE_ALTERNATIVE_FUNCTION)
message("called external method")
endfunction()
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)
message("called alternative external method")
endfunction()