Skip to content

Commit 5913685

Browse files
committed
feature: add URI to use shorthand syntax with additional options
This allows to combine the shorthand syntax with URI and additional arguments: ``` CPMAddPackage(URI "gh:nlohmann/[email protected]" OPTIONS "JSON_BUildTests OFF") ``` This is much shorter than the longer syntax way of writing: ``` CPMAddPackage( NAME nlohmann_json VERSION 3.9.1 GITHUB_REPOSITORY nlohmann/json OPTIONS "JSON_BuildTests OFF" ) ```
1 parent 2a9e203 commit 5913685

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

cmake/CPM.cmake

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -590,14 +590,6 @@ endfunction()
590590
function(CPMAddPackage)
591591
cpm_set_policies()
592592

593-
list(LENGTH ARGN argnLength)
594-
if(argnLength EQUAL 1)
595-
cpm_parse_add_package_single_arg("${ARGN}" ARGN)
596-
597-
# The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM
598-
set(ARGN "${ARGN};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;")
599-
endif()
600-
601593
set(oneValueArgs
602594
NAME
603595
FORCE
@@ -620,10 +612,26 @@ function(CPMAddPackage)
620612

621613
set(multiValueArgs URL OPTIONS DOWNLOAD_COMMAND PATCHES)
622614

615+
list(LENGTH ARGN argnLength)
616+
617+
# Parse single shorthand argument
618+
if(argnLength EQUAL 1)
619+
cpm_parse_add_package_single_arg("${ARGN}" ARGN)
620+
621+
# The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM
622+
set(ARGN "${ARGN};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;")
623+
624+
# Parse URI shorthand argument
625+
elseif(argnLength GREATER 1 AND "${ARGV0}" STREQUAL "URI")
626+
list(REMOVE_AT ARGN 0 1) # remove "URI gh:<...>@version#tag"
627+
cpm_parse_add_package_single_arg("${ARGV1}" ARGV0)
628+
629+
set(ARGN "${ARGV0};${ARGN}")
630+
endif()
631+
623632
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
624633

625634
# Set default values for arguments
626-
627635
if(NOT DEFINED CPM_ARGS_VERSION)
628636
if(DEFINED CPM_ARGS_GIT_TAG)
629637
cpm_get_version_from_git_tag("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION)

0 commit comments

Comments
 (0)