Skip to content
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

cmake: set CAPNP_INCLUDE_DIR #1071

Merged
merged 1 commit into from
Oct 13, 2020
Merged

Conversation

p4l1ly
Copy link
Contributor

@p4l1ly p4l1ly commented Sep 28, 2020

when installing capnp to a non-standard location (out of /usr or /usr/local), the capnp compile must be issued with the -I option even for the standard /capnp/c++.capnp import. Some projects that use capnp compile directly, not via cmake (e.g. capnproto-java) cannot be built in this configuration.

@p4l1ly
Copy link
Contributor Author

p4l1ly commented Sep 28, 2020

The windows CI checks fail for some reason that seems unrelated (test executables don't get built) and I have too little experience to be able to debug it

@@ -168,6 +168,7 @@ if(NOT CAPNP_LITE)
set_target_properties(capnp_tool PROPERTIES CAPNP_INCLUDE_DIRECTORY
$<JOIN:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>,$<INSTALL_INTERFACE:${CMAKE_INSTALL_BINDIR}/..>>
)
set_target_properties(capnp_tool PROPERTIES COMPILE_FLAGS -DCAPNP_INCLUDE_DIR='"${CMAKE_INSTALL_FULL_INCLUDEDIR}"')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Seems like this should be indented to match the surrounding lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh ugly, sorry, am I blind or did vim betray me few minutes before push?

@kentonv
Copy link
Member

kentonv commented Sep 29, 2020

The Cygwin test failure is expected (it has... bitrotted), but the other failures seem to be caused by this change.

Copy link
Member

@harrishancock harrishancock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

@kentonv
Copy link
Member

kentonv commented Sep 30, 2020

Can you please make this change without changing the format of the macro? Otherwise this breaks people who are already customizing the macro in their own builds.

@p4l1ly
Copy link
Contributor Author

p4l1ly commented Oct 3, 2020

The problem is that I cannot figure out how to pass the double quotes to COMPILE_FLAGS in a Windows/Linux compatible way (I think this is a CMake's bug but we have to cope with it somehow).

Anyway, I think that requiring double quotes around the argument is quite weird and as it moreover violates platform independency, it might be a good idea to remove it. The version is still unstable...

@p4l1ly
Copy link
Contributor Author

p4l1ly commented Oct 3, 2020

ok, the escaping "\\\"${CMAKE_INSTALL_FULL_INCLUDEDIR}\\\"", however ugly, seems to work.

@p4l1ly p4l1ly force-pushed the includedir branch 2 times, most recently from c585c3b to 46abd32 Compare October 3, 2020 12:29
@@ -168,6 +168,7 @@ if(NOT CAPNP_LITE)
set_target_properties(capnp_tool PROPERTIES CAPNP_INCLUDE_DIRECTORY
$<JOIN:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>,$<INSTALL_INTERFACE:${CMAKE_INSTALL_BINDIR}/..>>
)
set_target_properties(capnp_tool PROPERTIES COMPILE_FLAGS -DCAPNP_INCLUDE_DIR="\\\"${CMAKE_INSTALL_FULL_INCLUDEDIR}\\\"")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to use COMPILE_FLAGS over COMPILE_DEFINITIONS?
The latter seems more appropriate, and I think the escaping syntax will be lighter:

set_target_properties(capnp_tool PROPERTIES
  COMPILE_DEFINITIONS CAPNP_INCLUDE_DIR=\"${CMAKE_INSTALL_FULL_INCLUDEDIR}\")

I don't know if the capnproto installation is relocatable today, but using CMAKE_INSTALL_FULL_XXX in the binary may harm relocatability of the package.
Unfortunately, I think the solution to this is more complex.
To do so, the binary should be able to locate it's own installation prefix at runtime, which is platform specific.

Copy link
Contributor Author

@p4l1ly p4l1ly Oct 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the hint, I didn't know about COMPILE_DEFINITIONS.
As for the relocatability, the installation was not relocatable before in the context of default include paths. Actually, the default include paths were hardcoded to /usr/include and /usr/local/include. The proposed change is not the ideal solution but is a bit more dynamic than before. The installation cannot be relocated but it can be at least compiled and installed locally with the correct default include paths. It was not possible before if using cmake.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this makes the cmake build match what the autotools build has done for a long time, which seems like an improvement.

Making the binary relocatable was discussed a bit in #1062, but it's not completely obvious what the right approach is.

@kentonv
Copy link
Member

kentonv commented Oct 10, 2020

@harrishancock Can you verify this still looks good to you and, if so, feel free to merge?

@harrishancock harrishancock merged commit a6848ba into capnproto:master Oct 13, 2020
@p4l1ly p4l1ly deleted the includedir branch October 14, 2020 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants