Skip to content

Commit 5a7b584

Browse files
committed
feature: allow additional arguments after shorthand syntax
This allows to combine the shorthand syntax with additional arguments: ``` CPMAddPackage("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 5a7b584

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

cmake/CPM.cmake

Lines changed: 22 additions & 8 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,6 +597,28 @@ 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 shorthand argument as first argument but with following arguments
610+
elseif(
611+
argnLength GREATER 1
612+
AND NOT "${ARGV0}" IN_LIST oneValueArgs
613+
AND NOT "${ARGV0}" IN_LIST multiValueArgs
614+
)
615+
list(POP_FRONT ARGN)
616+
cpm_parse_add_package_single_arg("${ARGV0}" ARGV0)
617+
618+
# The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM
619+
set(ARGN "${ARGV0};${ARGN};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;")
620+
endif()
621+
608622
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
609623

610624
# Set default values for arguments

0 commit comments

Comments
 (0)