Skip to content

FetchContent: Fix syntax to forward FIND_PACKAGE_ARGS arguments correctly

CMake version: 3.27.7 OS: Manjaro

When CMAKE_FIND_PACKAGE_TARGETS_GLOBAL is se to TRUE and then FetchContent_Declare() is called with FIND_PACKAGE_ARGS arguments:

cmake_minimum_required(VERSION 3.27)

project(test)

set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL TRUE)

include(FetchContent)
FetchContent_Declare(
  googletest
  GIT_REPOSITORY https://github.com/google/googletest.git
  GIT_TAG        703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
  FIND_PACKAGE_ARGS NAMES GTest
)

add_executable(test test.cpp)

then CMake fails with an obscure error:

CMake Error at /usr/share/cmake/Modules/FetchContent.cmake:1187:EVAL:1:
  Syntax Error in cmake code at column 107

  Argument not separated from preceding token by whitespace.
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FetchContent.cmake:1187 (cmake_language)
  /usr/share/cmake/Modules/FetchContent.cmake:1351:EVAL:1 (__FetchContent_declareDetails)
  /usr/share/cmake/Modules/FetchContent.cmake:1351 (cmake_language)
  CMakeLists.txt:8 (FetchContent_Declare)


CMake Error at /usr/share/cmake/Modules/FetchContent.cmake:1187 (cmake_language):
  cmake_language unknown error.
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FetchContent.cmake:1351:EVAL:1 (__FetchContent_declareDetails)
  /usr/share/cmake/Modules/FetchContent.cmake:1351 (cmake_language)
  CMakeLists.txt:8 (FetchContent_Declare)


-- Configuring incomplete, errors occurred!

Seems like there is a mix of list/string operations. When string operations are used only, it works.

Topic-rename: FetchContent-find_package-args

Edited by Brad King

Merge request reports