Skip to content

Commit

Permalink
CMake: Handle generator expressions requiring a target for pkg-config (
Browse files Browse the repository at this point in the history
…facebook#1433)

Summary:
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 facebook#1414.

Pull Request resolved: facebook#1433

Reviewed By: yfeldblum

Differential Revision: D23433365

Pulled By: Orvid

fbshipit-source-id: 6ef5f180e13b41f0c92137f53fd8c19ba6355dd6
  • Loading branch information
tambry authored and dotconnor committed Mar 18, 2021
1 parent e4be545 commit 8f9232d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
14 changes: 13 additions & 1 deletion CMake/GenPkgConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,19 @@ 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
"<COMPILE_LANG_AND_ID:CUDA,NVIDIA>" "<COMPILE_LANGUAGE:CUDA>"
cflags "${cflags}"
)
endif()

set("${var_prefix}_CFLAGS" "${cflags}" PARENT_SCOPE)
set("${var_prefix}_PRIVATE_LIBS" "${private_libs}" PARENT_SCOPE)
endfunction()
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,18 @@ 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
Expand Down

0 comments on commit 8f9232d

Please sign in to comment.