From a4f055c7aa9a594276bfbf533342749ff11e8b24 Mon Sep 17 00:00:00 2001 From: Lars Melchior Date: Mon, 20 May 2019 13:33:01 +0200 Subject: [PATCH] Add url shortcuts (#53) * add github and gitlab shortcut, closes #52 * update version * update examples and readme --- README.md | 5 +++-- cmake/CPM.cmake | 13 +++++++++++-- examples/benchmark/CMakeLists.txt | 2 +- examples/catch2/CMakeLists.txt | 2 +- examples/doctest/CMakeLists.txt | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index df3be3e..73a502c 100644 --- a/README.md +++ b/README.md @@ -85,12 +85,13 @@ Has a CMakeLists.txt that supports `add_subdirectory`. ```cmake CPMAddPackage( NAME Catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GITHUB_REPOSITORY catchorg/Catch2 VERSION 2.5.0 ) ``` See [here](https://github.com/TheLartians/CPM/blob/master/examples/doctest/CMakeLists.txt) for doctest example. +Note that we can shorten Github and Gitlab URLs by using `GITHUB_REPOSITORY` or `GITLAB_REPOSITORY`, respectively. ### [google/benchmark](https://github.com/google/benchmark.git) @@ -99,7 +100,7 @@ Has a CMakeLists.txt that supports `add_subdirectory`, but needs some configurin ```cmake CPMAddPackage( NAME benchmark - GIT_REPOSITORY https://github.com/google/benchmark.git + GITHUB_REPOSITORY google/benchmark VERSION 1.4.1 OPTIONS "BENCHMARK_ENABLE_TESTING Off" diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index 67d7488..5c15bc1 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -28,7 +28,7 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) -set(CURRENT_CPM_VERSION 0.10) +set(CURRENT_CPM_VERSION 0.11) if(CPM_DIRECTORY) if(NOT ${CPM_DIRECTORY} MATCHES ${CMAKE_CURRENT_LIST_DIR}) @@ -97,12 +97,22 @@ function(CPMAddPackage) set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION}) endif() + list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_TAG ${CPM_ARGS_GIT_TAG}) + if(CPM_ARGS_DOWNLOAD_ONLY) set(DOWNLOAD_ONLY ${CPM_ARGS_DOWNLOAD_ONLY}) else() set(DOWNLOAD_ONLY NO) endif() + if (CPM_ARGS_GITHUB_REPOSITORY) + list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_REPOSITORY "https://github.com/${CPM_ARGS_GITHUB_REPOSITORY}.git") + endif() + + if (CPM_ARGS_GITLAB_REPOSITORY) + list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_REPOSITORY "https://gitlab.com/${CPM_ARGS_GITHUB_REPOSITORY}.git") + endif() + if (${CPM_ARGS_NAME} IN_LIST CPM_PACKAGES) CPM_GET_PACKAGE_VERSION(${CPM_ARGS_NAME}) if(${CPM_PACKAGE_VERSION} VERSION_LESS ${CPM_ARGS_VERSION}) @@ -146,7 +156,6 @@ function (CPM_DECLARE_PACKAGE PACKAGE VERSION GIT_TAG) FetchContent_Declare( ${PACKAGE} - GIT_TAG ${GIT_TAG} ${ARGN} ) endfunction() diff --git a/examples/benchmark/CMakeLists.txt b/examples/benchmark/CMakeLists.txt index 921525a..2f5b9ee 100644 --- a/examples/benchmark/CMakeLists.txt +++ b/examples/benchmark/CMakeLists.txt @@ -12,7 +12,7 @@ CPMAddPackage( CPMAddPackage( NAME benchmark - GIT_REPOSITORY https://github.com/google/benchmark.git + GITHUB_REPOSITORY google/benchmark VERSION 1.4.1 OPTIONS "BENCHMARK_ENABLE_TESTING Off" diff --git a/examples/catch2/CMakeLists.txt b/examples/catch2/CMakeLists.txt index 311fba5..89932ca 100644 --- a/examples/catch2/CMakeLists.txt +++ b/examples/catch2/CMakeLists.txt @@ -16,7 +16,7 @@ CPMAddPackage( CPMAddPackage( NAME Catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GITHUB_REPOSITORY catchorg/Catch2 VERSION 2.5.0 ) diff --git a/examples/doctest/CMakeLists.txt b/examples/doctest/CMakeLists.txt index a4a3042..13657ff 100644 --- a/examples/doctest/CMakeLists.txt +++ b/examples/doctest/CMakeLists.txt @@ -16,7 +16,7 @@ CPMAddPackage( CPMAddPackage( NAME doctest - GIT_REPOSITORY https://github.com/onqtam/doctest.git + GITHUB_REPOSITORY onqtam/doctest VERSION 2.3.2 GIT_TAG 2.3.2 )