smanders / externpro

build external projects with cmake
MIT License
13 stars 12 forks source link

add flatbuffers #283

Closed smanders closed 3 years ago

smanders commented 4 years ago

https://github.com/google/flatbuffers

smanders commented 3 years ago

flatbuffers patch https://github.com/google/flatbuffers/compare/v1.12.0...smanders:xp1.12.0

smanders commented 3 years ago

BuildFlatBuffers.cmake and FindFlatBuffers.cmake aren't cmake install()'ed

it's almost as if it's not expected that projects use these cmake functions, or maybe they are expected to be available to projects which already use CMake by building FlatBuffers as part of the project as described in "Using in CMake-based projects" http://google.github.io/flatbuffers/flatbuffers_guide_building.html

I did find an issue describing some of the same confusion I have regarding the cmake provided by FlatBuffers https://github.com/google/flatbuffers/issues/4690 -- and it appears that the answer as to why they're doing things the way they do is "because it grew this way"

it's just different than protobuf and the cmake provided by protobuf, so just expect differences!

smanders commented 3 years ago

with the use script enhancements and new xpFlatBuffersBuild() cmake function, projects can generate C++ headers with cmake similar to the following

set(src_fbs_srcs
  src/fbs/GruHardTimeout.fbs
  )
source_group(src\\fbs FILES ${src_fbs_srcs})
list(APPEND ${lib_name}_libsrcs ${src_fbs_srcs})
#######################################
add_library(${lib_name} STATIC ${${lib_name}_libsrcs})
target_include_directories(${lib_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
xpFindPkg(PKGS flatbuffers)
xpFlatBuffersBuild(TARGET ${lib_name} SCHEMAS ${src_fbs_srcs})
target_link_libraries(${lib_name} PRIVATE xpro::flatbuffers)

you can see all the (optional) arguments xpFlatBuffersBuild() currently accepts https://github.com/smanders/externpro/blob/6189183107a281dfc9a0fb3d1b6898cdb4201b73/projects/use/usexp-flatbuffers-config.cmake#L22-L24

since this is a wrapper of the build_flatbuffers() cmake function, see it's documentation for a description of these arguments https://github.com/google/flatbuffers/blob/v1.12.0/CMake/BuildFlatBuffers.cmake#L18-L45

if GENERATED_INCLUDES_DIR isn't specified, the default is for the generated includes directory to be in ${CMAKE_CURRENT_BINARY_DIR}/fbs and by default this directory is a PRIVATE include directory (if TARGET is specified), but can be made PUBLIC with an option

xpFlatBuffersBuild(TARGET ${lib_name} SCHEMAS ${src_fbs_srcs} PUBLIC_INCLUDES)
smanders commented 3 years ago

completed with commits to dev branch referenced above