Skip to content

Commit b2a1bca

Browse files
committed
feature: allow additional arguments after shorthand syntax
This allows to combine the shorthand syntax with additional arguments: ``` CPMAddPackage("gh:nlohmann/json@3.9.1" 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 b2a1bca

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

cmake/CPM.cmake

Lines changed: 20 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,29 @@ 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(
611+
argnLength GREATER 1
612+
AND "${ARGV0}" STREQUAL "URI"
613+
)
614+
list(REMOVE_AT ARGN 0 1) # remove "URI gh:<...>@version#tag"
615+
cpm_parse_add_package_single_arg("${ARGV1}" ARGV0)
616+
617+
set(ARGN "${ARGV0};${ARGN}")
618+
endif()
619+
608620
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
609621

610622
# Set default values for arguments
611-
612623
if(NOT DEFINED CPM_ARGS_VERSION)
613624
if(DEFINED CPM_ARGS_GIT_TAG)
614625
cpm_get_version_from_git_tag("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION)

0 commit comments

Comments
 (0)