mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-20 13:17:53 -05:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12daf366c7 | ||
|
|
0938e8fde7 | ||
|
|
09b056ae20 | ||
|
|
d34d2a8730 | ||
|
|
6fc2170d5d | ||
|
|
1184a6e6e7 | ||
|
|
c53417bd65 | ||
|
|
50e9b9edb8 |
@@ -34,6 +34,7 @@ parse:
|
||||
HTTP_USERNAME: 1
|
||||
HTTP_PASSWORD: 1
|
||||
EXCLUDE_FROM_ALL: 1
|
||||
SYSTEM: 1
|
||||
SOURCE_SUBDIR: 1
|
||||
OPTIONS: +
|
||||
cpmfindpackage:
|
||||
|
||||
@@ -12,7 +12,7 @@ jobs:
|
||||
gcc:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- name: build all
|
||||
env:
|
||||
CC: gcc
|
||||
@@ -22,7 +22,7 @@ jobs:
|
||||
clang:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- name: build all
|
||||
env:
|
||||
CC: clang
|
||||
2
.github/workflows/publish.yaml
vendored
2
.github/workflows/publish.yaml
vendored
@@ -10,7 +10,7 @@ jobs:
|
||||
name: Publish CPM.cmake
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set CPM version by tag
|
||||
run: |
|
||||
|
||||
@@ -14,7 +14,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup cmake
|
||||
uses: jwlawson/actions-setup-cmake@v1.13
|
||||
with:
|
||||
cmake-version: '3.25.x'
|
||||
|
||||
- name: Install format dependencies
|
||||
run: pip3 install clang-format==14.0.6 cmake_format==0.6.11 pyyaml
|
||||
@@ -20,7 +20,12 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: clone
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup cmake
|
||||
uses: jwlawson/actions-setup-cmake@v1.13
|
||||
with:
|
||||
cmake-version: '3.25.x'
|
||||
|
||||
- name: unit tests
|
||||
run: |
|
||||
24
README.md
24
README.md
@@ -37,10 +37,10 @@ include(cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage("gh:fmtlib/fmt#7.1.3")
|
||||
CPMAddPackage("gh:nlohmann/json@3.10.5")
|
||||
CPMAddPackage("gh:catchorg/Catch2@2.5.0")
|
||||
CPMAddPackage("gh:catchorg/Catch2@3.2.1")
|
||||
|
||||
# link dependencies
|
||||
target_link_libraries(main fmt::fmt nlohmann_json::nlohmann_json Catch2::Catch2)
|
||||
target_link_libraries(main fmt::fmt nlohmann_json::nlohmann_json Catch2::Catch2WithMain)
|
||||
```
|
||||
|
||||
See the [examples directory](https://github.com/cpm-cmake/CPM.cmake/tree/master/examples) for complete examples with source code and check [below](#snippets) or in the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/More-Snippets) for example snippets.
|
||||
@@ -68,6 +68,10 @@ On the other hand, if `VERSION` hasn't been explicitly specified, CPM can automa
|
||||
|
||||
If an additional optional parameter `EXCLUDE_FROM_ALL` is set to a truthy value, then any targets defined inside the dependency won't be built by default. See the [CMake docs](https://cmake.org/cmake/help/latest/prop_tgt/EXCLUDE_FROM_ALL.html) for details.
|
||||
|
||||
If an additional optional parameter `SYSTEM` is set to a truthy value, the SYSTEM directory property of the subdirectory added will be set to true.
|
||||
See the [add_subdirectory ](https://cmake.org/cmake/help/latest/command/add_subdirectory.html?highlight=add_subdirectory)
|
||||
and [SYSTEM](https://cmake.org/cmake/help/latest/prop_tgt/SYSTEM.html#prop_tgt:SYSTEM) target property for details.
|
||||
|
||||
A single-argument compact syntax is also supported:
|
||||
|
||||
```cmake
|
||||
@@ -308,6 +312,18 @@ If you know others, feel free to add them here through a PR.
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="https://github.com/jhasse/jngl">
|
||||
<p align="center">
|
||||
<img src="https://github.com/jhasse/jngl/raw/master/doc/jngl-logo.svg" alt="JNGL" width="100pt" />
|
||||
</p>
|
||||
<p align="center"><b>JNGL - easy to use cross-platform 2D game library</b></p>
|
||||
</a>
|
||||
</td>
|
||||
<td/>
|
||||
<td/>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## Snippets
|
||||
@@ -353,9 +369,9 @@ CPMAddPackage(
|
||||
# using `CPM_SOURCE_CACHE` is strongly recommended
|
||||
CPMAddPackage(
|
||||
NAME Boost
|
||||
VERSION 1.77.0
|
||||
VERSION 1.81.0
|
||||
GITHUB_REPOSITORY "boostorg/boost"
|
||||
GIT_TAG "boost-1.77.0"
|
||||
GIT_TAG "boost-1.81.0"
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
105
cmake/CPM.cmake
105
cmake/CPM.cmake
@@ -28,6 +28,20 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
# Initialize logging prefix
|
||||
if(NOT CPM_INDENT)
|
||||
set(CPM_INDENT
|
||||
"CPM:"
|
||||
CACHE INTERNAL ""
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT COMMAND cpm_message)
|
||||
function(cpm_message)
|
||||
message(${ARGV})
|
||||
endfunction()
|
||||
endif()
|
||||
|
||||
set(CURRENT_CPM_VERSION 1.0.0-development-version)
|
||||
|
||||
get_filename_component(CPM_CURRENT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
|
||||
@@ -59,7 +73,8 @@ See https://github.com/cpm-cmake/CPM.cmake for more information."
|
||||
endif()
|
||||
|
||||
if(CURRENT_CPM_VERSION MATCHES "development-version")
|
||||
message(WARNING "Your project is using an unstable development version of CPM.cmake. \
|
||||
message(
|
||||
WARNING "${CPM_INDENT} 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."
|
||||
)
|
||||
@@ -223,14 +238,6 @@ function(cpm_package_name_and_ver_from_url url outName outVer)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Initialize logging prefix
|
||||
if(NOT CPM_INDENT)
|
||||
set(CPM_INDENT
|
||||
"CPM:"
|
||||
CACHE INTERNAL ""
|
||||
)
|
||||
endif()
|
||||
|
||||
function(cpm_find_package NAME VERSION)
|
||||
string(REPLACE " " ";" EXTRA_ARGS "${ARGN}")
|
||||
find_package(${NAME} ${VERSION} ${EXTRA_ARGS} QUIET)
|
||||
@@ -238,7 +245,7 @@ function(cpm_find_package NAME VERSION)
|
||||
if(DEFINED ${CPM_ARGS_NAME}_VERSION)
|
||||
set(VERSION ${${CPM_ARGS_NAME}_VERSION})
|
||||
endif()
|
||||
message(STATUS "${CPM_INDENT} using local package ${CPM_ARGS_NAME}@${VERSION}")
|
||||
cpm_message(STATUS "${CPM_INDENT} Using local package ${CPM_ARGS_NAME}@${VERSION}")
|
||||
CPMRegisterPackage(${CPM_ARGS_NAME} "${VERSION}")
|
||||
set(CPM_PACKAGE_FOUND
|
||||
YES
|
||||
@@ -309,7 +316,7 @@ function(cpm_check_if_package_already_added CPM_ARGS_NAME CPM_ARGS_VERSION)
|
||||
if("${CPM_PACKAGE_VERSION}" VERSION_LESS "${CPM_ARGS_VERSION}")
|
||||
message(
|
||||
WARNING
|
||||
"${CPM_INDENT} requires a newer version of ${CPM_ARGS_NAME} (${CPM_ARGS_VERSION}) than currently included (${CPM_PACKAGE_VERSION})."
|
||||
"${CPM_INDENT} Requires a newer version of ${CPM_ARGS_NAME} (${CPM_ARGS_VERSION}) than currently included (${CPM_PACKAGE_VERSION})."
|
||||
)
|
||||
endif()
|
||||
cpm_get_fetch_properties(${CPM_ARGS_NAME})
|
||||
@@ -366,7 +373,7 @@ function(cpm_parse_add_package_single_arg arg outArgs)
|
||||
set(packageType "git")
|
||||
else()
|
||||
# Give up
|
||||
message(FATAL_ERROR "CPM: Can't determine package type of '${arg}'")
|
||||
message(FATAL_ERROR "${CPM_INDENT} Can't determine package type of '${arg}'")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -386,7 +393,7 @@ function(cpm_parse_add_package_single_arg arg outArgs)
|
||||
else()
|
||||
# We should never get here. This is an assertion and hitting it means there's a bug in the code
|
||||
# above. A packageType was set, but not handled by this if-else.
|
||||
message(FATAL_ERROR "CPM: Unsupported package type '${packageType}' of '${arg}'")
|
||||
message(FATAL_ERROR "${CPM_INDENT} Unsupported package type '${packageType}' of '${arg}'")
|
||||
endif()
|
||||
|
||||
set(${outArgs}
|
||||
@@ -419,7 +426,7 @@ function(cpm_check_git_working_dir_is_clean repoPath gitTag isClean)
|
||||
)
|
||||
if(resultGitStatus)
|
||||
# not supposed to happen, assume clean anyway
|
||||
message(WARNING "Calling git status on folder ${repoPath} failed")
|
||||
message(WARNING "${CPM_INDENT} Calling git status on folder ${repoPath} failed")
|
||||
set(${isClean}
|
||||
TRUE
|
||||
PARENT_SCOPE
|
||||
@@ -464,7 +471,7 @@ endfunction()
|
||||
function(cpm_override_fetchcontent contentName)
|
||||
cmake_parse_arguments(PARSE_ARGV 1 arg "" "SOURCE_DIR;BINARY_DIR" "")
|
||||
if(NOT "${arg_UNPARSED_ARGUMENTS}" STREQUAL "")
|
||||
message(FATAL_ERROR "Unsupported arguments: ${arg_UNPARSED_ARGUMENTS}")
|
||||
message(FATAL_ERROR "${CPM_INDENT} Unsupported arguments: ${arg_UNPARSED_ARGUMENTS}")
|
||||
endif()
|
||||
|
||||
string(TOLOWER ${contentName} contentNameLower)
|
||||
@@ -506,8 +513,8 @@ function(CPMAddPackage)
|
||||
if(argnLength EQUAL 1)
|
||||
cpm_parse_add_package_single_arg("${ARGN}" ARGN)
|
||||
|
||||
# The shorthand syntax implies EXCLUDE_FROM_ALL
|
||||
set(ARGN "${ARGN};EXCLUDE_FROM_ALL;YES")
|
||||
# The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM
|
||||
set(ARGN "${ARGN};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;")
|
||||
endif()
|
||||
|
||||
set(oneValueArgs
|
||||
@@ -524,6 +531,7 @@ function(CPMAddPackage)
|
||||
DOWNLOAD_COMMAND
|
||||
FIND_PACKAGE_ARGUMENTS
|
||||
NO_CACHE
|
||||
SYSTEM
|
||||
GIT_SHALLOW
|
||||
EXCLUDE_FROM_ALL
|
||||
SOURCE_SUBDIR
|
||||
@@ -600,7 +608,7 @@ function(CPMAddPackage)
|
||||
if(NOT DEFINED CPM_ARGS_NAME)
|
||||
message(
|
||||
FATAL_ERROR
|
||||
"CPM: 'NAME' was not provided and couldn't be automatically inferred for package added with arguments: '${ARGN}'"
|
||||
"${CPM_INDENT} 'NAME' was not provided and couldn't be automatically inferred for package added with arguments: '${ARGN}'"
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -619,6 +627,7 @@ function(CPMAddPackage)
|
||||
NAME "${CPM_ARGS_NAME}"
|
||||
SOURCE_DIR "${PACKAGE_SOURCE}"
|
||||
EXCLUDE_FROM_ALL "${CPM_ARGS_EXCLUDE_FROM_ALL}"
|
||||
SYSTEM "${CPM_ARGS_SYSTEM}"
|
||||
OPTIONS "${CPM_ARGS_OPTIONS}"
|
||||
SOURCE_SUBDIR "${CPM_ARGS_SOURCE_SUBDIR}"
|
||||
DOWNLOAD_ONLY "${DOWNLOAD_ONLY}"
|
||||
@@ -650,7 +659,7 @@ function(CPMAddPackage)
|
||||
if(CPM_LOCAL_PACKAGES_ONLY)
|
||||
message(
|
||||
SEND_ERROR
|
||||
"CPM: ${CPM_ARGS_NAME} not found via find_package(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION})"
|
||||
"${CPM_INDENT} ${CPM_ARGS_NAME} not found via find_package(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION})"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
@@ -705,7 +714,16 @@ function(CPMAddPackage)
|
||||
# relative paths.
|
||||
get_filename_component(download_directory ${download_directory} ABSOLUTE)
|
||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${download_directory})
|
||||
|
||||
if(CPM_SOURCE_CACHE)
|
||||
file(LOCK ${download_directory}/../cmake.lock)
|
||||
endif()
|
||||
|
||||
if(EXISTS ${download_directory})
|
||||
if(CPM_SOURCE_CACHE)
|
||||
file(LOCK ${download_directory}/../cmake.lock RELEASE)
|
||||
endif()
|
||||
|
||||
cpm_store_fetch_properties(
|
||||
${CPM_ARGS_NAME} "${download_directory}"
|
||||
"${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build"
|
||||
@@ -716,14 +734,20 @@ function(CPMAddPackage)
|
||||
# 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")
|
||||
message(
|
||||
WARNING "${CPM_INDENT} 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}"
|
||||
"${CPM_ARGS_EXCLUDE_FROM_ALL}" "${CPM_ARGS_OPTIONS}"
|
||||
"${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_SYSTEM}"
|
||||
"${CPM_ARGS_OPTIONS}"
|
||||
)
|
||||
set(PACKAGE_INFO "${PACKAGE_INFO} at ${download_directory}")
|
||||
|
||||
@@ -762,8 +786,8 @@ function(CPMAddPackage)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message(
|
||||
STATUS "${CPM_INDENT} adding package ${CPM_ARGS_NAME}@${CPM_ARGS_VERSION} (${PACKAGE_INFO})"
|
||||
cpm_message(
|
||||
STATUS "${CPM_INDENT} Adding package ${CPM_ARGS_NAME}@${CPM_ARGS_VERSION} (${PACKAGE_INFO})"
|
||||
)
|
||||
|
||||
if(NOT CPM_SKIP_FETCH)
|
||||
@@ -771,11 +795,18 @@ function(CPMAddPackage)
|
||||
"${CPM_ARGS_NAME}" "${CPM_ARGS_VERSION}" "${PACKAGE_INFO}" "${CPM_ARGS_UNPARSED_ARGUMENTS}"
|
||||
)
|
||||
cpm_fetch_package("${CPM_ARGS_NAME}" populated)
|
||||
if(CPM_CACHE_SOURCE AND download_directory)
|
||||
file(LOCK ${download_directory}/../cmake.lock RELEASE)
|
||||
endif()
|
||||
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}"
|
||||
"${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_SYSTEM}"
|
||||
"${CPM_ARGS_OPTIONS}"
|
||||
)
|
||||
endif()
|
||||
cpm_get_fetch_properties("${CPM_ARGS_NAME}")
|
||||
@@ -790,7 +821,7 @@ macro(CPMGetPackage Name)
|
||||
if(DEFINED "CPM_DECLARATION_${Name}")
|
||||
CPMAddPackage(NAME ${Name})
|
||||
else()
|
||||
message(SEND_ERROR "Cannot retrieve package ${Name}: no declaration available")
|
||||
message(SEND_ERROR "${CPM_INDENT} Cannot retrieve package ${Name}: no declaration available")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
@@ -880,7 +911,7 @@ endfunction()
|
||||
# declares a package in FetchContent_Declare
|
||||
function(cpm_declare_fetch PACKAGE VERSION INFO)
|
||||
if(${CPM_DRY_RUN})
|
||||
message(STATUS "${CPM_INDENT} package not declared (dry run)")
|
||||
cpm_message(STATUS "${CPM_INDENT} Package not declared (dry run)")
|
||||
return()
|
||||
endif()
|
||||
|
||||
@@ -926,13 +957,18 @@ function(
|
||||
SOURCE_DIR
|
||||
BINARY_DIR
|
||||
EXCLUDE
|
||||
SYSTEM
|
||||
OPTIONS
|
||||
)
|
||||
|
||||
if(NOT DOWNLOAD_ONLY AND EXISTS ${SOURCE_DIR}/CMakeLists.txt)
|
||||
set(addSubdirectoryExtraArgs "")
|
||||
if(EXCLUDE)
|
||||
set(addSubdirectoryExtraArgs EXCLUDE_FROM_ALL)
|
||||
else()
|
||||
set(addSubdirectoryExtraArgs "")
|
||||
list(APPEND addSubdirectoryExtraArgs EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
if("${SYSTEM}" AND "${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.25")
|
||||
# https://cmake.org/cmake/help/latest/prop_dir/SYSTEM.html#prop_dir:SYSTEM
|
||||
list(APPEND addSubdirectoryExtraArgs SYSTEM)
|
||||
endif()
|
||||
if(OPTIONS)
|
||||
foreach(OPTION ${OPTIONS})
|
||||
@@ -955,7 +991,7 @@ function(cpm_fetch_package PACKAGE populated)
|
||||
PARENT_SCOPE
|
||||
)
|
||||
if(${CPM_DRY_RUN})
|
||||
message(STATUS "${CPM_INDENT} package ${PACKAGE} not fetched (dry run)")
|
||||
cpm_message(STATUS "${CPM_INDENT} Package ${PACKAGE} not fetched (dry run)")
|
||||
return()
|
||||
endif()
|
||||
|
||||
@@ -1063,6 +1099,7 @@ function(cpm_prettify_package_arguments OUT_VAR IS_IN_COMMENT)
|
||||
DOWNLOAD_COMMAND
|
||||
FIND_PACKAGE_ARGUMENTS
|
||||
NO_CACHE
|
||||
SYSTEM
|
||||
GIT_SHALLOW
|
||||
)
|
||||
set(multiValueArgs OPTIONS)
|
||||
|
||||
@@ -10,12 +10,23 @@ endif()
|
||||
|
||||
# Expand relative path. This is important if the provided path contains a tilde (~)
|
||||
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
|
||||
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
|
||||
|
||||
function(download_cpm)
|
||||
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
|
||||
file(DOWNLOAD
|
||||
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
|
||||
${CPM_DOWNLOAD_LOCATION}
|
||||
)
|
||||
endfunction()
|
||||
|
||||
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
|
||||
download_cpm()
|
||||
else()
|
||||
# resume download if it previously failed
|
||||
file(READ ${CPM_DOWNLOAD_LOCATION} check)
|
||||
if("${check}" STREQUAL "")
|
||||
download_cpm()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(${CPM_DOWNLOAD_LOCATION})
|
||||
|
||||
@@ -11,7 +11,7 @@ CPMAddPackage("gh:cpm-cmake/testpack-fibonacci@2.0")
|
||||
CPMAddPackage(
|
||||
NAME benchmark
|
||||
GITHUB_REPOSITORY google/benchmark
|
||||
VERSION 1.5.2
|
||||
VERSION 1.7.1
|
||||
OPTIONS "BENCHMARK_ENABLE_TESTING Off"
|
||||
)
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ include(../../cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME Boost
|
||||
VERSION 1.77.0
|
||||
VERSION 1.81.0
|
||||
GITHUB_REPOSITORY "boostorg/boost"
|
||||
GIT_TAG "boost-1.77.0"
|
||||
GIT_TAG "boost-1.81.0"
|
||||
)
|
||||
|
||||
target_link_libraries(CPMExampleBoost PRIVATE Boost::asio)
|
||||
|
||||
@@ -7,12 +7,12 @@ project(CPMExampleCatch2)
|
||||
include(../../cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage("gh:cpm-cmake/testpack-fibonacci@2.0")
|
||||
CPMAddPackage("gh:catchorg/Catch2@2.13.4")
|
||||
CPMAddPackage("gh:catchorg/Catch2@3.2.1")
|
||||
|
||||
# ---- Create binary ----
|
||||
|
||||
add_executable(CPMExampleCatch2 main.cpp)
|
||||
target_link_libraries(CPMExampleCatch2 fibonacci Catch2)
|
||||
target_link_libraries(CPMExampleCatch2 fibonacci Catch2::Catch2WithMain)
|
||||
target_compile_features(CPMExampleCatch2 PRIVATE cxx_std_17)
|
||||
|
||||
# ---- Enable testing ----
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
|
||||
#include <fibonacci.h>
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("fibonacci") {
|
||||
REQUIRE(fibonacci(0) == 0);
|
||||
|
||||
@@ -7,7 +7,7 @@ project(CPMExampleDoctest)
|
||||
include(../../cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage("gh:cpm-cmake/testpack-fibonacci@2.0")
|
||||
CPMAddPackage("gh:onqtam/doctest#2.4.5")
|
||||
CPMAddPackage("gh:onqtam/doctest@2.4.9")
|
||||
|
||||
# ---- Create binary ----
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ CPMAddPackage("gh:cpm-cmake/testpack-fibonacci@2.0")
|
||||
CPMAddPackage(
|
||||
NAME googletest
|
||||
GITHUB_REPOSITORY google/googletest
|
||||
GIT_TAG release-1.10.0
|
||||
VERSION 1.10.0
|
||||
GIT_TAG release-1.12.1
|
||||
VERSION 1.12.1
|
||||
OPTIONS "INSTALL_GTEST OFF" "gtest_force_shared_crt"
|
||||
)
|
||||
|
||||
|
||||
@@ -15,29 +15,16 @@ CPMAddPackage(
|
||||
|
||||
if(lua_ADDED)
|
||||
# lua has no CMakeLists, so we create our own target
|
||||
|
||||
file(GLOB lua_sources ${lua_SOURCE_DIR}/*.c)
|
||||
list(REMOVE_ITEM lua_sources "${lua_SOURCE_DIR}/lua.c" "${lua_SOURCE_DIR}/luac.c")
|
||||
add_library(lua STATIC ${lua_sources})
|
||||
|
||||
target_include_directories(lua SYSTEM PUBLIC $<BUILD_INTERFACE:${lua_SOURCE_DIR}>)
|
||||
endif()
|
||||
|
||||
CPMAddPackage(
|
||||
NAME sol2
|
||||
URL https://github.com/ThePhD/sol2/archive/v3.0.2.zip
|
||||
VERSION 3.0.2
|
||||
DOWNLOAD_ONLY YES
|
||||
)
|
||||
|
||||
if(sol2_ADDED)
|
||||
add_library(sol2 INTERFACE IMPORTED)
|
||||
target_include_directories(sol2 SYSTEM INTERFACE ${sol2_SOURCE_DIR}/include)
|
||||
target_link_libraries(sol2 INTERFACE lua)
|
||||
endif()
|
||||
CPMAddPackage("gh:ThePhD/sol2@3.3.0")
|
||||
|
||||
# ---- Executable ----
|
||||
|
||||
add_executable(CPMSol2Example main.cpp)
|
||||
target_compile_features(CPMSol2Example PRIVATE cxx_std_17)
|
||||
target_link_libraries(CPMSol2Example sol2)
|
||||
target_link_libraries(CPMSol2Example sol2 lua)
|
||||
|
||||
@@ -8,6 +8,20 @@ include(../../cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage("gh:gabime/spdlog@1.8.2")
|
||||
|
||||
# spdlog uses fmt and bundles that dependency. If you want to use fmt in your project as well, you
|
||||
# can let spdlog re-use fmt from CPM.cmake like this:
|
||||
#
|
||||
# cmake-format: off
|
||||
#
|
||||
# CPMAddPackage("gh:fmtlib/fmt#7.1.3")
|
||||
# CPMAddPackage(
|
||||
# GITHUB_REPOSITORY gabime/spdlog
|
||||
# VERSION 1.8.2
|
||||
# OPTIONS "SPDLOG_FMT_EXTERNAL 1"
|
||||
# )
|
||||
#
|
||||
# cmake-format: on
|
||||
|
||||
# ---- Executable ----
|
||||
|
||||
add_executable(CPMSpdlogExample main.cpp)
|
||||
|
||||
@@ -157,6 +157,11 @@ class IntegrationTest < Test::Unit::TestCase
|
||||
assert_block(msg) { res.status.success? }
|
||||
end
|
||||
|
||||
def assert_failure(res)
|
||||
msg = build_message(nil, "command status was expected to be a failure, but succeeded")
|
||||
assert_block(msg) { !res.status.success? }
|
||||
end
|
||||
|
||||
def assert_same_path(a, b)
|
||||
msg = build_message(nil, "<?> expected but was\n<?>", a, b)
|
||||
assert_block(msg) { File.identical? a, b }
|
||||
@@ -180,19 +185,20 @@ class IntegrationTest < Test::Unit::TestCase
|
||||
@@test_dir
|
||||
end
|
||||
|
||||
def make_project(template_dir = nil)
|
||||
def make_project(name: nil, from_template: nil)
|
||||
test_name = local_name
|
||||
test_name = test_name[5..] if test_name.start_with?('test_')
|
||||
|
||||
base = File.join(cur_test_dir, test_name)
|
||||
base += "-#{name}" if name
|
||||
src_dir = base + '-src'
|
||||
|
||||
FileUtils.mkdir_p src_dir
|
||||
|
||||
if template_dir
|
||||
template_dir = File.join(TestLib::TEMPLATES_DIR, template_dir)
|
||||
raise "#{template_dir} is not a directory" if !File.directory?(template_dir)
|
||||
FileUtils.copy_entry template_dir, src_dir
|
||||
if from_template
|
||||
from_template = File.join(TestLib::TEMPLATES_DIR, from_template)
|
||||
raise "#{from_template} is not a directory" if !File.directory?(from_template)
|
||||
FileUtils.copy_entry from_template, src_dir
|
||||
end
|
||||
|
||||
Project.new src_dir, base + '-bin'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Integration Test Framework Refernce
|
||||
# Integration Test Framework Reference
|
||||
|
||||
## `TestLib`
|
||||
|
||||
@@ -60,6 +60,7 @@ The class which must be a parent of all integration test case classes. It itself
|
||||
### Utils
|
||||
|
||||
* `cur_test_dir` - the directory of the current test case. A subdirectory of `TestLib::TMP_DIR`
|
||||
* `make_project(template_dir = nil)` - create a project from a test method. Will create a the project's source and binary directories as subdirectories of `cur_test_dir`.
|
||||
* Optionally work with a template directory, in which case it will copy the contents of the template directory (one from `templates`) in the project's source directory.
|
||||
* `make_project(name: nil, from_template: nil)` - create a project from a test method. Will create the project's source and binary directories as subdirectories of `cur_test_dir`.
|
||||
* Optionally provide a name which will be concatenated to the project directory. This allows creating multiple projects in a test
|
||||
* Optionally work with a template, in which case it will copy the contents of the template directory (one from `templates`) in the project's source directory.
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ require_relative './lib'
|
||||
class Basics < IntegrationTest
|
||||
# Test cpm caches with no cpm-related env vars
|
||||
def test_cpm_default
|
||||
prj = make_project 'no-deps'
|
||||
prj = make_project from_template: 'no-deps'
|
||||
prj.create_lists_from_default_template
|
||||
assert_success prj.configure
|
||||
|
||||
@@ -38,7 +38,7 @@ class Basics < IntegrationTest
|
||||
def test_env_cpm_source_cache
|
||||
ENV['CPM_SOURCE_CACHE'] = cur_test_dir
|
||||
|
||||
prj = make_project 'no-deps'
|
||||
prj = make_project from_template: 'no-deps'
|
||||
prj.create_lists_from_default_template
|
||||
assert_success prj.configure
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ class FetchContentCompatibility < IntegrationTest
|
||||
end
|
||||
|
||||
def test_add_dependency_cpm_and_fetchcontent
|
||||
prj = make_project 'using-adder'
|
||||
|
||||
prj = make_project from_template: 'using-adder'
|
||||
|
||||
prj.create_lists_from_default_template package: <<~PACK
|
||||
CPMAddPackage(
|
||||
NAME testpack-adder
|
||||
|
||||
21
test/integration/test_parallelism.rb
Normal file
21
test/integration/test_parallelism.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
require_relative './lib'
|
||||
|
||||
class Parallelism < IntegrationTest
|
||||
def setup
|
||||
@cache_dir = File.join(cur_test_dir, 'cpmcache')
|
||||
ENV['CPM_SOURCE_CACHE'] = @cache_dir
|
||||
end
|
||||
|
||||
def test_populate_cache_in_parallel
|
||||
4.times.map { |i|
|
||||
prj = make_project name: i.to_s, from_template: 'using-fibadder'
|
||||
prj.create_lists_from_default_template package: 'CPMAddPackage("gh:cpm-cmake/testpack-fibadder@1.0.0")'
|
||||
prj
|
||||
}.map { |prj|
|
||||
Thread.new do
|
||||
assert_success prj.configure
|
||||
assert_success prj.build
|
||||
end
|
||||
}.map(&:join)
|
||||
end
|
||||
end
|
||||
@@ -2,8 +2,8 @@ require_relative './lib'
|
||||
|
||||
class RemoveSourceDir < IntegrationTest
|
||||
def test_remove_source_dir
|
||||
prj = make_project 'using-adder'
|
||||
|
||||
prj = make_project from_template: 'using-adder'
|
||||
|
||||
prj.create_lists_from_default_template package: <<~PACK
|
||||
CPMAddPackage(
|
||||
NAME testpack-adder
|
||||
|
||||
@@ -4,7 +4,7 @@ class Simple < IntegrationTest
|
||||
ADDER_PACKAGE_NAME = 'testpack-adder'
|
||||
|
||||
def test_update_single_package
|
||||
prj = make_project 'using-adder'
|
||||
prj = make_project from_template: 'using-adder'
|
||||
adder_cache0 = nil
|
||||
adder_ver_file = nil
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class SourceCache < IntegrationTest
|
||||
end
|
||||
|
||||
def test_add_remove_dependency
|
||||
prj = make_project 'using-fibadder'
|
||||
prj = make_project from_template: 'using-fibadder'
|
||||
|
||||
###################################
|
||||
# create
|
||||
@@ -45,7 +45,7 @@ class SourceCache < IntegrationTest
|
||||
end
|
||||
|
||||
def test_second_project
|
||||
prj = make_project 'using-fibadder'
|
||||
prj = make_project from_template: 'using-fibadder'
|
||||
prj.create_lists_from_default_template package: 'CPMAddPackage("gh:cpm-cmake/testpack-fibadder@1.1.0")'
|
||||
assert_success prj.configure
|
||||
|
||||
|
||||
48
test/integration/test_system_warnings.rb
Normal file
48
test/integration/test_system_warnings.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
require_relative './lib'
|
||||
|
||||
class SystemWarnings < IntegrationTest
|
||||
|
||||
def test_dependency_added_using_system
|
||||
for use_system in [true, false] do
|
||||
prj = make_project name: use_system ? "system" : "no_system", from_template: 'using-adder'
|
||||
prj.create_lists_from_default_template package: <<~PACK
|
||||
# this commit has a warning in a public header
|
||||
CPMAddPackage(
|
||||
NAME Adder
|
||||
GITHUB_REPOSITORY cpm-cmake/testpack-adder
|
||||
GIT_TAG v1.0.1-warnings
|
||||
SYSTEM #{use_system ? "YES" : "NO"}
|
||||
)
|
||||
# all packages using `adder` will error on warnings
|
||||
target_compile_options(adder INTERFACE
|
||||
$<$<CXX_COMPILER_ID:MSVC>:/Wall /WX>
|
||||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Werror>
|
||||
)
|
||||
PACK
|
||||
|
||||
assert_success prj.configure
|
||||
if use_system
|
||||
assert_success prj.build
|
||||
else
|
||||
assert_failure prj.build
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_dependency_added_implicitly_using_system
|
||||
prj = make_project from_template: 'using-adder'
|
||||
prj.create_lists_from_default_template package: <<~PACK
|
||||
# this commit has a warning in a public header
|
||||
CPMAddPackage("gh:cpm-cmake/testpack-adder@1.0.1-warnings")
|
||||
# all packages using `adder` will error on warnings
|
||||
target_compile_options(adder INTERFACE
|
||||
$<$<CXX_COMPILER_ID:MSVC>:/Wall /WX>
|
||||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Werror>
|
||||
)
|
||||
PACK
|
||||
|
||||
assert_success prj.configure
|
||||
assert_success prj.build
|
||||
end
|
||||
|
||||
end
|
||||
@@ -26,6 +26,17 @@ function(reset_test)
|
||||
update_cmake_lists()
|
||||
endfunction()
|
||||
|
||||
function(assert_cache_directory_count directory count)
|
||||
set(version_count 0)
|
||||
file(GLOB potential_versions ${directory})
|
||||
foreach(entry ${potential_versions})
|
||||
if(IS_DIRECTORY ${entry})
|
||||
math(EXPR version_count "${version_count} + 1")
|
||||
endif()
|
||||
endforeach()
|
||||
assert_equal("${version_count}" "${count}")
|
||||
endfunction()
|
||||
|
||||
set(FIBONACCI_VERSION 1.0)
|
||||
|
||||
# Read CPM_SOURCE_CACHE from arguments
|
||||
@@ -40,13 +51,7 @@ execute_process(
|
||||
assert_equal(${ret} "0")
|
||||
assert_exists("${CPM_SOURCE_CACHE_DIR}/fibonacci")
|
||||
|
||||
file(GLOB FIBONACCI_VERSIONs "${CPM_SOURCE_CACHE_DIR}/fibonacci/*")
|
||||
list(LENGTH FIBONACCI_VERSIONs FIBONACCI_VERSION_count)
|
||||
assert_equal(${FIBONACCI_VERSION_count} "1")
|
||||
|
||||
file(GLOB fibonacci_versions "${CPM_SOURCE_CACHE_DIR}/fibonacci/*")
|
||||
list(LENGTH fibonacci_versions fibonacci_version_count)
|
||||
assert_equal(${fibonacci_version_count} "1")
|
||||
assert_cache_directory_count("${CPM_SOURCE_CACHE_DIR}/fibonacci/*" 1)
|
||||
|
||||
# Update dependency and keep CPM_SOURCE_CACHE
|
||||
|
||||
@@ -54,12 +59,9 @@ set(FIBONACCI_VERSION 2.0)
|
||||
update_cmake_lists()
|
||||
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} ${TEST_BUILD_DIR} RESULT_VARIABLE ret)
|
||||
|
||||
assert_equal(${ret} "0")
|
||||
|
||||
file(GLOB FIBONACCI_VERSIONs "${CPM_SOURCE_CACHE_DIR}/fibonacci/*")
|
||||
list(LENGTH FIBONACCI_VERSIONs FIBONACCI_VERSION_count)
|
||||
assert_equal(${FIBONACCI_VERSION_count} "2")
|
||||
assert_cache_directory_count("${CPM_SOURCE_CACHE_DIR}/fibonacci/*" 2)
|
||||
|
||||
# Clear cache and update
|
||||
|
||||
|
||||
Reference in New Issue
Block a user