Compare commits

..

5 Commits
v0.15 ... v0.17

Author SHA1 Message Date
Lars Melchior
01b69aad82 add support for SOURCE_DIR argument (#97)
* add support for SOURCE_DIR argument

* simplify code

* add test

* update comment
2020-02-25 13:29:21 +01:00
Lars Melchior
775a235880 default to "ON" for options without explicit value definition (#96)
* default to "ON" for options without explicit value definition

* increment CPM version

* compare the correct lengths
2020-02-06 11:50:55 +01:00
Lars Melchior
f8d4e959bb abort when nested (bugfix) (#94)
* abort when nested (bugfix)

* update error message

* update error message
2019-10-25 20:52:22 +02:00
Lars Melchior
4c7aa36dff Update README.md 2019-10-25 16:01:47 +02:00
Lars Melchior
3a4516265c Add GitHub workflows (#93)
* add mac workflow

* rename and add windows and ubuntu workflows

* update tests

* update tests

* update travis
2019-10-24 18:14:58 +02:00
12 changed files with 135 additions and 26 deletions

16
.github/workflows/macos.yml vendored Normal file
View File

@@ -0,0 +1,16 @@
name: MacOS
on: [push]
jobs:
build:
runs-on: macOS-10.14
steps:
- uses: actions/checkout@v1
- name: run tests
run: |
cmake -Htest -Bbuild/test
cmake --build build/test --target test-verbose

23
.github/workflows/ubuntu.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: Ubuntu
on: [push]
jobs:
build:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- name: install updates
run: |
wget -O cmake.sh https://cmake.org/files/v3.14/cmake-3.14.0-Linux-x86_64.sh
sudo sh cmake.sh --skip-license --exclude-subdir --prefix=/usr/local
export PATH=/usr/local/bin:$PATH
cmake --version
- name: run tests
run: |
cmake -Htest -Bbuild/test
cmake --build build/test --target test-verbose

16
.github/workflows/windows.yml vendored Normal file
View File

@@ -0,0 +1,16 @@
name: Windows
on: [push]
jobs:
build:
runs-on: windows-2019
steps:
- uses: actions/checkout@v1
- name: run tests
run: |
cmake -Htest -Bbuild/test
cmake --build build/test --target test-verbose

View File

@@ -45,6 +45,6 @@ before_install:
script:
# unit tests
- cmake -Htest -Bbuild/test
- CTEST_OUTPUT_ON_FAILURE=1 cmake --build build/test --target test
- cmake --build build/test --target test-verbose
# build examples
- python3 examples/build_all.py

View File

@@ -1,4 +1,7 @@
[![Build Status](https://travis-ci.com/TheLartians/CPM.cmake.svg?branch=master)](https://travis-ci.com/TheLartians/CPM.cmake)
[![Actions Status](https://github.com/TheLartians/CPM.cmake/workflows/MacOS/badge.svg)](https://github.com/TheLartians/CPM.cmake/actions)
[![Actions Status](https://github.com/TheLartians/CPM.cmake/workflows/Windows/badge.svg)](https://github.com/TheLartians/CPM.cmake/actions)
[![Actions Status](https://github.com/TheLartians/CPM.cmake/workflows/Ubuntu/badge.svg)](https://github.com/TheLartians/CPM.cmake/actions)
<p align="center">
<img src="./logo/CPM.png" height="100" />
@@ -104,8 +107,8 @@ Dependencies using CPM will automatically use the updated script of the outermos
- **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 resolved by adding a new version of the dependency in the outermost project.
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 `CPMFindPackages` should work with external package managers.
This can also be enabled for all CPM dependencies by enabling [`CPM_USE_LOCAL_PACKAGES`](#cpmuselocalpackages).
Dependencies added with `CPMFindPackage` should work with external package managers.
Additionally, the option [`CPM_USE_LOCAL_PACKAGES`](#cpmuselocalpackages) will enable `find_package` for all CPM dependencies.
## Options

View File

@@ -28,17 +28,18 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
set(CURRENT_CPM_VERSION 0.15)
set(CURRENT_CPM_VERSION 0.17)
if(CPM_DIRECTORY)
if(NOT ${CPM_DIRECTORY} MATCHES ${CMAKE_CURRENT_LIST_DIR})
if (${CPM_VERSION} VERSION_LESS ${CURRENT_CPM_VERSION})
message(AUTHOR_WARNING "${CPM_INDENT} \
A dependency is using a more recent CPM (${NEW_CPM_VERSION}) than the current project (${CPM_VERSION}). \
A dependency is using a more recent CPM version (${CURRENT_CPM_VERSION}) than the current project (${CPM_VERSION}). \
It is recommended to upgrade CPM to the most recent version. \
See https://github.com/TheLartians/CPM for more information."
See https://github.com/TheLartians/CPM.cmake for more information."
)
endif()
return()
endif()
endif()
@@ -207,22 +208,22 @@ function(CPMAddPackage)
if (DEFINED CPM_ARGS_DOWNLOAD_COMMAND)
set(FETCH_CONTENT_DECLARE_EXTRA_OPTS DOWNLOAD_COMMAND ${CPM_ARGS_DOWNLOAD_COMMAND})
else()
if (CPM_SOURCE_CACHE AND NOT DEFINED CPM_ARGS_SOURCE_DIR)
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})
list(APPEND FETCH_CONTENT_DECLARE_EXTRA_OPTS SOURCE_DIR ${download_directory})
if (EXISTS ${download_directory})
list(APPEND FETCH_CONTENT_DECLARE_EXTRA_OPTS DOWNLOAD_COMMAND ":")
set(PACKAGE_INFO "${download_directory}")
else()
# remove timestamps so CMake will re-download the dependency
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/_deps/${lower_case_name}-subbuild)
set(PACKAGE_INFO "${PACKAGE_INFO} -> ${download_directory}")
endif()
elseif(DEFINED CPM_ARGS_SOURCE_DIR)
set(FETCH_CONTENT_DECLARE_EXTRA_OPTS SOURCE_DIR ${CPM_ARGS_SOURCE_DIR})
elseif (CPM_SOURCE_CACHE)
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})
list(APPEND FETCH_CONTENT_DECLARE_EXTRA_OPTS SOURCE_DIR ${download_directory})
if (EXISTS ${download_directory})
list(APPEND FETCH_CONTENT_DECLARE_EXTRA_OPTS DOWNLOAD_COMMAND ":")
set(PACKAGE_INFO "${download_directory}")
else()
# remove timestamps so CMake will re-download the dependency
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/_deps/${lower_case_name}-subbuild)
set(PACKAGE_INFO "${PACKAGE_INFO} -> ${download_directory}")
endif()
endif()
@@ -302,9 +303,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)
math(EXPR OPTION_KEY_LENGTH "${OPTION_KEY_LENGTH}+1")
string(SUBSTRING ${OPTION} "${OPTION_KEY_LENGTH}" "-1" OPTION_VALUE)
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)
endif()
set(OPTION_KEY "${OPTION_KEY}" PARENT_SCOPE)
set(OPTION_VALUE "${OPTION_VALUE}" PARENT_SCOPE)
endfunction()

View File

@@ -23,7 +23,7 @@ CPMAddPackage(
VERSION 1.8.1
OPTIONS
"INSTALL_GTEST OFF"
"gtest_force_shared_crt ON"
"gtest_force_shared_crt"
)
# ---- Create binary ----

View File

@@ -14,4 +14,4 @@ foreach(test ${tests})
)
endforeach()
add_custom_target(test-verbose COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
add_custom_target(test-verbose COMMAND ${CMAKE_CTEST_COMMAND} -C Debug --verbose)

View File

@@ -0,0 +1,19 @@
include(CMakePackageConfigHelpers)
include(${CPM_PATH}/testing.cmake)
set(TEST_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/source_dir)
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/source_dir/CMakeLists.txt.in"
"${CMAKE_CURRENT_LIST_DIR}/source_dir/CMakeLists.txt"
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/junk
)
execute_process(
COMMAND
${CMAKE_COMMAND} "-H${CMAKE_CURRENT_LIST_DIR}/source_dir" "-B${TEST_BUILD_DIR}"
RESULT_VARIABLE ret
)
ASSERT_EQUAL(${ret} "0")

1
test/unit/source_dir/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/CMakeLists.txt

View File

@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(CPMExampleCatch2)
# ---- Options ----
option(ENABLE_TEST_COVERAGE "Enable test coverage" OFF)
# ---- Dependencies ----
include(@CPM_PATH@/CPM.cmake)
CPMAddPackage(
NAME Dependency
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/dependency
)
# ---- Call dependency method to validate correct addition of directory ----
dependency_function()

View File

@@ -0,0 +1,4 @@
function(dependency_function)
message("called external method")
endfunction()