Commit 60950182 authored by Chad Austin's avatar Chad Austin Committed by Facebook Github Bot

transitively carry thrift dependencies forward

Summary: eden.thrift includes fb303_core.thrift, so any cmake target that depends on eden.thrift should pull in fb303_core.thrift's include directories and libraries. Implement that machinery in CppThriftLibrary.cmake.

Reviewed By: wez

Differential Revision: D16062657

fbshipit-source-id: d5d962960e767a138a9b634a12aebccf72d6ef43
parent 593c828e
...@@ -37,7 +37,13 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE) ...@@ -37,7 +37,13 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE)
DIRECTORY DIRECTORY
) )
list(APPEND GEN_ARGS "include_prefix=${output_dir}") # Generate relative paths in #includes
file(RELATIVE_PATH include_prefix ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${THRIFT_FILE})
get_filename_component(include_prefix ${include_prefix} DIRECTORY)
if (NOT "${include_prefix}" STREQUAL "")
list(APPEND GEN_ARGS "include_prefix=${include_prefix}")
endif()
# CMake 3.12 is finally getting a list(JOIN) function, but until then # CMake 3.12 is finally getting a list(JOIN) function, but until then
# treating the list as a string and replacing the semicolons is good enough. # treating the list as a string and replacing the semicolons is good enough.
string(REPLACE ";" "," GEN_ARG_STR "${GEN_ARGS}") string(REPLACE ";" "," GEN_ARG_STR "${GEN_ARGS}")
...@@ -70,6 +76,24 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE) ...@@ -70,6 +76,24 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE)
) )
endforeach() endforeach()
list(APPEND thrift_include_options -I ${CMAKE_SOURCE_DIR})
foreach(depends IN LISTS DEPENDS)
get_property(thrift_include_directory
TARGET ${depends}
PROPERTY THRIFT_INCLUDE_DIRECTORY)
if (thrift_include_directory STREQUAL "")
message(STATUS "No thrift dependency found for ${depends}")
else()
list(APPEND thrift_include_options -I
${thrift_include_directory})
endif()
endforeach()
file(
GLOB_RECURSE THRIFT_TEMPLATE_FILES
FOLLOW_SYMLINKS ${FBTHRIFT_TEMPLATES_DIR}/*.mustache)
# Emit the rule to run the thrift compiler # Emit the rule to run the thrift compiler
add_custom_command( add_custom_command(
OUTPUT OUTPUT
...@@ -82,7 +106,7 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE) ...@@ -82,7 +106,7 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE)
--strict --strict
--templates ${FBTHRIFT_TEMPLATES_DIR} --templates ${FBTHRIFT_TEMPLATES_DIR}
--gen "mstch_cpp2:${GEN_ARG_STR}" --gen "mstch_cpp2:${GEN_ARG_STR}"
-I ${CMAKE_SOURCE_DIR} ${thrift_include_options}
-o ${output_dir} -o ${output_dir}
${CMAKE_CURRENT_SOURCE_DIR}/${THRIFT_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/${THRIFT_FILE}
WORKING_DIRECTORY WORKING_DIRECTORY
...@@ -97,16 +121,18 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE) ...@@ -97,16 +121,18 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE)
add_library(${LIB_NAME} STATIC add_library(${LIB_NAME} STATIC
${generated_sources} ${generated_sources}
) )
set_property(
TARGET ${LIB_NAME} install(
PROPERTY PUBLIC_HEADER FILES ${generated_headers}
${generated_headers} DESTINATION $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/gen-cpp2
) )
target_include_directories( target_include_directories(
${LIB_NAME} ${LIB_NAME}
PRIVATE
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
PUBLIC PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
${FOLLY_INCLUDE_DIR} ${FOLLY_INCLUDE_DIR}
${FBTHRIFT_INCLUDE_DIR} ${FBTHRIFT_INCLUDE_DIR}
) )
...@@ -117,4 +143,15 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE) ...@@ -117,4 +143,15 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE)
FBThrift::thriftcpp2 FBThrift::thriftcpp2
Folly::folly Folly::folly
) )
set_target_properties(
${LIB_NAME}
PROPERTIES
EXPORT_PROPERTIES "THRIFT_INCLUDE_DIRECTORY"
THRIFT_INCLUDE_DIRECTORY ${CMAKE_SOURCE_DIR}
)
get_property(thrift_include_directory
TARGET ${LIB_NAME}
PROPERTY THRIFT_INCLUDE_DIRECTORY)
endfunction() endfunction()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment