aboutsummaryrefslogtreecommitdiffstats
path: root/cmake/fbs.cmake
blob: 8de30b8f61fcc8c27efa063392d9c8a827251c63 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
include(common)

function(target_fbs_source Tgt Key Src)
    get_built_tool_path(flatc_bin flatc_dependency contrib/tools/flatc/bin  flatc)

    file(RELATIVE_PATH fbsRel ${CMAKE_SOURCE_DIR} ${Src})
    get_filename_component(OutputBase ${fbsRel} NAME_WLE)
    get_filename_component(OutputDir ${CMAKE_BINARY_DIR}/${fbsRel} DIRECTORY)
    add_custom_command(
      OUTPUT
        ${CMAKE_BINARY_DIR}/${fbsRel}.h
        ${CMAKE_BINARY_DIR}/${fbsRel}.cpp
        ${OutputDir}/${OutputBase}.iter.fbs.h
        ${OutputDir}/${OutputBase}.bfbs
      COMMAND Python3::Interpreter
        ${CMAKE_SOURCE_DIR}/build/scripts/cpp_flatc_wrapper.py
        ${flatc_bin}
        ${FBS_CPP_FLAGS} ${ARGN}
        -o ${CMAKE_BINARY_DIR}/${fbsRel}.h
        ${Src}
      DEPENDS ${CMAKE_SOURCE_DIR}/build/scripts/cpp_flatc_wrapper.py ${Src} ${flatc_dependency}
      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
    )
    target_sources(${Tgt} ${Key}
      ${CMAKE_BINARY_DIR}/${fbsRel}.cpp
      ${CMAKE_BINARY_DIR}/${fbsRel}.h
      ${OutputDir}/${OutputBase}.iter.fbs.h
    )
endfunction()