distinguish the multiple `rpc` functions in ClientCheck
[hiphop-php.git] / third-party / mcrouter / mcrouter-thrift-codegen.cmake
blob939631508af2d9d78ac8dbe827da9a68eef50b73
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")
7 set(CODEGEN_SOURCES)
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
13   set(OUTPUTS
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"
18   )
19   if("${BASENAME}" MATCHES "Service$")
20     string(REPLACE "Service" "" SERVICE "${BASENAME}")
21     list(APPEND OUTPUTS
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"
26     )
27   endif()
28   list(APPEND CODEGEN_SOURCES ${OUTPUTS})
30   add_custom_command(
31     OUTPUT ${OUTPUTS}
32     COMMAND
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}"
38     BYPRODUCTS ${OUTPUTS}
39     WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
40     DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_SUBDIR}/${SOURCE}"
41   )
42   add_custom_target("mcrouter_thrift1_${BASENAME}" DEPENDS ${OUTPUTS})
43   add_dependencies(mcrouter_thrift1_codegen "mcrouter_thrift1_${BASENAME}")
44 endmacro()
46 macro(carbon_thrift1 SOURCE)
47   mcrouter_thrift1_impl("mstch_cpp2:stack_arguments,sync_methods_return_try" "${SOURCE}" mcrouter/lib/carbon)
48 endmacro()
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"
56     "${SOURCE}"
57     mcrouter/lib/network/gen
58   )
59 endmacro()
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}")
72 install(
73   TARGETS mcrouter_thrift_lib
74   LIBRARY ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}