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

CMakeLists.txt: fixing relocatable package issue #19

Merged
merged 2 commits into from Oct 26, 2023
Merged

CMakeLists.txt: fixing relocatable package issue #19

merged 2 commits into from Oct 26, 2023

Conversation

ghost
Copy link

@ghost ghost commented Mar 8, 2023

With the current CMakeLists, the installed package will have an absolute path, which breaks if the package gets relocated later on.

This patch tries to set up a proper header only ros2 package.

CMakeLists.txt Outdated

install(
DIRECTORY include/
DESTINATION include
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're modifying this, mind making it install the headers to a unique include directory? It's allows overriding in a merged colcon or ament workspace: https://colcon.readthedocs.io/en/released/user/overriding-packages.html#install-headers-to-a-unique-include-directory

Copy link
Author

Choose a reason for hiding this comment

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

Actually, I really do not get the point of why in the world installing into include/foo/foo/foo.hpp would be a thing. I have read the paragraph, but it only advises to do so, not why. I have seen (core) packages doing it as well as others not doing it. Also, this is the behavior it had before, did it not?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I really do not get the point of why in the world installing into include/foo/foo/foo.hpp would be a thing.

It's so that when one package overrides another, the overriding package's headers will be included regardless of the order that include directories are given in CMake. There's more info here: https://colcon.readthedocs.io/en/released/user/overriding-packages.html#include-directory-search-order-problem . ROS 1 solved it by ordering the include directories in find_package(catking REQUIRED COMPONENTS pkg1 pkg2), but that was no longer an option with modern CMake targets.

I have seen (core) packages doing it as well as others not doing it

Which ones? The core packages should all be using it by now.

Copy link
Author

Choose a reason for hiding this comment

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

CMakeLists.txt Outdated
)

ament_target_dependencies(${PROJECT_NAME} Eigen3)
ament_export_targets(${PROJECT_NAME}Targets HAS_LIBRARY_TARGET)
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC HAS_LIBRARY_TARGET means "has a shared library target", and causes an environment hook for LD_LIBRARY_PATH to be set. It shouldn't be set here because only an interface target is being used.

Copy link
Author

Choose a reason for hiding this comment

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

LD_LIBRARY_PATH has nothing to do with it. The "library" is declared as INTERFACE and therefore is header only

Copy link
Contributor

Choose a reason for hiding this comment

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

CMakeLists.txt Outdated
add_library(${PROJECT_NAME} INTERFACE
include/${PROJECT_NAME}/eigen_stl_containers.h
include/${PROJECT_NAME}/eigen_stl_map_container.h
include/${PROJECT_NAME}/eigen_stl_vector_container.h
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think these files will need to be specified as long as we set the install interface include directories correctly through target_include_directories()

Copy link
Author

Choose a reason for hiding this comment

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

This is a difficult call for me, I know that it cmake does not yield a correct project for Microsoft Visual Studio if you do not mention these files here. But I use no Windows, so idk. It should not hurt at least.

CMakeLists.txt Outdated
include/${PROJECT_NAME}/eigen_stl_vector_container.h
)

ament_target_dependencies(${PROJECT_NAME} Eigen3)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend using target_link_libraries() in new code. ament/ament_cmake#292

Copy link
Author

Choose a reason for hiding this comment

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

I will fix that. Ty

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I missed this one. If you could change this to:

Suggested change
ament_target_dependencies(${PROJECT_NAME} Eigen3)
target_link_libraries(${PROJECT_NAME} INTERFACE Eigen3::Eigen3)

I think that should do it.

@ghost
Copy link
Author

ghost commented Oct 18, 2023

Groomed through my old PR, updated this. Friendly bump

@clalancette
Copy link
Contributor

Groomed through my old PR, updated this. Friendly bump

As far as I can tell, we are still waiting for two changes to this PR:

  • Move the includes to a unique include directory
  • Removal of "HAS_LIBRARY_TARGET"

Once those two are fixed, I think we can go ahead with another review of this.

@ghost
Copy link
Author

ghost commented Oct 23, 2023

Hi @clalancette

I did the requested changes.

Thanks and regards,
Matthias

CMakeLists.txt Outdated
include/${PROJECT_NAME}/eigen_stl_vector_container.h
)

ament_target_dependencies(${PROJECT_NAME} Eigen3)
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I missed this one. If you could change this to:

Suggested change
ament_target_dependencies(${PROJECT_NAME} Eigen3)
target_link_libraries(${PROJECT_NAME} INTERFACE Eigen3::Eigen3)

I think that should do it.

@ghost
Copy link
Author

ghost commented Oct 23, 2023

@clalancette yes, sure. done.

Matthias Schoepfer and others added 2 commits October 26, 2023 10:31
With the current CMakeLists, the installed package will have an absolute
path, which breaks if the package gets relocated later on.

This patch tries to set up a proper header only ros2 package.

Signed-off-by: Matthias Schoepfer <[email protected]>
Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

With my latest changes, this looks like it should now. Thanks @RethinkMatze ! I'll go ahead and merge this.

@clalancette clalancette merged commit 30c7cc9 into ros:ros2 Oct 26, 2023
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.

2 participants