From 61d9ede8d1f0ece652724eca0397ce9bcb61250a Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Mon, 31 Aug 2020 13:37:26 +0300 Subject: [PATCH] CMake: Handle generator expressions requiring a target for pkg-config CMake's find modules may have target-based generator expressions, which get propagated to us when generating the pkg-config file. CMake 3.19 introduces the TARGET argument to file(GENERATE), which allows resolving such generator expressions and will avoid future issues. A workaround proposed by @adriaandegroot is added for CMake 3.18. Additionally changed list->string conversion to use list(JOIN) instead of string replacement. Fixes #1414. --- CMake/GenPkgConfig.cmake | 9 ++++++++- CMakeLists.txt | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CMake/GenPkgConfig.cmake b/CMake/GenPkgConfig.cmake index f8701b469a8..31c1e3ce6e0 100644 --- a/CMake/GenPkgConfig.cmake +++ b/CMake/GenPkgConfig.cmake @@ -92,7 +92,14 @@ function(gen_pkgconfig_vars) # Set the output variables string(REPLACE ";" " " cflags "${cflags}") - set("${var_prefix}_CFLAGS" "${cflags}" PARENT_SCOPE) string(REPLACE ";" " " private_libs "${private_libs}") + + # Since CMake 3.18 FindThreads may include a generator expression requiring a target, which gets propagated to us through INTERFACE_COMPILE_OPTIONS. + # Before CMake 3.19 there's no way to solve this in a general way, so we work around the specific case. See #1414 and CMake bug #21074. + if(CMAKE_VERSION VERSION_LESS 3.19) + string(REPLACE "" "" cflags "${cflags}") + endif() + + set("${var_prefix}_CFLAGS" "${cflags}" PARENT_SCOPE) set("${var_prefix}_PRIVATE_LIBS" "${private_libs}" PARENT_SCOPE) endfunction() diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a37b4a71fc..2f547bb503f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -436,10 +436,17 @@ configure_file( ${CMAKE_CURRENT_BINARY_DIR}/libfolly.pc.gen @ONLY ) + +# Specify target to allow resolving generator expressions requiring a target for CMake >=3.19. See #1414. +if(CMAKE_VERSION VERSION_GREATER 3.18) + set(target_arg TARGET folly_deps) +endif() + file( GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libfolly.pc INPUT ${CMAKE_CURRENT_BINARY_DIR}/libfolly.pc.gen + ${target_arg} ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libfolly.pc