Skip to content

Commit 00ff943

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 a8144f5 commit 00ff943

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

cmake/CPM.cmake

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -515,14 +515,6 @@ endfunction()
515515
function(CPMAddPackage)
516516
cpm_set_policies()
517517

518-
list(LENGTH ARGN argnLength)
519-
if(argnLength EQUAL 1)
520-
cpm_parse_add_package_single_arg("${ARGN}" ARGN)
521-
522-
# The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM
523-
set(ARGN "${ARGN};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;")
524-
endif()
525-
526518
set(oneValueArgs
527519
NAME
528520
FORCE
@@ -544,6 +536,24 @@ function(CPMAddPackage)
544536

545537
set(multiValueArgs URL OPTIONS DOWNLOAD_COMMAND)
546538

539+
list(LENGTH ARGN argnLength)
540+
541+
# Parse single shorthand argument
542+
if(argnLength EQUAL 1)
543+
cpm_parse_add_package_single_arg("${ARGN}" ARGN)
544+
545+
# The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM
546+
set(ARGN "${ARGN};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;")
547+
548+
# Parse shorthand argument as first argument but with following arguments
549+
elseif(argnLength GREATER 1 AND NOT "${ARGV0}" IN_LIST oneValueArgs AND NOT "${ARGV0}" IN_LIST multiValueArgs)
550+
list(POP_FRONT ARGN)
551+
cpm_parse_add_package_single_arg("${ARGV0}" ARGV0)
552+
553+
# The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM
554+
set(ARGN "${ARGV0};${ARGN};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;")
555+
endif()
556+
547557
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
548558

549559
# Set default values for arguments

0 commit comments

Comments
 (0)