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
Fix capnp/capnpc --version when built using CMake #1306
Conversation
Note that the official Cap'n Proto build is the autotools build. Any distro packages should be built with autotools, not with cmake. The cmake files were contributed by external volunteers and I personally don't know cmake, hence the cmake files are more likely to have bugs -- like this one. Arch should switch to using the autotools build. With that said, we should still fix this. @harrishancock does this look OK? |
I do happen to know CMake quite a bit although that knowledge has waxed and waned over the years . I think this PR is fine as is the suggestion to switch to |
@nyanpasu64 did you want to change the whole thing to use target_compile_definitions or do you want me to merge it in as-is? |
I'm not sure. It was added in 2020 at #1071, and it seems @p4l1ly wanted "to pass the double quotes to In any case, the I could try the following, but I don't know if target_compile_definitions(capnp_tool PRIVATE
CAPNP_INCLUDE_DIR=\"${CMAKE_INSTALL_FULL_INCLUDEDIR}\"
VERSION="${VERSION}"
) Perhaps I'll remove the backslashes while I'm at it. Both |
28e9d1a
to
057bf26
Compare
Your latest commit, with
And it seems it is intended according to CMake documentation, although it may be using legacy syntax?
|
If I remember well, the only reason why I did not bring |
Replacing my current "legacy" code with the recommended alternative looks a lot uglier, but works as well (on Windows at least). I'm not sure what the community (as opposed to the official docs) prefers. target_compile_definitions(capnp_tool PRIVATE
"CAPNP_INCLUDE_DIR=\"${CMAKE_INSTALL_FULL_INCLUDEDIR}\""
"VERSION=\"${VERSION}\""
) I'm not pushing this command at the moment because I feel it's less readable, but I'm open to receiving feedback either way. |
🤷 not too ugly... As the previous, slightly more beautiful option is officially legacy, I would keep the latter one. |
Although I find the unquoted argument prettier, I think it may be better to use the quoted argument syntax:
|
057bf26
to
35b8dec
Compare
I found a bug report with a discussion saying that |
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.
Makes sense to me, thanks for figuring this out!
Currently, running
capnp[c] --version
on Arch Linux (both the current 0.8.0 and my self-built 0.9.0 package) prints "Cap'n Proto version (unknown)" becauseVERSION
is a CMake variable but not a C++ definition. This addsVERSION
as a C++ definition, fixing the resulting binaries. This also switchesCAPNP_INCLUDE_DIR
to atarget_compile_definitions
call for simplicity.Old
The existing CMakeLists.txt is strange though; the following overwrites the list of definitions:
I tried adding variations of
;VERSION="${VERSION}"
to set two definitions, but it was rejected since CMake thought it was multiple arguments to set_target_properties. I decided to append onto your existing string with a separatetarget_compile_definitions
command, since it was easier to get working.Do you want to replace
set_target_properties(... COMPILE_DEFINITIONS)
withtarget_compile_definitions
entirely?