From 9ede4cab2ba8a405749c09922a7fe54c70ecc190 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 28 Jun 2023 09:19:22 -0400 Subject: FetchContent: Protect ExternalProject keywords from unknown arguments `ExternalProject_Add` treats all keyword arguments as multi-valued. FetchContent re-orders some keyword arguments w.r.t. unparsed arguments. Add an internal keyword argument to separate the keyword values from following unparsed arguments. This was exposed by commit 550f63447d (ExternalProject/FetchContent: Support relative remote URLs, 2023-04-21, v3.27.0-rc1~156^2) by adding `GIT_REPOSITORY` to the set of re-ordered keyword arguments. This caused its value to absorb following unparsed arguments. Fixes: #25029 --- Modules/ExternalProject.cmake | 4 ++++ Modules/FetchContent.cmake | 4 +++- Tests/RunCMake/DependencyProviders/FetchContentSerial-stdout.txt | 2 +- Tests/RunCMake/DependencyProviders/PassThroughProvider-stdout.txt | 2 +- Tests/RunCMake/DependencyProviders/Recurse-stdout.txt | 2 +- .../DependencyProviders/RedirectFetchContentSerial-stdout.txt | 2 +- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index 574b339..605908d 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -4266,6 +4266,10 @@ function(ExternalProject_Add name) # Miscellaneous options # LIST_SEPARATOR + # + # Internal options (undocumented) + # + EXTERNALPROJECT_INTERNAL_ARGUMENT_SEPARATOR ) _ep_parse_arguments( ExternalProject_Add diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake index 56fc0ed..4ff43ed 100644 --- a/Modules/FetchContent.cmake +++ b/Modules/FetchContent.cmake @@ -1336,9 +1336,11 @@ function(FetchContent_Declare contentName) endif() # Add back in the keyword args we pulled out and potentially tweaked/added + set(sep EXTERNALPROJECT_INTERNAL_ARGUMENT_SEPARATOR) foreach(key IN LISTS oneValueArgs) if(DEFINED ARG_${key}) - list(PREPEND ARG_UNPARSED_ARGUMENTS ${key} "${ARG_${key}}") + list(PREPEND ARG_UNPARSED_ARGUMENTS ${key} "${ARG_${key}}" ${sep}) + set(sep "") endif() endforeach() diff --git a/Tests/RunCMake/DependencyProviders/FetchContentSerial-stdout.txt b/Tests/RunCMake/DependencyProviders/FetchContentSerial-stdout.txt index fa4a794..5cda903 100644 --- a/Tests/RunCMake/DependencyProviders/FetchContentSerial-stdout.txt +++ b/Tests/RunCMake/DependencyProviders/FetchContentSerial-stdout.txt @@ -2,6 +2,6 @@ -- After cmake_language -- AThing_FOUND = 0 -- Intercepted FetchContent_MakeAvailable\(SomeDep\) --- Provider invoked for method FETCHCONTENT_MAKEAVAILABLE_SERIAL with args: SOURCE_DIR;.*/Tests/RunCMake/DependencyProviders;BINARY_DIR;.*/Tests/RunCMake/DependencyProviders/FetchContentSerial-build/_deps/somedep-build;SOURCE_SUBDIR;DoesNotExist +-- Provider invoked for method FETCHCONTENT_MAKEAVAILABLE_SERIAL with args: SOURCE_DIR;.*/Tests/RunCMake/DependencyProviders;BINARY_DIR;.*/Tests/RunCMake/DependencyProviders/FetchContentSerial-build/_deps/somedep-build;EXTERNALPROJECT_INTERNAL_ARGUMENT_SEPARATOR;SOURCE_SUBDIR;DoesNotExist -- FetchContent_MakeAvailable\(\) succeeded -- Configuring done diff --git a/Tests/RunCMake/DependencyProviders/PassThroughProvider-stdout.txt b/Tests/RunCMake/DependencyProviders/PassThroughProvider-stdout.txt index 0c9303a..5e412c4 100644 --- a/Tests/RunCMake/DependencyProviders/PassThroughProvider-stdout.txt +++ b/Tests/RunCMake/DependencyProviders/PassThroughProvider-stdout.txt @@ -4,4 +4,4 @@ -- Provider invoked for method FIND_PACKAGE with args: AThing;QUIET -- AThing_FOUND = 0 -- Null provider called --- Provider invoked for method FETCHCONTENT_MAKEAVAILABLE_SERIAL with args: SomeDep;SOURCE_DIR;.*/Tests/RunCMake/DependencyProviders;BINARY_DIR;.*/Tests/RunCMake/DependencyProviders/PassThroughProvider-build/_deps/somedep-build;SOURCE_SUBDIR;DoesNotExist +-- Provider invoked for method FETCHCONTENT_MAKEAVAILABLE_SERIAL with args: SomeDep;SOURCE_DIR;.*/Tests/RunCMake/DependencyProviders;BINARY_DIR;.*/Tests/RunCMake/DependencyProviders/PassThroughProvider-build/_deps/somedep-build;EXTERNALPROJECT_INTERNAL_ARGUMENT_SEPARATOR;SOURCE_SUBDIR;DoesNotExist diff --git a/Tests/RunCMake/DependencyProviders/Recurse-stdout.txt b/Tests/RunCMake/DependencyProviders/Recurse-stdout.txt index 2c2035a..25824cb 100644 --- a/Tests/RunCMake/DependencyProviders/Recurse-stdout.txt +++ b/Tests/RunCMake/DependencyProviders/Recurse-stdout.txt @@ -1,7 +1,7 @@ -- Before cmake_language -- After cmake_language -- Intercepted FetchContent_MakeAvailable\(SomeDep\) --- Provider invoked for method FETCHCONTENT_MAKEAVAILABLE_SERIAL with args: SOURCE_DIR;.*/Tests/RunCMake/DependencyProviders/Recurse-build/_deps/somedep-src;BINARY_DIR;.*/Tests/RunCMake/DependencyProviders/Recurse-build/_deps/somedep-build;DOWNLOAD_COMMAND;.*/cmake(\.exe)?;-E;echo;Download command called +-- Provider invoked for method FETCHCONTENT_MAKEAVAILABLE_SERIAL with args: SOURCE_DIR;.*/Tests/RunCMake/DependencyProviders/Recurse-build/_deps/somedep-src;BINARY_DIR;.*/Tests/RunCMake/DependencyProviders/Recurse-build/_deps/somedep-build;EXTERNALPROJECT_INTERNAL_ARGUMENT_SEPARATOR;DOWNLOAD_COMMAND;.*/cmake(\.exe)?;-E;echo;Download command called .*Download command called .*-- Should now be handled -- Configuring done diff --git a/Tests/RunCMake/DependencyProviders/RedirectFetchContentSerial-stdout.txt b/Tests/RunCMake/DependencyProviders/RedirectFetchContentSerial-stdout.txt index a293324..06f94e5 100644 --- a/Tests/RunCMake/DependencyProviders/RedirectFetchContentSerial-stdout.txt +++ b/Tests/RunCMake/DependencyProviders/RedirectFetchContentSerial-stdout.txt @@ -2,4 +2,4 @@ -- After cmake_language -- AThing_FOUND = 0 -- Redirecting FetchContent_MakeAvailable\(SomeDep\) to find_package\(\) --- Provider invoked for method FETCHCONTENT_MAKEAVAILABLE_SERIAL with args: SOURCE_DIR;.*/Tests/RunCMake/DependencyProviders;BINARY_DIR;.*/Tests/RunCMake/DependencyProviders/RedirectFetchContentSerial-build/_deps/somedep-build;SOURCE_SUBDIR;DoesNotExist +-- Provider invoked for method FETCHCONTENT_MAKEAVAILABLE_SERIAL with args: SOURCE_DIR;.*/Tests/RunCMake/DependencyProviders;BINARY_DIR;.*/Tests/RunCMake/DependencyProviders/RedirectFetchContentSerial-build/_deps/somedep-build;EXTERNALPROJECT_INTERNAL_ARGUMENT_SEPARATOR;SOURCE_SUBDIR;DoesNotExist -- cgit v0.12