-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#168: add cmake helper function to generate flatbuffer code #169
Conversation
endif() | ||
|
||
message(VERBOSE "Executing command ${FLATCC_COMPILER} ${FLATCC_CC_OPTIONS} -o ${FLATCC_GENERATED_SOURCE_DIRECTORY} ${FLATCC_DEFINITION_FILES}") | ||
add_custom_command(OUTPUT ${FLATCC_EXPECTED_OUTPUT_FILES} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs DEPENDS
for dependency tracking of the input flatbuffer files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without reading carefully and from memory, just adding DEPENDS will break Ninja build because CMake doesn't handle dependecies properly, even if it works with Make. If you look at some of the examples that build with CMAKE, these are rather clumsy because of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But without DEPENDS, the target sources don't get regenerated when the input sources get modified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The add_custom_command
documentation does mention ninja
with multiple arguments, but not with DEPENDS
btw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know because I am not a CMake expert. But I do know that I have spent several days trying to make it work (or something similar). Another who believed he could fix it had to admit he couldn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking into it now, I'll open a pr for installing flatcc-config.cmake
.
This allows your users to use flatcc by doing find_package(flatcc REQUIRED)
and call flatcc using flatcc::flatcc
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like on every make
, all tests are re-built.
This is because the dependency tree is not correct.
I'll look into that too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wdobbe
You can then re-use/rebase your FlatccGenerateSources.cmake
script on my pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, here is an old discussion about broken dependencies - I haven't reread it, but linked here for reference:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking into it now, I'll open a pr for installing
flatcc-config.cmake
.This allows your users to use flatcc by doing
find_package(flatcc REQUIRED)
and call flatcc usingflatcc::flatcc
.
Yes, that is a good idea. I have plenty examples of how to generate the config files (correctly) so if you want me to do it, let me know.
set(FLATCC_BIN_PATH "$ENV{FLATCC_BUILD_BIN_PATH}") | ||
if (FLATCC_BIN_PATH) | ||
#user provided location where asn1c compiler executable is installed | ||
find_program(FLATCC_COMPILER flatcc | ||
PATHS ${FLATCC_BIN_PATH} | ||
NO_DEFAULT_PATH | ||
NO_SYSTEM_ENVIRONMENT_PATH | ||
NO_CMAKE_SYSTEM_PATH | ||
) | ||
else() | ||
#Find compiler exe | ||
find_program(FLATCC_COMPILER flatcc) | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok to do this with one find_program
:
- it's possible to override by doing
-DFLATCC_COMPILER=xxx
. - Using
-DFLATCC_ROOT
, you can set a prefix of flatxx - Using the
FLATCC_ROOT
environment variable, you can also set a prefix
I think the options NO_DEFAULT_PATH
, NO_SYSTEM_ENVIRONMENT_PATH
and NO_CMAKE_SYSTEM_PATH
are not needed.
set(FLATCC_BIN_PATH "$ENV{FLATCC_BUILD_BIN_PATH}") | |
if (FLATCC_BIN_PATH) | |
#user provided location where asn1c compiler executable is installed | |
find_program(FLATCC_COMPILER flatcc | |
PATHS ${FLATCC_BIN_PATH} | |
NO_DEFAULT_PATH | |
NO_SYSTEM_ENVIRONMENT_PATH | |
NO_CMAKE_SYSTEM_PATH | |
) | |
else() | |
#Find compiler exe | |
find_program(FLATCC_COMPILER flatcc) | |
endif() | |
#user provided location where asn1c compiler executable is installed | |
find_program(FLATCC_COMPILER flatcc | |
PATHS ${FLATCC_ROOT} ENV FLATCC_ROOT | |
PATH_SUFFIXES bin | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#user provided location where asn1c compiler executable is installed
asn1c?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, copy/paste error from a similar script for the ASN1C compiler.
I'll correct that.
@@ -0,0 +1,86 @@ | |||
cmake_minimum_required(VERSION 3.5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would split this file in 2:
- Export the
flatcc
target asflatcc::flatcc
withinstall(TARGETS)
andinstall(EXPORT)
. - Inside
flatcc-config.cmake
, doinclude("${CMAKE_CURRENT_LIST_DIR}/FlatccGenerateSources.cmake")
which then only contains the function. Instead of theFLATCC_COMPILER
, it can then use the importedflatcc::flatcc
executable target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would be a better solution.
Can you provide an example within FlatCC's test cases that uses this module? I'm not convinced I want to accept this PR because I'd like to keep CMake maintenance to a minimum. It is has been rather painful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding minimum required version, there is reason why flatcc uses cmake_minimum_required (VERSION 2.8)
Otherwise it will not build on some older conservative platforms. If it is really necessary to use a more recent version and it only affects users own programs opting in to this feature then maybe OK, but otherwise it would interfere with portability which is important to FlatCC.
|
||
Optionally you can let cmake know the directory where the flatcc executable | ||
is located in environment variable `FLATCC_BUILD_BIN_PATH`. This is especially | ||
usefull when cross-compiling. In that case you should provide the directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding minimum required version, there is reason why flatcc uses cmake_minimum_required (VERSION 2.8)
Otherwise it will not build on some older conservative platforms. If it is really necessary to use a more recent version and it only affects users own programs opting in to this feature then maybe OK, but otherwise it would interfere with portability which is important to FlatCC.
Edit: sorry was confused with PRs from Conan.
I had to update the cmake_minimum_required version from 2.8 to 3.1 in another recipe PR today because a conan-center hook rejects the PR if the cmake_minimum_required is not at least 3.1.
In this case the minimum cmake version is 3.5 because from that version cmake function cmake_parse_arguments checks for value arguments that are miss their value, so it makes the function more fool-proof.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm suggesting to add an example of using this module within the FlatCC project, but perhaps not replacing existing since it could break portability with CMake version. I'm not sure if the module only works after CMake install and the README should probably also clarify how to make it available.
Ok, I will do that.
The only thing to do is that you have to do to make the module work is add the FlatCC cmake subdir to your CMAKE_MODULE_PATH.
Edit: when we also export a flatcc cmake config file as suggested by @madebr then appending CMAKE_MODULE_PATH is no longer necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if it works the same for correct arguments on earlier versions then an earlier MIN version will still support the check for users with a recent CMake while not breaking the build for those who do not.
BTW: any idea why Travis build breaks on MacOS? Is it just Travis that hasn't upgraded its platform properly? |
This is how I call it in one of our company cmake files:
|
I'm suggesting to add an example of using this module within the FlatCC project, but perhaps not replacing existing since it could break portability with CMake version. I'm not sure if the module only works after CMake install and the README should probably also clarify how to make it available. |
When adding flatcc to conan-center-index we also had problems on MacOS because of a new security feature called Security Integrity Protection (SIP). That could be the case, however I currently don't see build logs for MacOS for this PR? And the only Mac I currently have access to (due to Covid-19 lockdown) is too old to have SIP. |
Ok, I will do that once changes suggested by you and @madebr are implemented. |
I'm developing flatcc on Mac Intel with Ninja. Travis has been building without issues before, except that it is often very slow. I think all travis builds use Make. It is unlikely that this PR triggered a build issue, but it is the first time that I see it. |
BTW: conan is different because it uses a binary dist, I think. Building from source should only give SIP issues if the core tools are broken (homebrew?, clang, make, cmake). |
This is the comment I added for the workaround at that time (see here and here):
So the issue I talked about only arises when the flatcc executable links dynamically to the flatcc library and flatcc is called from cmake. |
DYLD, OK. Build logs - follow details in the "Some checks were not successful" |
I'm not too familiar with homebrew (I use conan nowadays) however in the build logs I don't see anything go particularly wrong, apart from the timeout at the end. Maybe the homebrew install was stuck or too slow? |
@wdobbe I don't have the full overview here, but it seems that @madebr has already integrated most or all of your changes into his PR #171 |
I have used @wdobbe 's commit and kept his name, so he should be mentioned as co-creator. |
Should we close this PR then? |
a8e7a8a
to
d7f50b2
Compare
Sorry for not following up on this. We have several build PRs going and I need to narrow this down. If you are still interested, please comment on PR #258. The plan is to make a release soon, then introduce changes to the build. |
Resolves #168 .
Install a cmake module that provides cmake function
flatcc_generate_sources
.This function simplifies generation of C code from flatbuffer definition file(s).