Compare commits

...

11 Commits

Author SHA1 Message Date
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
pgorgon-hem
634800c619 Added directory inside cache to make it shown more friendly in CLion (#268)
* Added directory inside cache to make it shown more friendly in CLion

* Changed hash generation to omit collision with old cache scheme. Removed moving old directory for compatibility reason.

* Added CPM_USE_NAMED_CACHE_DIRECTORIES option

* Fixed formatting

* Added description of CPM_USE_NAMED_CACHE_DIRECTORIES into README.md

Co-authored-by: Paweł Gorgoń <pgorgon@hem-e.com>
2021-09-15 21:39:31 +02:00
Andrea Barbadoro
f552da96bd Detecting when the cache is dirty (#284)
* Check that the cache working directory is clean

* cpm_check_working_dir_is_clean for non git repo will not terminate cmake

* sileneced check for git repo, in case of error

* style(CPM.cmake): fixed indentation for ERROR_QUIET

* refactor(CPM.cmake): added logic to handle a cache folder inside a (not correlated) git repo

this is accomplished by checking if we are in the directory where .git lives

* style(CPM.cmake): stray tab to spaces

* test(dirty-cache-check): added unit test to check cpm_check_working_dir_is_clean

the test creates a file in a folder and then uses git to create a repo in that folder, to check various conditions

* Update test/unit/dirty-cache-check.cmake

added user.name and user.email to comply with test machine where git is not completely configured

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

* feat(cpm_check_working_dir_is_clean): now it takes a git tag (works with hashes too) to check for uncommitted and commited changes

* refactor(cpm_check_working_dir_is_clean): early return for the most common case of uncommited changes in a repo

* refactor(cpm_check_git_working_dir_is_clean): removed edgecase detection (a non-git folder in an unrelated git repo)

now the contract is that com_check_git_working_dir_is_clean is given the base folder of a git repo

Co-authored-by: Andrew Gribble <ag131012@renishaw.com>
Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
2021-09-15 11:38:49 +02:00
Olivier Le Doeuff
ea6a8eb895 Fix CPMAddPackage when FetchContent_MakeAvailable already added package (#288)
Add fetchcontent_dependency unit test:
* This test should highlight the fact that cpm_add_subdirectory is always called, even when
  cpm_fetch_package isn't populating the dependency
* NO_CACHE YES highlight a bug introduced in 32b063eba5 where
  cpm_fetch_package was checking undefined ${lower_case_name}_POPULATED variable

https://github.com/cpm-cmake/CPM.cmake/issues/287
2021-08-29 22:02:18 +02:00
MixusMinimax
a5c22bf6e8 use quotes for CPM_FILE when creating FIND.cmake (#286) 2021-08-29 22:01:50 +02:00
Lars Melchior
c5cb85b2f1 Build examples in CI using GitHub (#283)
* build examples in CI using github

* update cxxopts style
2021-08-29 20:27:10 +02:00
13 changed files with 333 additions and 85 deletions

30
.github/workflows/examples.yml vendored Normal file
View File

@@ -0,0 +1,30 @@
name: Examples
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
gcc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: build all
env:
CC: gcc
CXX: g++
run: python3 examples/build_all.py
clang:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: build all
env:
CC: clang
CXX: clang++
run: python3 examples/build_all.py

View File

@@ -1,49 +0,0 @@
language: cpp
sudo: require
dist: xenial
common_sources: &all_sources
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty
python:
- 3.7
matrix:
include:
- os: linux
compiler: gcc
addons: &gcc8
apt:
sources: *all_sources
packages:
- g++-8
env:
- MATRIX_EVAL="export CC=gcc-8; export CXX=g++-8;"
- os: linux
compiler: clang
addons:
apt:
sources: *all_sources
packages:
- g++-8
- clang-6.0
env:
- MATRIX_EVAL="export CC=clang-6.0; export CXX=clang++-6.0;"
before_install:
# Update compilers
- eval "${MATRIX_EVAL}"
- echo "CC=$CC CXX=$CXX"
- wget -O cmake.sh https://github.com/Kitware/CMake/releases/download/v3.20.3/cmake-3.20.3-linux-x86_64.sh
- sudo sh cmake.sh --skip-license --exclude-subdir --prefix=/usr/local
- export PATH=/usr/local/bin:$PATH
- cmake --version
script:
# unit tests
- cmake -Htest -Bbuild/test
- cmake --build build/test --target test-verbose
# build examples
- python3 examples/build_all.py

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)
@@ -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`.
### 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
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")
```
### [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)
@@ -284,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
@@ -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)
```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"
@@ -76,6 +83,10 @@ option(CPM_INCLUDE_ALL_IN_PACKAGE_LOCK
"Add all packages added through CPM.cmake to the 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
${CURRENT_CPM_VERSION}
@@ -223,7 +234,7 @@ function(cpm_create_module_file Name)
if(NOT CPM_DONT_UPDATE_MODULE_PATH)
# erase any previous modules
file(WRITE ${CPM_MODULE_PATH}/Find${Name}.cmake
"include(${CPM_FILE})\n${ARGN}\nset(${Name}_FOUND TRUE)"
"include(\"${CPM_FILE}\")\n${ARGN}\nset(${Name}_FOUND TRUE)"
)
endif()
endfunction()
@@ -354,6 +365,68 @@ function(cpm_parse_add_package_single_arg arg outArgs)
)
endfunction()
# Check that the working directory for a git repo is clean
function(cpm_check_git_working_dir_is_clean repoPath gitTag isClean)
find_package(Git REQUIRED)
if(NOT GIT_EXECUTABLE)
# No git executable, assume directory is clean
set(${isClean}
TRUE
PARENT_SCOPE
)
return()
endif()
# check for uncommited changes
execute_process(
COMMAND ${GIT_EXECUTABLE} status --porcelain
RESULT_VARIABLE resultGitStatus
OUTPUT_VARIABLE repoStatus
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
WORKING_DIRECTORY ${repoPath}
)
if(resultGitStatus)
# not supposed to happen, assume clean anyway
message(WARNING "Calling git status on folder ${repoPath} failed")
set(${isClean}
TRUE
PARENT_SCOPE
)
return()
endif()
if(NOT "${repoStatus}" STREQUAL "")
set(${isClean}
FALSE
PARENT_SCOPE
)
return()
endif()
# check for commited changes
execute_process(
COMMAND ${GIT_EXECUTABLE} diff -s --exit-code ${gitTag}
RESULT_VARIABLE resultGitDiff
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_QUIET
WORKING_DIRECTORY ${repoPath}
)
if(${resultGitDiff} EQUAL 0)
set(${isClean}
TRUE
PARENT_SCOPE
)
else()
set(${isClean}
FALSE
PARENT_SCOPE
)
endif()
endfunction()
# Download and add a package from source
function(CPMAddPackage)
list(LENGTH ARGN argnLength)
@@ -475,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})
@@ -533,8 +607,13 @@ function(CPMAddPackage)
string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
set(origin_parameters ${CPM_ARGS_UNPARSED_ARGUMENTS})
list(SORT origin_parameters)
string(SHA1 origin_hash "${origin_parameters}")
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash})
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}")
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
# relative paths.
get_filename_component(download_directory ${download_directory} ABSOLUTE)
@@ -544,6 +623,15 @@ function(CPMAddPackage)
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})
if(DEFINED CPM_ARGS_GIT_TAG)
# 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})
message(WARNING "Cache for ${CPM_ARGS_NAME} (${download_directory}) is dirty")
endif()
endif()
cpm_add_subdirectory(
"${CPM_ARGS_NAME}" "${DOWNLOAD_ONLY}"
"${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}" "${${CPM_ARGS_NAME}_BINARY_DIR}"
@@ -587,12 +675,14 @@ function(CPMAddPackage)
cpm_declare_fetch(
"${CPM_ARGS_NAME}" "${CPM_ARGS_VERSION}" "${PACKAGE_INFO}" "${CPM_ARGS_UNPARSED_ARGUMENTS}"
)
cpm_fetch_package("${CPM_ARGS_NAME}")
cpm_add_subdirectory(
"${CPM_ARGS_NAME}" "${DOWNLOAD_ONLY}"
"${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}" "${${CPM_ARGS_NAME}_BINARY_DIR}"
"${CPM_ARGS_EXCLUDE_FROM_ALL}" "${CPM_ARGS_OPTIONS}"
)
cpm_fetch_package("${CPM_ARGS_NAME}" populated)
if(${populated})
cpm_add_subdirectory(
"${CPM_ARGS_NAME}" "${DOWNLOAD_ONLY}"
"${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}" "${${CPM_ARGS_NAME}_BINARY_DIR}"
"${CPM_ARGS_EXCLUDE_FROM_ALL}" "${CPM_ARGS_OPTIONS}"
)
endif()
cpm_get_fetch_properties("${CPM_ARGS_NAME}")
endif()
@@ -737,8 +827,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}")
@@ -750,7 +840,11 @@ endfunction()
# downloads a previously declared package via FetchContent and exports the variables
# `${PACKAGE}_SOURCE_DIR` and `${PACKAGE}_BINARY_DIR` to the parent scope
function(cpm_fetch_package PACKAGE)
function(cpm_fetch_package PACKAGE populated)
set(${populated}
FALSE
PARENT_SCOPE
)
if(${CPM_DRY_RUN})
message(STATUS "${CPM_INDENT} package ${PACKAGE} not fetched (dry run)")
return()
@@ -758,11 +852,16 @@ function(cpm_fetch_package PACKAGE)
FetchContent_GetProperties(${PACKAGE})
string(TOLOWER "${PACKAGE}" lower_case_name)
if(NOT ${lower_case_name}_POPULATED)
FetchContent_Populate(${PACKAGE})
set(${populated}
TRUE
PARENT_SCOPE
)
endif()
string(TOLOWER "${PACKAGE}" lower_case_name)
set(${PACKAGE}_SOURCE_DIR
${${lower_case_name}_SOURCE_DIR}
PARENT_SCOPE
@@ -775,15 +874,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

@@ -3,8 +3,14 @@
int main(int argc, char** argv) {
cxxopts::Options options("MyProgram", "One line description of MyProgram");
options.add_options()("h,help", "Show help")(
"d,debug", "Enable debugging")("f,file", "File name", cxxopts::value<std::string>());
// clang-format off
options.add_options()
("h,help", "Show help")
("d,debug", "Enable debugging")
("f,file", "File name", cxxopts::value<std::string>()
);
// clang-format on
auto result = options.parse(argc, argv);

View File

@@ -0,0 +1,49 @@
include(${CPM_PATH}/CPM.cmake)
include(${CPM_PATH}/testing.cmake)
set(baseDir "${CMAKE_CURRENT_BINARY_DIR}/test_dirty_cache")
find_package(Git REQUIRED)
function(git_do dir)
execute_process(
COMMAND ${GIT_EXECUTABLE} -c user.name='User' -c user.email='user@email.org' ${ARGN}
RESULT_VARIABLE result
OUTPUT_VARIABLE status
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY "${dir}"
)
if(result)
message(FATAL_ERROR "git ${ARGN} fail: ${result} ${status}")
endif()
endfunction()
file(MAKE_DIRECTORY "${baseDir}")
file(WRITE "${baseDir}/draft.txt" "this is a test")
git_do("${baseDir}" init -b main)
git_do("${baseDir}" commit --allow-empty -m "empty repo")
message(STATUS "empty repo with file")
cpm_check_git_working_dir_is_clean(${baseDir} HEAD emptygit_test)
assert_falsy(emptygit_test)
git_do("${baseDir}" add draft.txt)
git_do("${baseDir}" commit -m "test change")
git_do("${baseDir}" tag v0.0.0)
message(STATUS "commit a change")
cpm_check_git_working_dir_is_clean(${baseDir} v0.0.0 onecommit_test)
assert_truthy(onecommit_test)
file(WRITE "${baseDir}/draft.txt" "a modification")
message(STATUS "dirty repo")
cpm_check_git_working_dir_is_clean(${baseDir} v0.0.0 nonemptygit_test)
assert_falsy(nonemptygit_test)
git_do("${baseDir}" add draft.txt)
git_do("${baseDir}" commit -m "another change")
message(STATUS "repo clean")
cpm_check_git_working_dir_is_clean(${baseDir} v0.0.0 twocommit_test)
assert_falsy(twocommit_test)
file(REMOVE_RECURSE "${baseDir}")

View File

@@ -0,0 +1,38 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
include(${CPM_PATH}/testing.cmake)
include(CMakePackageConfigHelpers)
set(CPM_SOURCE_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/CPM")
set(TEST_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/fetchcontent_dependency)
function(clear_cache)
message(STATUS "clearing CPM cache")
file(REMOVE_RECURSE ${CPM_SOURCE_CACHE_DIR})
assert_not_exists("${CPM_SOURCE_CACHE_DIR}")
endfunction()
function(update_cmake_lists)
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/fetchcontent_dependency/CMakeLists.txt.in"
"${CMAKE_CURRENT_LIST_DIR}/fetchcontent_dependency/CMakeLists.txt"
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/junk
)
endfunction()
function(reset_test)
clear_cache()
file(REMOVE_RECURSE ${TEST_BUILD_DIR})
update_cmake_lists()
endfunction()
# Read CPM_SOURCE_CACHE from arguments
reset_test()
execute_process(
COMMAND ${CMAKE_COMMAND} "-H${CMAKE_CURRENT_LIST_DIR}/fetchcontent_dependency"
"-B${TEST_BUILD_DIR}" "-DCPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}" RESULT_VARIABLE ret
)
assert_equal(${ret} "0")

View File

@@ -0,0 +1,2 @@
/CMakeLists.txt
/package-lock.cmake

View File

@@ -0,0 +1,38 @@
# ~~~
# ┌────────────────────────┐
# │ FetchContentDependency │
# └─────┬────────────┬─────┘
# │1. │3.
# │ │
# ┌────────▼────┐ ┌───▼─────────┐
# │ Dependency ├───► Fibonacci │
# └─────────────┘2. └─────────────┘
#
# 1. Add Project with CPMAddPackage
# 2. Dependency will add Fibonacci with FetchContent
# 3. Our project add Fibonacci with CPMAddPackage
# ~~~
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(CPMTest_FetchContentDependency)
# ---- Dependencies ----
include(@CPM_PATH@/CPM.cmake)
# 1 & 2 Dependency will add Fibonacci using FetchContent (1 & 2)
CPMAddPackage(NAME Dependency SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/dependency)
# 3 Add again Fibonacci that have already been populated with FetchContent_MakeAvailable
#
# * This test should highlight the fact that cpm_add_subdirectory is always called, even when
# cpm_fetch_package isn't populating the dependency
# * NO_CACHE YES highlight a bug introduced in 32b063eba5c754f833725ed4b9e5f352bc3ca959 where
# cpm_fetch_package was checking undefined ${lower_case_name}_POPULATED variable
CPMAddPackage(
NAME Fibonacci
GIT_REPOSITORY https://github.com/cpm-cmake/testpack-fibonacci.git
VERSION 2.0
NO_CACHE YES
)

View File

@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(CPMTest_Dependency)
# ---- Dependencies ----
include(FetchContent)
FetchContent_Declare(
Fibonacci
GIT_REPOSITORY https://github.com/cpm-cmake/testpack-fibonacci.git
GIT_TAG v2.0
)
FetchContent_MakeAvailable(Fibonacci)

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