From 43f9f96c0c97a191fe5eb92502d740e7f123c685 Mon Sep 17 00:00:00 2001 From: Craig Hutchinson Date: Tue, 7 Mar 2023 15:15:55 +0000 Subject: [PATCH] Preserving forwarding of empty string arguments Also: - Support cmake-format on Windows - Auto fixes some whitespace - `CPMFindPackage` not updated --- .cmake-format | 1 + cmake/CPM.cmake | 47 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/.cmake-format b/.cmake-format index 24850af3..a52417dc 100644 --- a/.cmake-format +++ b/.cmake-format @@ -1,6 +1,7 @@ format: tab_size: 2 line_width: 100 + line_ending: auto dangle_parens: true parse: diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index 92953b8c..f08e288a 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -506,16 +506,34 @@ function(cpm_override_fetchcontent contentName) endfunction() # Download and add a package from source -function(CPMAddPackage) +macro(CPMAddPackage) + set(__ARGN "${ARGN}") + list(LENGTH __ARGN __ARGN_Length) + if(__ARGN_Length EQUAL 1) + cpm_add_package_single_arg(${ARGN}) + else() + # Forward preserving empty string arguments + # (https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4729) + set(__ARGN_Quoted) + foreach(__ARG IN LISTS __ARGN) + string(APPEND __ARGN_Quoted " [==[${__ARG}]==]") + endforeach() + cmake_language(EVAL CODE "cpm_add_package_multi_arg( ${__ARGN_Quoted} )") + endif() +endmacro() + +function(cpm_add_package_single_arg arg) cpm_set_policies() + cpm_parse_add_package_single_arg("${arg}" ARGN) - list(LENGTH ARGN argnLength) - if(argnLength EQUAL 1) - cpm_parse_add_package_single_arg("${ARGN}" ARGN) + # The shorthand syntax implies EXCLUDE_FROM_ALL + list(APPEND ARGN EXCLUDE_FROM_ALL YES) - # The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM - set(ARGN "${ARGN};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;") - endif() + cpm_add_package_multi_arg(${ARGN}) # Forward function arguments to CPMAddPackage() +endfunction() + +function(cpm_add_package_multi_arg) + cpm_set_policies() set(oneValueArgs NAME @@ -531,7 +549,6 @@ function(CPMAddPackage) DOWNLOAD_COMMAND FIND_PACKAGE_ARGUMENTS NO_CACHE - SYSTEM GIT_SHALLOW EXCLUDE_FROM_ALL SOURCE_SUBDIR @@ -539,7 +556,7 @@ function(CPMAddPackage) set(multiValueArgs URL OPTIONS) - cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}") + cmake_parse_arguments(PARSE_ARGV 0 CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}") # Set default values for arguments @@ -647,7 +664,7 @@ function(CPMAddPackage) cpm_check_if_package_already_added(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}") return() endif() - + if(NOT CPM_ARGS_FORCE) if(CPM_USE_LOCAL_PACKAGES OR CPM_LOCAL_PACKAGES_ONLY) cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS}) @@ -917,7 +934,13 @@ function(cpm_declare_fetch PACKAGE VERSION INFO) return() endif() - FetchContent_Declare(${PACKAGE} ${ARGN}) + # Forward preserving empty string arguments + # (https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4729) + set(__argsQuoted) + foreach(__item IN LISTS ARGN) + string(APPEND __argsQuoted " [==[${__item}]==]") + endforeach() + cmake_language(EVAL CODE "FetchContent_Declare(${PACKAGE} ${__argsQuoted} )") endfunction() # returns properties for a package previously defined by cpm_declare_fetch @@ -1105,7 +1128,7 @@ function(cpm_prettify_package_arguments OUT_VAR IS_IN_COMMENT) GIT_SHALLOW ) set(multiValueArgs OPTIONS) - cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + cmake_parse_arguments(PARSE_ARGV 0 CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}") foreach(oneArgName ${oneValueArgs}) if(DEFINED CPM_ARGS_${oneArgName})