fbs.cmake 1.0 KB

1234567891011121314151617181920212223242526272829
  1. include(common)
  2. function(target_fbs_source Tgt Key Src)
  3. get_built_tool_path(flatc_bin flatc_dependency contrib/tools/flatc/bin flatc)
  4. file(RELATIVE_PATH fbsRel ${CMAKE_SOURCE_DIR} ${Src})
  5. get_filename_component(OutputBase ${fbsRel} NAME_WLE)
  6. get_filename_component(OutputDir ${CMAKE_BINARY_DIR}/${fbsRel} DIRECTORY)
  7. add_custom_command(
  8. OUTPUT
  9. ${CMAKE_BINARY_DIR}/${fbsRel}.h
  10. ${CMAKE_BINARY_DIR}/${fbsRel}.cpp
  11. ${OutputDir}/${OutputBase}.iter.fbs.h
  12. ${OutputDir}/${OutputBase}.bfbs
  13. COMMAND Python3::Interpreter
  14. ${CMAKE_SOURCE_DIR}/build/scripts/cpp_flatc_wrapper.py
  15. ${flatc_bin}
  16. ${FBS_CPP_FLAGS} ${ARGN}
  17. -o ${CMAKE_BINARY_DIR}/${fbsRel}.h
  18. ${Src}
  19. DEPENDS ${CMAKE_SOURCE_DIR}/build/scripts/cpp_flatc_wrapper.py ${Src} ${flatc_dependency}
  20. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  21. )
  22. target_sources(${Tgt} ${Key}
  23. ${CMAKE_BINARY_DIR}/${fbsRel}.cpp
  24. ${CMAKE_BINARY_DIR}/${fbsRel}.h
  25. ${OutputDir}/${OutputBase}.iter.fbs.h
  26. )
  27. endfunction()