As the flatbuffers cmake is now setup, the compiler, headers and libs are all linked.
While for a cross compilation you would like:
Separating these would also help things like conan. Say for example you want to cross compile from Windows to QNX (my use case), you would want flatc as a build_require and flatbuffers as a require. This is now hard to do without writing custom cmake files. I would propose that you have multiple find package you can do which would be something like:
-flatbuffers::flatbuffers (headers)
-flatbuffers::flatc (compiler)
-flatbuffers::flathash (flathash lib)
-flatbuffers;:flatlib (idl parser and such)
(similar to https://cmake.org/cmake/help/latest/module/FindProtobuf.html).
Let me know if I missed anything, but at the time I am a bit unsure how to best use flatbuffers & conan while cross-compiling, except through https://github.com/mjvk/conan-flatc_installer which is a bit hacky...
Wouldn't you simply do a regular build on the host OS (which then gets you flatc etc), and then build for the target with FLATBUFFERS_BUILD_FLATC off for the target?
Manually that works fine indeed! That is what I would like do to with Conan as well. Through Conan that would mean including the same package twice with different options which is not possible (normally a library and a compiler are not in the same package). In addition you need to tell conan that for flatc it can ignore the target os and arch and should only check host os compatibility.
But I see that you might already have this with the config files. I was a bit thrown by the FindFlatbuffers.cmake and the Flatbuffersconfig.cmake being present. I need to have a look.
Something like https://github.com/bincrafters/conan-protobuf would be an example how some tackle this. This would mean that you include flatc using find_package(Flatbuffers) and the libs with find_package(flatbuffers::FlatbuffersTargets) or something in that direction.
Not too familiar with Conan, but if you want to improve our Conan files to make this easier, that'd be welcome!
@uilianries may have opinions :)
Hi everyone! Indeed Conan is not able to separate flatc and flatbuffers libs automatically.
You have few options in this case, like creating separated recipes for each artifact, or build multiple time and separating the output manually. The first option is the best approach, Protobuf has the same problem by the way. We have separated recipes for flatc here:
https://github.com/conan-io/conan-center-index/blob/master/recipes/flatc/all/conanfile.py
https://github.com/conan-io/conan-center-index/blob/master/recipes/flatbuffers/all/conanfile.py
To install the respective packages:
conan install -r conan-center flatc/1.11.0@
conan install -r conan-center flatbuffers/1.11.0@
Since Conan 1.18.2 packages can be built and distributed without a namespace.
Ah that is great, I missed the flatc one! I have one more question, all the .cmake files are not included in the package. These are quite useful with the cmake_paths generator. I made an issue for that in the conan-center repo, so I will close this one. Thank you for the help!
Most helpful comment
Hi everyone! Indeed Conan is not able to separate flatc and flatbuffers libs automatically.
You have few options in this case, like creating separated recipes for each artifact, or build multiple time and separating the output manually. The first option is the best approach, Protobuf has the same problem by the way. We have separated recipes for flatc here:
https://github.com/conan-io/conan-center-index/blob/master/recipes/flatc/all/conanfile.py
https://github.com/conan-io/conan-center-index/blob/master/recipes/flatbuffers/all/conanfile.py
To install the respective packages:
Since Conan 1.18.2 packages can be built and distributed without a namespace.