1# Copyright 2022 Meta
2# SPDX-License-Identifier: Apache-2.0
3
4find_program(THRIFT_EXECUTABLE thrift)
5if(NOT THRIFT_EXECUTABLE)
6  message(FATAL_ERROR "The 'thrift' command was not found")
7endif()
8
9function(thrift
10    target          # CMake target (for dependencies / headers)
11    lang            # The language for generated sources
12    lang_opts       # Language options (e.g. ':no_skeleton')
13    out_dir         # Output directory for generated files
14                    # (do not include 'gen-cpp', etc)
15    source_file     # The .thrift source file
16    options         # Additional thrift options
17
18                    # Generated files in ${ARGN}
19    )
20  file(MAKE_DIRECTORY ${out_dir})
21  add_custom_command(
22    OUTPUT ${ARGN}
23    COMMAND
24    ${THRIFT_EXECUTABLE}
25    --gen ${lang}${lang_opts}
26    -o ${out_dir}
27    ${source_file}
28    ${options}
29    DEPENDS ${source_file}
30    )
31
32    target_include_directories(${target} PRIVATE ${out_dir}/gen-${lang})
33endfunction()
34