Compare commits

..

4 Commits

Author SHA1 Message Date
Borislav Stanimirov
4cbf443363 If a name isn't provided, try to infer it from the git repo (#202)
* Added assert_not_defined check

* Function to get package name form git uri and tests

* Autofix format

* If name is not provided, try to infer it from the git repo

* Unset result of cpm_package_name_from_git_uri if there is no match
- Also reordered tests to ensure that the result is actually unset when needed

* Removed trailing spaces in README

* Updated the main example with the new minimal syntax

* Well... autofix format again

* Update error message for missing name to reflect the possible auto-infer step

* Autofix format... yet again :)
2021-02-17 12:41:25 +01:00
Borislav Stanimirov
2744b87f07 FATAL_ERROR if no NAME is provided (#201)
* FATAL_ERROR if no NAME is provided

* Fixed format
2021-02-16 14:54:31 +00:00
Lars Melchior
fd539b8ff3 Add dependencies using EXCLUDE_FROM_ALL flag (#198)
* add dependencies using EXCLUDE_FROM_ALL flag

* respect DOWNLOAD_ONLY flag

* set EXCLUDE_FROM_ALL as an optional flag

* use one value arg for consistency

* fix argument passing

* add unit test

* update cmake-format
2021-02-16 10:26:16 +00:00
Lars Melchior
02d57a1601 Update URLs for new CPM.cmake organisation (#194)
* update URLs for new CPM.cmake organisation

* trigger travis
2021-02-08 21:31:06 +01:00
10 changed files with 180 additions and 37 deletions

View File

@@ -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:

View File

@@ -1,7 +1,7 @@
[![Build Status](https://travis-ci.com/TheLartians/CPM.cmake.svg?branch=master)](https://travis-ci.com/TheLartians/CPM.cmake) [![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/TheLartians/CPM.cmake/workflows/MacOS/badge.svg)](https://github.com/TheLartians/CPM.cmake/actions) [![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/TheLartians/CPM.cmake/workflows/Windows/badge.svg)](https://github.com/TheLartians/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/TheLartians/CPM.cmake/workflows/Ubuntu/badge.svg)](https://github.com/TheLartians/CPM.cmake/actions) [![Join the chat at https://gitter.im/TheLartians/CPM.cmake](https://badges.gitter.im/TheLartians/CPM.cmake.svg)](https://gitter.im/TheLartians/CPM.cmake?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Actions Status](https://github.com/cpm-cmake/CPM.cmake/workflows/Ubuntu/badge.svg)](https://github.com/cpm-cmake/CPM.cmake/actions)
<br /> <br />
<p align="center"> <p align="center">
@@ -71,7 +71,6 @@ add_executable(tests tests.cpp)
include(cmake/CPM.cmake) include(cmake/CPM.cmake)
CPMAddPackage( CPMAddPackage(
NAME Catch2
GITHUB_REPOSITORY catchorg/Catch2 GITHUB_REPOSITORY catchorg/Catch2
VERSION 2.5.0 VERSION 2.5.0
) )
@@ -80,19 +79,19 @@ CPMAddPackage(
target_link_libraries(tests Catch2) target_link_libraries(tests Catch2)
``` ```
See the [examples directory](https://github.com/TheLartians/CPM.cmake/tree/master/examples) for complete examples with source code and check [below](#snippets) or in the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/More-Snippets) for example snippets. 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.
## Adding CPM ## Adding CPM
To add CPM to your current project, simply add the [latest release](https://github.com/TheLartians/CPM.cmake/releases/latest) of `CPM.cmake` or `get_cpm.cmake` to your project's `cmake` directory. To add CPM to your current project, simply add the [latest release](https://github.com/cpm-cmake/CPM.cmake/releases/latest) of `CPM.cmake` or `get_cpm.cmake` to your project's `cmake` directory.
The command below will perform this automatically. The command below will perform this automatically.
```bash ```bash
mkdir -p cmake mkdir -p cmake
wget -O cmake/CPM.cmake https://github.com/TheLartians/CPM.cmake/releases/latest/download/get_cpm.cmake wget -O cmake/CPM.cmake https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/get_cpm.cmake
``` ```
You can also download CPM.cmake directly from your project's `CMakeLists.txt`. See the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/Downloading-CPM.cmake-in-CMake) for more details. You can also download CPM.cmake directly from your project's `CMakeLists.txt`. See the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/Downloading-CPM.cmake-in-CMake) for more details.
## Updating CPM ## Updating CPM
@@ -112,7 +111,7 @@ Dependencies using CPM will automatically use the updated script of the outermos
## Limitations ## Limitations
- **No pre-built binaries** For every new build directory, all dependencies are initially downloaded and built from scratch. To avoid extra downloads it is recommend to set the [`CPM_SOURCE_CACHE`](#CPM_SOURCE_CACHE) environmental variable. Using a caching compiler such as [ccache](https://github.com/TheLartians/Ccache.cmake) can drastically reduce build time. - **No pre-built binaries** For every new build directory, all dependencies are initially downloaded and built from scratch. To avoid extra downloads it is recommend to set the [`CPM_SOURCE_CACHE`](#CPM_SOURCE_CACHE) environmental variable. Using a caching compiler such as [ccache](https://github.com/TheLartians/Ccache.cmake) can drastically reduce build time.
- **Dependent on good CMakeLists** Many libraries do not have CMakeLists that work well for subprojects. Luckily this is slowly changing, however, until then, some manual configuration may be required (see the snippets [below](#snippets) for examples). For best practices on preparing projects for CPM, see the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/Preparing-projects-for-CPM.cmake). - **Dependent on good CMakeLists** Many libraries do not have CMakeLists that work well for subprojects. Luckily this is slowly changing, however, until then, some manual configuration may be required (see the snippets [below](#snippets) for examples). For best practices on preparing projects for CPM, see the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/Preparing-projects-for-CPM.cmake).
- **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 easily resolved by adding a new version of the dependency in the outermost project, or by introducing a [package lock file](#package-lock). - **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 easily resolved by adding a new version of the dependency in the outermost project, or by introducing a [package lock file](#package-lock).
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). 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).
@@ -127,7 +126,7 @@ Additionally, it is difficult to cross-compile projects (e.g. for mobile), as th
CPM.cmake allows dependencies to be unambiguously defined and builds them from source. CPM.cmake allows dependencies to be unambiguously defined and builds them from source.
Note that the behaviour differs from `find_package`, as variables exported to the parent scope (such as `<PackageName>_LIBRARIES`) will not be visible after adding a package using CPM.cmake. Note that the behaviour differs from `find_package`, as variables exported to the parent scope (such as `<PackageName>_LIBRARIES`) will not be visible after adding a package using CPM.cmake.
The behaviour can be [achieved manually](https://github.com/TheLartians/CPM.cmake/issues/132#issuecomment-644955140), if required. The behaviour can be [achieved manually](https://github.com/cpm-cmake/CPM.cmake/issues/132#issuecomment-644955140), if required.
## Comparison to pure FetchContent / ExternalProject ## Comparison to pure FetchContent / ExternalProject
@@ -160,7 +159,7 @@ export CPM_SOURCE_CACHE=$HOME/.cache/CPM
Note that passing the variable as a configure option to CMake will always override the value set by the environmental variable. Note that passing the variable as a configure option to CMake will always override the value set by the environmental variable.
You can use `CPM_SOURCE_CACHE` on GitHub Actions workflows [cache](https://github.com/actions/cache) and combine it with ccache, to make your CI faster. See the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/Caching-with-CPM.cmake-and-ccache-on-GitHub-Actions) for more info. You can use `CPM_SOURCE_CACHE` on GitHub Actions workflows [cache](https://github.com/actions/cache) and combine it with ccache, to make your CI faster. See the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/Caching-with-CPM.cmake-and-ccache-on-GitHub-Actions) for more info.
### CPM_DOWNLOAD_ALL ### CPM_DOWNLOAD_ALL
@@ -201,7 +200,7 @@ cmake -Bbuild
cmake --build build --target cpm-update-package-lock cmake --build build --target cpm-update-package-lock
``` ```
See the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/Package-lock) for more info. See the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/Package-lock) for more info.
## Built with CPM.cmake ## Built with CPM.cmake
@@ -240,7 +239,7 @@ If you know others, feel free to add them here through a PR.
## Snippets ## Snippets
These examples demonstrate how to include some well-known projects with CPM. These examples demonstrate how to include some well-known projects with CPM.
See the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/More-Snippets) for more snippets. See the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/More-Snippets) for more snippets.
### [Catch2](https://github.com/catchorg/Catch2) ### [Catch2](https://github.com/catchorg/Catch2)
@@ -371,4 +370,4 @@ For a full example on using CPM to download and configure lua with sol2 see [her
### Full Examples ### Full Examples
See the [examples directory](https://github.com/TheLartians/CPM.cmake/tree/master/examples) for full examples with source code and check out the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/More-Snippets) for many more example snippets. See the [examples directory](https://github.com/cpm-cmake/CPM.cmake/tree/master/examples) for full examples with source code and check out the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/More-Snippets) for many more example snippets.

View File

@@ -1,6 +1,6 @@
# CPM.cmake - CMake's missing package manager # CPM.cmake - CMake's missing package manager
# =========================================== # ===========================================
# See https://github.com/TheLartians/CPM.cmake for usage and update instructions. # See https://github.com/cpm-cmake/CPM.cmake for usage and update instructions.
# #
# MIT License # MIT License
# ----------- # -----------
@@ -38,7 +38,7 @@ if(CPM_DIRECTORY)
"${CPM_INDENT} \ "${CPM_INDENT} \
A dependency is using a more recent CPM version (${CURRENT_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. \ It is recommended to upgrade CPM to the most recent version. \
See https://github.com/TheLartians/CPM.cmake for more information." See https://github.com/cpm-cmake/CPM.cmake for more information."
) )
endif() endif()
if(${CMAKE_VERSION} VERSION_LESS "3.17.0") if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
@@ -134,6 +134,19 @@ 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)
string(REGEX MATCH "([^/:]+)/?.git/?$" cpmGitUriMatch "${URI}")
if(DEFINED cpmGitUriMatch)
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
@@ -257,6 +270,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 +304,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 +321,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 +415,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 +457,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 +580,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

View File

@@ -13,7 +13,7 @@ endif()
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION})) if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}") message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD file(DOWNLOAD
https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} ${CPM_DOWNLOAD_LOCATION}
) )
endif() endif()

View File

@@ -10,6 +10,18 @@ function(ASSERT_EQUAL)
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")

View File

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

View 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@
)

View File

@@ -0,0 +1,3 @@
project(BrokenDependency)
add_custom_target(error ALL ${CMAKE_COMMAND} -E false)

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

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