Open qh-huang opened 2 years ago
This is how I do it: (Note: these are only snippets, it's not a fully working example)
# This generates a conanfile.txt file, you can also specify this in a conanfile.txt itself.
conan_cmake_configure(
REQUIRES
flatbuffers/2.0.0
GENERATORS cmake_find_package
IMPORTS "bin, flatc -> ./bin" # macOS
IMPORTS "bin, flatc.exe -> ./bin" # Windows
OPTIONS flatbuffers:options_from_context=False
OPTIONS flatbuffers:flatc=True
)
# Flatbuffers
if (WIN32)
set(FLATBUFFERS_FLATC_EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/bin/flatc.exe)
else ()
set(FLATBUFFERS_FLATC_EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/bin/flatc)
endif ()
flatbuffers_generate_headers(
TARGET FlatbuffersGeneratedHeaders
SCHEMAS SomeSchema.fbs
FLAGS --gen-object-api --reflect-names --gen-name-strings --gen-compare
)
include_directories(${CMAKE_BINARY_DIR}/FlatbuffersGeneratedHeaders)
It's related to #8374.
As I have a conanfile.txt which includes flatbuffers/2.0.0 with option flatbuffers:flatc=True, and it can be installed correctly.
However, cmake complains about
flatc
is not found when I try to generate flatbuffer headers withbuild_flatbuffers
macro.(I tried flatbuffers:options_from_context=False after I read #8374 but it's not working)
What's the recommended way to use
flatbuffer
along with conan?To make it more clear, following are my
conanfile.txt
andCMakeLists.txt
. I'd like to know what it should be to use flatbuffers in my project. Thanks.