Commit abc21143 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

fbcode_builder: update ThriftCppLibrary to use fb_cmake_parse_args()

Summary:
Change ThriftCppLibrary to use `fb_cmake_parse_args()`

This code doesn't really care much about handling empty arguments, so we could
use the standard `cmake_parse_arguments()` function here instead of
`fb_cmake_parse_args()`.  However, it is slightly more convenient that
`fb_cmake_parse_args()` automatically errors out on unhandled arguments, so
that we don't have to check for this ourselves.

Reviewed By: wez

Differential Revision: D16738445

fbshipit-source-id: 67b9761f2ceaf7665bd336290bb44af32fec6f4a
parent 4c502a7f
# Copyright (c) Facebook, Inc. and its affiliates. # Copyright (c) Facebook, Inc. and its affiliates.
# NOTE: If you change this file, fbcode/fboss/github/ThriftCppLibrary.cmake also # NOTE: If you change this file, fbcode/fboss/github/ThriftCppLibrary.cmake also
# needs to be changed. TODO: this should be handled via shipit. # needs to be changed. TODO: this should be handled via shipit.
include(FBCMakeParseArgs)
function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE) function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE)
# Parse the arguments # Parse the arguments
set(SERVICES) set(multi_value_args SERVICES DEPENDS OPTIONS)
set(DEPENDS) fb_cmake_parse_args(ARG "" "" "${multi_value_args}" "${ARGN}")
set(GEN_ARGS)
set(mode "UNSET")
foreach(arg IN LISTS ARGN)
if("${arg}" STREQUAL "SERVICES")
set(mode "SERVICES")
elseif("${arg}" STREQUAL "DEPENDS")
set(mode "DEPENDS")
elseif("${arg}" STREQUAL "OPTIONS")
set(mode "OPTIONS")
else()
if("${mode}" STREQUAL "SERVICES")
list(APPEND SERVICES "${arg}")
elseif("${mode}" STREQUAL "DEPENDS")
list(APPEND DEPENDS "${arg}")
elseif("${mode}" STREQUAL "OPTIONS")
list(APPEND GEN_ARGS "${arg}")
else()
message(
FATAL_ERROR
"expected SERVICES, DEPENDS, or OPTIONS argument, found ${arg}"
)
endif()
endif()
endforeach()
get_filename_component(base ${THRIFT_FILE} NAME_WE) get_filename_component(base ${THRIFT_FILE} NAME_WE)
get_filename_component( get_filename_component(
...@@ -42,11 +21,11 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE) ...@@ -42,11 +21,11 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE)
get_filename_component(include_prefix ${include_prefix} DIRECTORY) get_filename_component(include_prefix ${include_prefix} DIRECTORY)
if (NOT "${include_prefix}" STREQUAL "") if (NOT "${include_prefix}" STREQUAL "")
list(APPEND GEN_ARGS "include_prefix=${include_prefix}") list(APPEND ARG_OPTIONS "include_prefix=${include_prefix}")
endif() 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 "${ARG_OPTIONS}")
# Compute the list of generated files # Compute the list of generated files
list(APPEND generated_headers list(APPEND generated_headers
...@@ -61,7 +40,7 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE) ...@@ -61,7 +40,7 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE)
${output_dir}/gen-cpp2/${base}_data.cpp ${output_dir}/gen-cpp2/${base}_data.cpp
${output_dir}/gen-cpp2/${base}_types.cpp ${output_dir}/gen-cpp2/${base}_types.cpp
) )
foreach(service IN LISTS SERVICES) foreach(service IN LISTS ARG_SERVICES)
list(APPEND generated_headers list(APPEND generated_headers
${output_dir}/gen-cpp2/${service}.h ${output_dir}/gen-cpp2/${service}.h
${output_dir}/gen-cpp2/${service}.tcc ${output_dir}/gen-cpp2/${service}.tcc
...@@ -77,7 +56,7 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE) ...@@ -77,7 +56,7 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE)
endforeach() endforeach()
list(APPEND thrift_include_options -I ${CMAKE_SOURCE_DIR}) list(APPEND thrift_include_options -I ${CMAKE_SOURCE_DIR})
foreach(depends IN LISTS DEPENDS) foreach(depends IN LISTS ARG_DEPENDS)
get_property(thrift_include_directory get_property(thrift_include_directory
TARGET ${depends} TARGET ${depends}
PROPERTY THRIFT_INCLUDE_DIRECTORY) PROPERTY THRIFT_INCLUDE_DIRECTORY)
...@@ -114,7 +93,7 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE) ...@@ -114,7 +93,7 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE)
MAIN_DEPENDENCY MAIN_DEPENDENCY
${THRIFT_FILE} ${THRIFT_FILE}
DEPENDS DEPENDS
${DEPENDS} ${ARG_DEPENDS}
) )
# Now emit the library rule to compile the sources # Now emit the library rule to compile the sources
...@@ -139,7 +118,7 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE) ...@@ -139,7 +118,7 @@ function(add_thrift_cpp2_library LIB_NAME THRIFT_FILE)
target_link_libraries( target_link_libraries(
${LIB_NAME} ${LIB_NAME}
PUBLIC PUBLIC
${DEPENDS} ${ARG_DEPENDS}
FBThrift::thriftcpp2 FBThrift::thriftcpp2
Folly::folly Folly::folly
) )
......
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