Skip to content

Commit f4d231f

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 0bc73f4 commit f4d231f

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
@@ -575,14 +575,6 @@ endfunction()
575575
function(CPMAddPackage)
576576
cpm_set_policies()
577577

578-
list(LENGTH ARGN argnLength)
579-
if(argnLength EQUAL 1)
580-
cpm_parse_add_package_single_arg("${ARGN}" ARGN)
581-
582-
# The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM
583-
set(ARGN "${ARGN};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;")
584-
endif()
585-
586578
set(oneValueArgs
587579
NAME
588580
FORCE
@@ -605,10 +597,26 @@ function(CPMAddPackage)
605597

606598
set(multiValueArgs URL OPTIONS DOWNLOAD_COMMAND PATCHES)
607599

600+
list(LENGTH ARGN argnLength)
601+
602+
# Parse single shorthand argument
603+
if(argnLength EQUAL 1)
604+
cpm_parse_add_package_single_arg("${ARGN}" ARGN)
605+
606+
# The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM
607+
set(ARGN "${ARGN};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;")
608+
609+
# Parse URI shorthand argument
610+
elseif(argnLength GREATER 1 AND "${ARGV0}" STREQUAL "URI")
611+
list(REMOVE_AT ARGN 0 1) # remove "URI gh:<...>@version#tag"
612+
cpm_parse_add_package_single_arg("${ARGV1}" ARGV0)
613+
614+
set(ARGN "${ARGV0};${ARGN}")
615+
endif()
616+
608617
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
609618

610619
# Set default values for arguments
611-
612620
if(NOT DEFINED CPM_ARGS_VERSION)
613621
if(DEFINED CPM_ARGS_GIT_TAG)
614622
cpm_get_version_from_git_tag("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION)

0 commit comments

Comments
 (0)