1 # ----- Generate C++ sources from .thrift files -----
2 include(GNUInstallDirs)
4 add_custom_target(mcrouter_thrift1_codegen)
6 set(CODEGEN_SOURCES_DIR "${CMAKE_CURRENT_BINARY_DIR}/thrift-gen/src")
9 macro(mcrouter_thrift1_impl GEN_ARGS SOURCE SOURCE_SUBDIR)
10 get_filename_component(BASENAME "${SOURCE}" NAME_WE)
11 file(MAKE_DIRECTORY "${CODEGEN_SOURCES_DIR}/${SOURCE_SUBDIR}")
12 # Taken from FBThriftCppLibrary.cmake in fbcode_builder
14 "${CODEGEN_SOURCES_DIR}/${SOURCE_SUBDIR}/gen-cpp2/${BASENAME}_constants.cpp"
15 "${CODEGEN_SOURCES_DIR}/${SOURCE_SUBDIR}/gen-cpp2/${BASENAME}_data.cpp"
16 "${CODEGEN_SOURCES_DIR}/${SOURCE_SUBDIR}/gen-cpp2/${BASENAME}_types.cpp"
17 "${CODEGEN_SOURCES_DIR}/${SOURCE_SUBDIR}/gen-cpp2/${BASENAME}_metadata.cpp"
19 if("${BASENAME}" MATCHES "Service$")
20 string(REPLACE "Service" "" SERVICE "${BASENAME}")
22 "${CODEGEN_SOURCES_DIR}/${SOURCE_SUBDIR}/gen-cpp2/${SERVICE}.cpp"
23 "${CODEGEN_SOURCES_DIR}/${SOURCE_SUBDIR}/gen-cpp2/${SERVICE}AsyncClient.cpp"
24 "${CODEGEN_SOURCES_DIR}/${SOURCE_SUBDIR}/gen-cpp2/${SERVICE}_processmap_binary.cpp"
25 "${CODEGEN_SOURCES_DIR}/${SOURCE_SUBDIR}/gen-cpp2/${SERVICE}_processmap_compact.cpp"
28 list(APPEND CODEGEN_SOURCES ${OUTPUTS})
33 FBThrift::thrift1 --gen
34 "${GEN_ARGS},include-prefix=${SOURCE_SUBDIR}"
35 -o "${CODEGEN_SOURCES_DIR}/${SOURCE_SUBDIR}"
36 -I "${SOURCE_SUBDIR}" -I "${CMAKE_CURRENT_SOURCE_DIR}"
37 "${SOURCE_SUBDIR}/${SOURCE}"
39 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
40 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_SUBDIR}/${SOURCE}"
42 add_custom_target("mcrouter_thrift1_${BASENAME}" DEPENDS ${OUTPUTS})
43 add_dependencies(mcrouter_thrift1_codegen "mcrouter_thrift1_${BASENAME}")
46 macro(carbon_thrift1 SOURCE)
47 mcrouter_thrift1_impl("mstch_cpp2:stack_arguments,sync_methods_return_try" "${SOURCE}" mcrouter/lib/carbon)
50 carbon_thrift1(carbon.thrift)
51 carbon_thrift1(carbon_result.thrift)
53 macro(network_thrift1 SOURCE)
54 mcrouter_thrift1_impl(
55 "mstch_cpp2:stack_arguments,sync_methods_return_try,terse_writes"
57 mcrouter/lib/network/gen
61 network_thrift1(Common.thrift)
62 network_thrift1(Memcache.thrift)
63 network_thrift1(MemcacheService.thrift)
65 # ----- Build a static library from the generated C++ sources ------
67 add_library(mcrouter_thrift_lib STATIC EXCLUDE_FROM_ALL ${CODEGEN_SOURCES})
68 add_dependencies(mcrouter_thrift_lib mcrouter_thrift1_codegen)
69 target_link_libraries(mcrouter_thrift_lib PUBLIC FBThrift::thriftcpp2)
70 target_include_directories(mcrouter_thrift_lib PUBLIC ${CODEGEN_SOURCES_DIR} "${JEMALLOC_INCLUDE_DIR}")
73 TARGETS mcrouter_thrift_lib
74 LIBRARY ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}