mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-18 07:07:47 -05:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01b69aad82 | ||
|
|
775a235880 | ||
|
|
f8d4e959bb | ||
|
|
4c7aa36dff | ||
|
|
3a4516265c |
16
.github/workflows/macos.yml
vendored
Normal file
16
.github/workflows/macos.yml
vendored
Normal 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
23
.github/workflows/ubuntu.yml
vendored
Normal 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
16
.github/workflows/windows.yml
vendored
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
[](https://travis-ci.com/TheLartians/CPM.cmake)
|
||||
[](https://github.com/TheLartians/CPM.cmake/actions)
|
||||
[](https://github.com/TheLartians/CPM.cmake/actions)
|
||||
[](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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -23,7 +23,7 @@ CPMAddPackage(
|
||||
VERSION 1.8.1
|
||||
OPTIONS
|
||||
"INSTALL_GTEST OFF"
|
||||
"gtest_force_shared_crt ON"
|
||||
"gtest_force_shared_crt"
|
||||
)
|
||||
|
||||
# ---- Create binary ----
|
||||
|
||||
@@ -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)
|
||||
|
||||
19
test/unit/source_dir.cmake
Normal file
19
test/unit/source_dir.cmake
Normal 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
1
test/unit/source_dir/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/CMakeLists.txt
|
||||
20
test/unit/source_dir/CMakeLists.txt.in
Normal file
20
test/unit/source_dir/CMakeLists.txt.in
Normal 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()
|
||||
4
test/unit/source_dir/dependency/CMakeLists.txt
Normal file
4
test/unit/source_dir/dependency/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
function(dependency_function)
|
||||
message("called external method")
|
||||
endfunction()
|
||||
Reference in New Issue
Block a user