mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-23 04:37:43 -05:00
Compare commits
5 Commits
v0.29.0-pr
...
v0.31.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f6cbe7383 | ||
|
|
4aadac1972 | ||
|
|
4cbf443363 | ||
|
|
2744b87f07 | ||
|
|
fd539b8ff3 |
@@ -33,6 +33,7 @@ parse:
|
|||||||
DOWNLOAD_NO_EXTRACT: 1
|
DOWNLOAD_NO_EXTRACT: 1
|
||||||
HTTP_USERNAME: 1
|
HTTP_USERNAME: 1
|
||||||
HTTP_PASSWORD: 1
|
HTTP_PASSWORD: 1
|
||||||
|
EXCLUDE_FROM_ALL: 1
|
||||||
OPTIONS: +
|
OPTIONS: +
|
||||||
cpmfindpackage:
|
cpmfindpackage:
|
||||||
pargs:
|
pargs:
|
||||||
|
|||||||
31
README.md
31
README.md
@@ -47,6 +47,19 @@ On the other hand, if `VERSION` hasn't been explicitly specified, CPM can automa
|
|||||||
`GIT_TAG` can also be set to a specific commit or a branch name such as `master` to always download the most recent version.
|
`GIT_TAG` can also be set to a specific commit or a branch name such as `master` to always download the most recent version.
|
||||||
The optional argument `FIND_PACKAGE_ARGUMENTS` can be specified to a string of parameters that will be passed to `find_package` if enabled (see below).
|
The optional argument `FIND_PACKAGE_ARGUMENTS` can be specified to a string of parameters that will be passed to `find_package` if enabled (see below).
|
||||||
|
|
||||||
|
A single-argument compact syntax is also supported:
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
# A git package from a given uri with a version
|
||||||
|
CPMAddPackage("uri@version")
|
||||||
|
# A git package from a given uri with a git tag or commit hash, or branch name
|
||||||
|
CPMAddPackage("uri#tag")
|
||||||
|
# A git package with both version and tag provided
|
||||||
|
CPMAddPackage("uri@version#tag")
|
||||||
|
```
|
||||||
|
|
||||||
|
In the shorthand syntax if the URI is of the form `gh:user/name`, it is interpreted as GitHub URI and converted to `https://github.com/user/name.git`. If the URI is of the form `gl:user/name`, it is interpreted as a [GitLab](https://gitlab.com/explore/) URI and coverted to `https://gitlab.com/user/name.git`. Otherwise the URI used verbatim as a git URL.
|
||||||
|
|
||||||
After calling `CPMAddPackage` or `CPMFindPackage`, the following variables are defined in the local scope, where `<dependency>` is the name of the dependency.
|
After calling `CPMAddPackage` or `CPMFindPackage`, the following variables are defined in the local scope, where `<dependency>` is the name of the dependency.
|
||||||
|
|
||||||
- `<dependency>_SOURCE_DIR` is the path to the source of the dependency.
|
- `<dependency>_SOURCE_DIR` is the path to the source of the dependency.
|
||||||
@@ -70,11 +83,7 @@ add_executable(tests tests.cpp)
|
|||||||
# add dependencies
|
# add dependencies
|
||||||
include(cmake/CPM.cmake)
|
include(cmake/CPM.cmake)
|
||||||
|
|
||||||
CPMAddPackage(
|
CPMAddPackage(gh:catchorg/Catch2@2.5.0)
|
||||||
NAME Catch2
|
|
||||||
GITHUB_REPOSITORY catchorg/Catch2
|
|
||||||
VERSION 2.5.0
|
|
||||||
)
|
|
||||||
|
|
||||||
# link dependencies
|
# link dependencies
|
||||||
target_link_libraries(tests Catch2)
|
target_link_libraries(tests Catch2)
|
||||||
@@ -245,21 +254,13 @@ See the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/More-Snippets) for mo
|
|||||||
### [Catch2](https://github.com/catchorg/Catch2)
|
### [Catch2](https://github.com/catchorg/Catch2)
|
||||||
|
|
||||||
```cmake
|
```cmake
|
||||||
CPMAddPackage(
|
CPMAddPackage(gh:catchorg/Catch2@2.5.0)
|
||||||
NAME Catch2
|
|
||||||
GITHUB_REPOSITORY catchorg/Catch2
|
|
||||||
VERSION 2.5.0
|
|
||||||
)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### [Boost (via boost-cmake)](https://github.com/Orphis/boost-cmake)
|
### [Boost (via boost-cmake)](https://github.com/Orphis/boost-cmake)
|
||||||
|
|
||||||
```CMake
|
```CMake
|
||||||
CPMAddPackage(
|
CPMAddPackage(gh:Orphis/boost-cmake@1.67.0)
|
||||||
NAME boost-cmake
|
|
||||||
GITHUB_REPOSITORY Orphis/boost-cmake
|
|
||||||
VERSION 1.67.0
|
|
||||||
)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### [cxxopts](https://github.com/jarro2783/cxxopts)
|
### [cxxopts](https://github.com/jarro2783/cxxopts)
|
||||||
|
|||||||
134
cmake/CPM.cmake
134
cmake/CPM.cmake
@@ -134,6 +134,18 @@ endif()
|
|||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
include(CMakeParseArguments)
|
include(CMakeParseArguments)
|
||||||
|
|
||||||
|
# Infer package name from git repository uri (path or url)
|
||||||
|
function(cpm_package_name_from_git_uri URI RESULT)
|
||||||
|
if("${URI}" MATCHES "([^/:]+)/?.git/?$")
|
||||||
|
set(${RESULT}
|
||||||
|
${CMAKE_MATCH_1}
|
||||||
|
PARENT_SCOPE
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
unset(${RESULT} PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# Initialize logging prefix
|
# Initialize logging prefix
|
||||||
if(NOT CPM_INDENT)
|
if(NOT CPM_INDENT)
|
||||||
set(CPM_INDENT
|
set(CPM_INDENT
|
||||||
@@ -240,8 +252,85 @@ function(cpm_check_if_package_already_added CPM_ARGS_NAME CPM_ARGS_VERSION CPM_A
|
|||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
# Parse the argument of CPMAddPackage in case a single one was provided and convert it to a list of
|
||||||
|
# arguments which can then be parsed idiomatically. For example gh:foo/bar@1.2.3 will be converted
|
||||||
|
# to: GITHUB_REPOSITORY;foo/bar;VERSION;1.2.3
|
||||||
|
function(cpm_parse_add_package_single_arg arg outArgs)
|
||||||
|
# Look for a scheme
|
||||||
|
if("${arg}" MATCHES "^([a-zA-Z]+):(.+)$")
|
||||||
|
string(TOLOWER "${CMAKE_MATCH_1}" scheme)
|
||||||
|
set(uri "${CMAKE_MATCH_2}")
|
||||||
|
|
||||||
|
# Check for CPM-specific schemes
|
||||||
|
if(scheme STREQUAL "gh")
|
||||||
|
set(out "GITHUB_REPOSITORY;${uri}")
|
||||||
|
set(packageType "git")
|
||||||
|
elseif(scheme STREQUAL "gl")
|
||||||
|
set(out "GITLAB_REPOSITORY;${uri}")
|
||||||
|
set(packageType "git")
|
||||||
|
# A CPM-specific scheme was not found. Looks like this is a generic URL so try to determine
|
||||||
|
# type
|
||||||
|
elseif(arg MATCHES ".git/?(@|#|$)")
|
||||||
|
set(out "GIT_REPOSITORY;${arg}")
|
||||||
|
set(packageType "git")
|
||||||
|
else()
|
||||||
|
# This error here is temporary. We can't provide URLs from here until we support inferring the
|
||||||
|
# package name from an url. When this is supported, remove this error as well as commented out
|
||||||
|
# tests in test/unit/parse_add_package_single_arg.cmake
|
||||||
|
message(FATAL_ERROR "CPM: Unsupported package type of '${arg}'")
|
||||||
|
|
||||||
|
# Fall back to a URL
|
||||||
|
set(out "URL;${arg}")
|
||||||
|
set(packageType "archive")
|
||||||
|
|
||||||
|
# We could also check for SVN since FetchContent supports it, but SVN is so rare these days.
|
||||||
|
# We just won't bother with the additional complexity it will induce in this function. SVN is
|
||||||
|
# done by multi-arg
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
if(arg MATCHES ".git/?(@|#|$)")
|
||||||
|
set(out "GIT_REPOSITORY;${arg}")
|
||||||
|
set(packageType "git")
|
||||||
|
else()
|
||||||
|
# Give up
|
||||||
|
message(FATAL_ERROR "CPM: Can't determine package type of '${arg}'")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# For all packages we interpret @... as version. Only replace the last occurence. Thus URIs
|
||||||
|
# containing '@' can be used
|
||||||
|
string(REGEX REPLACE "@([^@]+)$" ";VERSION;\\1" out "${out}")
|
||||||
|
|
||||||
|
# Parse the rest according to package type
|
||||||
|
if(packageType STREQUAL "git")
|
||||||
|
# For git repos we interpret #... as a tag or branch or commit hash
|
||||||
|
string(REGEX REPLACE "#([^#]+)$" ";GIT_TAG;\\1" out "${out}")
|
||||||
|
elseif(packageType STREQUAL "archive")
|
||||||
|
# For archives we interpret #... as a URL hash.
|
||||||
|
string(REGEX REPLACE "#([^#]+)$" ";URL_HASH;\\1" out "${out}")
|
||||||
|
# We don't try to parse the version if it's not provided explicitly. cpm_get_version_from_url
|
||||||
|
# should do this at a later point
|
||||||
|
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}'")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(${outArgs}
|
||||||
|
${out}
|
||||||
|
PARENT_SCOPE
|
||||||
|
)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# Download and add a package from source
|
# Download and add a package from source
|
||||||
function(CPMAddPackage)
|
function(CPMAddPackage)
|
||||||
|
list(LENGTH ARGN argnLength)
|
||||||
|
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")
|
||||||
|
endif()
|
||||||
|
|
||||||
set(oneValueArgs
|
set(oneValueArgs
|
||||||
NAME
|
NAME
|
||||||
@@ -257,6 +346,7 @@ function(CPMAddPackage)
|
|||||||
FIND_PACKAGE_ARGUMENTS
|
FIND_PACKAGE_ARGUMENTS
|
||||||
NO_CACHE
|
NO_CACHE
|
||||||
GIT_SHALLOW
|
GIT_SHALLOW
|
||||||
|
EXCLUDE_FROM_ALL
|
||||||
)
|
)
|
||||||
|
|
||||||
set(multiValueArgs OPTIONS)
|
set(multiValueArgs OPTIONS)
|
||||||
@@ -290,6 +380,11 @@ function(CPMAddPackage)
|
|||||||
if(NOT DEFINED CPM_ARGS_GIT_TAG)
|
if(NOT DEFINED CPM_ARGS_GIT_TAG)
|
||||||
set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION})
|
set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# If a name wasn't provided, try to infer it from the git repo
|
||||||
|
if(NOT DEFINED CPM_ARGS_NAME)
|
||||||
|
cpm_package_name_from_git_uri(${CPM_ARGS_GIT_REPOSITORY} CPM_ARGS_NAME)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CPM_SKIP_FETCH FALSE)
|
set(CPM_SKIP_FETCH FALSE)
|
||||||
@@ -302,6 +397,15 @@ function(CPMAddPackage)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Check for required arguments
|
||||||
|
|
||||||
|
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}'"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Check if package has been added before
|
# Check if package has been added before
|
||||||
cpm_check_if_package_already_added(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" "${CPM_ARGS_OPTIONS}")
|
cpm_check_if_package_already_added(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" "${CPM_ARGS_OPTIONS}")
|
||||||
if(CPM_PACKAGE_ALREADY_ADDED)
|
if(CPM_PACKAGE_ALREADY_ADDED)
|
||||||
@@ -387,7 +491,9 @@ function(CPMAddPackage)
|
|||||||
set(${CPM_ARGS_NAME}_ADDED YES)
|
set(${CPM_ARGS_NAME}_ADDED YES)
|
||||||
set(${CPM_ARGS_NAME}_SOURCE_DIR ${download_directory})
|
set(${CPM_ARGS_NAME}_SOURCE_DIR ${download_directory})
|
||||||
if(NOT CPM_ARGS_DOWNLOAD_ONLY AND EXISTS ${download_directory}/CMakeLists.txt)
|
if(NOT CPM_ARGS_DOWNLOAD_ONLY AND EXISTS ${download_directory}/CMakeLists.txt)
|
||||||
add_subdirectory(${download_directory} ${${CPM_ARGS_NAME}_BINARY_DIR})
|
cpm_add_subdirectory(
|
||||||
|
${download_directory} ${${CPM_ARGS_NAME}_BINARY_DIR} "${CPM_ARGS_EXCLUDE_FROM_ALL}"
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
set(CPM_SKIP_FETCH TRUE)
|
set(CPM_SKIP_FETCH TRUE)
|
||||||
set(PACKAGE_INFO "${PACKAGE_INFO} at ${download_directory}")
|
set(PACKAGE_INFO "${PACKAGE_INFO} at ${download_directory}")
|
||||||
@@ -427,7 +533,7 @@ function(CPMAddPackage)
|
|||||||
cpm_declare_fetch(
|
cpm_declare_fetch(
|
||||||
"${CPM_ARGS_NAME}" "${CPM_ARGS_VERSION}" "${PACKAGE_INFO}" "${CPM_ARGS_UNPARSED_ARGUMENTS}"
|
"${CPM_ARGS_NAME}" "${CPM_ARGS_VERSION}" "${PACKAGE_INFO}" "${CPM_ARGS_UNPARSED_ARGUMENTS}"
|
||||||
)
|
)
|
||||||
cpm_fetch_package("${CPM_ARGS_NAME}" "${DOWNLOAD_ONLY}")
|
cpm_fetch_package("${CPM_ARGS_NAME}" "${DOWNLOAD_ONLY}" "${CPM_ARGS_EXCLUDE_FROM_ALL}")
|
||||||
cpm_get_fetch_properties("${CPM_ARGS_NAME}")
|
cpm_get_fetch_properties("${CPM_ARGS_NAME}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -550,24 +656,36 @@ function(cpm_get_fetch_properties PACKAGE)
|
|||||||
)
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(cpm_add_subdirectory SOURCE_DIR BINARY_DIR EXCLUDE)
|
||||||
|
if(EXCLUDE)
|
||||||
|
set(addSubdirectoryExtraArgs EXCLUDE_FROM_ALL)
|
||||||
|
else()
|
||||||
|
set(addSubdirectoryExtraArgs "")
|
||||||
|
endif()
|
||||||
|
add_subdirectory(${SOURCE_DIR} ${BINARY_DIR} ${addSubdirectoryExtraArgs})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# downloads a previously declared package via FetchContent
|
# downloads a previously declared package via FetchContent
|
||||||
function(cpm_fetch_package PACKAGE DOWNLOAD_ONLY)
|
function(cpm_fetch_package PACKAGE DOWNLOAD_ONLY EXCLUDE)
|
||||||
if(${CPM_DRY_RUN})
|
if(${CPM_DRY_RUN})
|
||||||
message(STATUS "${CPM_INDENT} package ${PACKAGE} not fetched (dry run)")
|
message(STATUS "${CPM_INDENT} package ${PACKAGE} not fetched (dry run)")
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(DOWNLOAD_ONLY)
|
|
||||||
FetchContent_GetProperties(${PACKAGE})
|
FetchContent_GetProperties(${PACKAGE})
|
||||||
if(NOT ${PACKAGE}_POPULATED)
|
string(TOLOWER "${PACKAGE}" lower_case_name)
|
||||||
|
|
||||||
|
if(NOT ${lower_case_name}_POPULATED)
|
||||||
FetchContent_Populate(${PACKAGE})
|
FetchContent_Populate(${PACKAGE})
|
||||||
endif()
|
if(NOT DOWNLOAD_ONLY AND EXISTS ${${lower_case_name}_SOURCE_DIR}/CMakeLists.txt)
|
||||||
else()
|
|
||||||
set(CPM_OLD_INDENT "${CPM_INDENT}")
|
set(CPM_OLD_INDENT "${CPM_INDENT}")
|
||||||
set(CPM_INDENT "${CPM_INDENT} ${PACKAGE}:")
|
set(CPM_INDENT "${CPM_INDENT} ${PACKAGE}:")
|
||||||
FetchContent_MakeAvailable(${PACKAGE})
|
cpm_add_subdirectory(
|
||||||
|
${${lower_case_name}_SOURCE_DIR} ${${lower_case_name}_BINARY_DIR} "${EXCLUDE}"
|
||||||
|
)
|
||||||
set(CPM_INDENT "${CPM_OLD_INDENT}")
|
set(CPM_INDENT "${CPM_OLD_INDENT}")
|
||||||
endif()
|
endif()
|
||||||
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
# splits a package option
|
# splits a package option
|
||||||
|
|||||||
@@ -3,13 +3,25 @@ function(ASSERT_EQUAL)
|
|||||||
message(FATAL_ERROR "assertion failed: invalid argument count: ${ARGC}")
|
message(FATAL_ERROR "assertion failed: invalid argument count: ${ARGC}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT ${ARGV0} STREQUAL ${ARGV1})
|
if(NOT "${ARGV0}" STREQUAL "${ARGV1}")
|
||||||
message(FATAL_ERROR "assertion failed: '${ARGV0}' != '${ARGV1}'")
|
message(FATAL_ERROR "assertion failed: '${ARGV0}' != '${ARGV1}'")
|
||||||
else()
|
else()
|
||||||
message(STATUS "test passed: '${ARGV0}' == '${ARGV1}'")
|
message(STATUS "test passed: '${ARGV0}' == '${ARGV1}'")
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(ASSERT_NOT_EQUAL)
|
||||||
|
if(NOT ARGC EQUAL 2)
|
||||||
|
message(FATAL_ERROR "assertion failed: invalid argument count: ${ARGC}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if("${ARGV0}" STREQUAL "${ARGV1}")
|
||||||
|
message(FATAL_ERROR "assertion failed: '${ARGV0}' == '${ARGV1}'")
|
||||||
|
else()
|
||||||
|
message(STATUS "test passed: '${ARGV0}' != '${ARGV1}'")
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
function(ASSERT_EMPTY)
|
function(ASSERT_EMPTY)
|
||||||
if(NOT ARGC EQUAL 0)
|
if(NOT ARGC EQUAL 0)
|
||||||
message(FATAL_ERROR "assertion failed: input ${ARGC} not empty: '${ARGV}'")
|
message(FATAL_ERROR "assertion failed: input ${ARGC} not empty: '${ARGV}'")
|
||||||
@@ -24,6 +36,14 @@ function(ASSERT_DEFINED KEY)
|
|||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(ASSERT_NOT_DEFINED KEY)
|
||||||
|
if(DEFINED ${KEY})
|
||||||
|
message(FATAL_ERROR "assertion failed: '${KEY}' is defiend")
|
||||||
|
else()
|
||||||
|
message(STATUS "test passed: '${KEY}' is not defined")
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
function(ASSERT_TRUTHY KEY)
|
function(ASSERT_TRUTHY KEY)
|
||||||
if(${${KEY}})
|
if(${${KEY}})
|
||||||
message(STATUS "test passed: '${KEY}' is set truthy")
|
message(STATUS "test passed: '${KEY}' is set truthy")
|
||||||
|
|||||||
2
test/unit/broken_dependency/.gitignore
vendored
Normal file
2
test/unit/broken_dependency/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/CMakeLists.txt
|
||||||
|
/package-lock.cmake
|
||||||
13
test/unit/broken_dependency/CMakeLists.txt.in
Normal file
13
test/unit/broken_dependency/CMakeLists.txt.in
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||||
|
|
||||||
|
project(CPMTest)
|
||||||
|
|
||||||
|
# ---- Dependencies ----
|
||||||
|
|
||||||
|
include(@CPM_PATH@/CPM.cmake)
|
||||||
|
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME BrokenDependency
|
||||||
|
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/dependency
|
||||||
|
EXCLUDE_FROM_ALL @EXCLUDE_FROM_ALL@
|
||||||
|
)
|
||||||
3
test/unit/broken_dependency/dependency/CMakeLists.txt
Normal file
3
test/unit/broken_dependency/dependency/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
project(BrokenDependency)
|
||||||
|
|
||||||
|
add_custom_target(error ALL ${CMAKE_COMMAND} -E false)
|
||||||
35
test/unit/exclude_from_all.cmake
Normal file
35
test/unit/exclude_from_all.cmake
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
include(${CPM_PATH}/testing.cmake)
|
||||||
|
|
||||||
|
set(TEST_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/exclude_from_all)
|
||||||
|
|
||||||
|
function(init_project EXCLUDE_FROM_ALL)
|
||||||
|
configure_package_config_file(
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/broken_dependency/CMakeLists.txt.in"
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/broken_dependency/CMakeLists.txt"
|
||||||
|
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/junk
|
||||||
|
)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${CMAKE_COMMAND} "-H${CMAKE_CURRENT_LIST_DIR}/broken_dependency" "-B${TEST_BUILD_DIR}"
|
||||||
|
RESULT_VARIABLE ret
|
||||||
|
)
|
||||||
|
|
||||||
|
assert_equal(${ret} "0")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(build_project expected_success)
|
||||||
|
execute_process(COMMAND ${CMAKE_COMMAND} "--build" "${TEST_BUILD_DIR}" RESULT_VARIABLE ret)
|
||||||
|
|
||||||
|
if(expected_success)
|
||||||
|
assert_equal(${ret} 0)
|
||||||
|
else()
|
||||||
|
assert_not_equal(${ret} 0)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
init_project(FALSE)
|
||||||
|
build_project(FALSE)
|
||||||
|
|
||||||
|
init_project(TRUE)
|
||||||
|
build_project(TRUE)
|
||||||
28
test/unit/package_name_from_git_uri.cmake
Normal file
28
test/unit/package_name_from_git_uri.cmake
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||||
|
|
||||||
|
include(${CPM_PATH}/CPM.cmake)
|
||||||
|
include(${CPM_PATH}/testing.cmake)
|
||||||
|
|
||||||
|
cpm_package_name_from_git_uri("https://github.com/cpm-cmake/CPM.cmake.git" name)
|
||||||
|
assert_equal("CPM.cmake" ${name})
|
||||||
|
|
||||||
|
cpm_package_name_from_git_uri("ssh://user@host.xz:123/path/to/pkg.git/" name)
|
||||||
|
assert_equal("pkg" ${name})
|
||||||
|
|
||||||
|
cpm_package_name_from_git_uri("git://host.xz/path/to/pkg.git" name)
|
||||||
|
assert_equal("pkg" ${name})
|
||||||
|
|
||||||
|
cpm_package_name_from_git_uri("git@host.xz:cool-pkg.git" name)
|
||||||
|
assert_equal("cool-pkg" ${name})
|
||||||
|
|
||||||
|
cpm_package_name_from_git_uri("file:///path/to/pkg33.git" name)
|
||||||
|
assert_equal("pkg33" ${name})
|
||||||
|
|
||||||
|
cpm_package_name_from_git_uri("../local-repo/.git" name)
|
||||||
|
assert_equal("local-repo" ${name})
|
||||||
|
|
||||||
|
cpm_package_name_from_git_uri("asdf" name)
|
||||||
|
assert_not_defined(name)
|
||||||
|
|
||||||
|
cpm_package_name_from_git_uri("/something.git/stuff" name)
|
||||||
|
assert_not_defined(name)
|
||||||
64
test/unit/parse_add_package_single_arg.cmake
Normal file
64
test/unit/parse_add_package_single_arg.cmake
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||||
|
|
||||||
|
include(${CPM_PATH}/CPM.cmake)
|
||||||
|
include(${CPM_PATH}/testing.cmake)
|
||||||
|
|
||||||
|
cpm_parse_add_package_single_arg("gh:cpm-cmake/CPM.cmake" args)
|
||||||
|
assert_equal("GITHUB_REPOSITORY;cpm-cmake/CPM.cmake" "${args}")
|
||||||
|
|
||||||
|
cpm_parse_add_package_single_arg("gh:cpm-cmake/CPM.cmake@1.2.3" args)
|
||||||
|
assert_equal("GITHUB_REPOSITORY;cpm-cmake/CPM.cmake;VERSION;1.2.3" "${args}")
|
||||||
|
|
||||||
|
cpm_parse_add_package_single_arg("gh:cpm-cmake/CPM.cmake#master" args)
|
||||||
|
assert_equal("GITHUB_REPOSITORY;cpm-cmake/CPM.cmake;GIT_TAG;master" "${args}")
|
||||||
|
|
||||||
|
cpm_parse_add_package_single_arg("gh:cpm-cmake/CPM.cmake@0.20.3#asdf" args)
|
||||||
|
assert_equal("GITHUB_REPOSITORY;cpm-cmake/CPM.cmake;VERSION;0.20.3;GIT_TAG;asdf" "${args}")
|
||||||
|
|
||||||
|
cpm_parse_add_package_single_arg("gh:a/b#c@d" args)
|
||||||
|
assert_equal("GITHUB_REPOSITORY;a/b;GIT_TAG;c;VERSION;d" "${args}")
|
||||||
|
|
||||||
|
cpm_parse_add_package_single_arg("gh:foo#c@d" args)
|
||||||
|
assert_equal("GITHUB_REPOSITORY;foo;GIT_TAG;c;VERSION;d" "${args}")
|
||||||
|
|
||||||
|
cpm_parse_add_package_single_arg("gh:Foo@5" args)
|
||||||
|
assert_equal("GITHUB_REPOSITORY;Foo;VERSION;5" "${args}")
|
||||||
|
|
||||||
|
cpm_parse_add_package_single_arg("gl:foo/bar" args)
|
||||||
|
assert_equal("GITLAB_REPOSITORY;foo/bar" "${args}")
|
||||||
|
|
||||||
|
cpm_parse_add_package_single_arg("gl:foo/Bar" args)
|
||||||
|
assert_equal("GITLAB_REPOSITORY;foo/Bar" "${args}")
|
||||||
|
|
||||||
|
cpm_parse_add_package_single_arg("https://github.com/cpm-cmake/CPM.cmake.git@0.30.5" args)
|
||||||
|
assert_equal("GIT_REPOSITORY;https://github.com/cpm-cmake/CPM.cmake.git;VERSION;0.30.5" "${args}")
|
||||||
|
|
||||||
|
cpm_parse_add_package_single_arg("git@host.xz:user/pkg.git@0.1.2" args)
|
||||||
|
assert_equal("GIT_REPOSITORY;git@host.xz:user/pkg.git;VERSION;0.1.2" "${args}")
|
||||||
|
|
||||||
|
cpm_parse_add_package_single_arg("git@host.xz:user/pkg.git@0.1.2#rc" args)
|
||||||
|
assert_equal("GIT_REPOSITORY;git@host.xz:user/pkg.git;VERSION;0.1.2;GIT_TAG;rc" "${args}")
|
||||||
|
|
||||||
|
cpm_parse_add_package_single_arg(
|
||||||
|
"ssh://user@host.xz:123/path/to/pkg.git#fragment@1.2.3#branch" args
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"GIT_REPOSITORY;ssh://user@host.xz:123/path/to/pkg.git#fragment;VERSION;1.2.3;GIT_TAG;branch"
|
||||||
|
"${args}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# The following test cases are to be used in the future, once single-argument archives are supported
|
||||||
|
|
||||||
|
# cpm_parse_add_package_single_arg("https://example.org/foo.tar.gz" args)
|
||||||
|
|
||||||
|
# assert_equal("URL;https://example.org/foo.tar.gz" "${args}")
|
||||||
|
|
||||||
|
# cpm_parse_add_package_single_arg("https://example.org/foo.tar.gz#baadf00d@1.2.0" args)
|
||||||
|
|
||||||
|
# assert_equal("URL;https://example.org/foo.tar.gz;URL_HASH;baadf00d;VERSION;1.2.0" "${args}")
|
||||||
|
|
||||||
|
# cpm_parse_add_package_single_arg("ftp://user:password@server/pathname.zip#fragment#0ddb411@0"
|
||||||
|
# args)
|
||||||
|
|
||||||
|
# assert_equal("URL;ftp://user:password@server/pathname.zip#fragment;URL_HASH;0ddb411;VERSION;0"
|
||||||
|
# "${args}")
|
||||||
Reference in New Issue
Block a user