Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Plain cmake #63
Plain cmake #63
Changes from 8 commits
3394f0a
0a3368a
4ad7d8b
d70c144
b65bc9d
4ff987f
1576b74
e79f08b
53e9e28
de25ff0
43a88c7
e4c3ce2
51d95a0
e3ab8ff
3aba401
6e3eae4
7325505
a78ac54
3ad2428
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Should we use
GenerateExportHeader
instead of a custom visibility header? See also Create dlls on Windows without declspec() using new CMake export all feature.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.
Great idea! I will add it.
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 may be worth to mention in the comment "appears to be default installed" refers to Chocolatey-based ROS/ROS2 installs.
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.
There is any specific reason why you won't leave the user the possibility of selecting the type of the library (
SHARED
orSTATIC
) using the standardBUILD_SHARED_LIBS
variable? If you want to default to useSHARED
, you can simply declare theBUILD_SHARED_LIBS
variable as an option whose default value isON
, as suggested in CMake docs itself: https://cmake.org/cmake/help/v3.6/variable/BUILD_SHARED_LIBS.html . This would simplify packaging this lib for vcpkg (https://docs.microsoft.com/en-us/cpp/build/vcpkg?view=vs-2019).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.
No reason, it was like that in the generated cmake package template (from the ROS2 command line interface) that I used as a base. I.e. the template found here.
I like your arguments for making it an option instead.
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.
Thanks, I know where to open an issue to ask to make it an option then. :D
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
FindBoost.cmake
from CMake3.5
actually seems to exportBoost::
namespaced exported targets.We should be able to just
target_link_libraries(.. Boost::system
etc) instead of usingBoost_LIBRARIES
andBoost_INCLUDE_DIRS
.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.
If Boost and Protobuf headers are used in the public headers of the libraries, I suggest to mark them as
PUBLIC
.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 for my lack of knowledge, but could you explain how to mark them as
PUBLIC
? Doesn't lines 68-69 already do 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.
Lines 68-69 tells the preprocessor of the downstream compilation unit that uses
abb_libegm
the include directories of Boost and Protobuf need to be appended to the search path of includes (tipically on GCC this is done via the-I
compilation option).Marking as PUBLIC (by doing
target_link_libraries(${PROJECT_NAME} PUBLIC ${Boost_LIBRARIES} ${Protobuf_LIBRARIES}
) the linked libraries, tells the linker of the downstream library that usesabb_libegm
, to also link the Protobuf and Boost libraries whenabb_libegm
is linked. This is typically done (in *nix) via the-l
linker option.With CMake >= 3.9, you can just declare as
PUBLIC
intarget_link_libraries
the linking of the Boost's and Protobuf's imported targets, and that includes both passing the right library to the linker, and the right include dirs to the preprocessor, thanks to the use of so-called "Usage Requirements", see https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#build-specification-and-usage-requirements . If you want a more in-depth discussion, the best reference for this that I ever found is the book https://crascit.com/professional-cmake/ , but it is not available free of charge.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.
Should these go to
CMAKE_INSTALL_DATAROOTDIR
instead?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 am not sure if there is any policy/best practice for this, but for example the ignition-msgs package installs them in the same include directories of C++ include headers, see https://packages.debian.org/sid/amd64/libignition-msgs-dev/filelist . Perhaps @j-rivero knows about some policy regarding 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.
This will point to the wrong include dirs if during configuration the user change the GNUInstallDirs's variable
CMAKE_INSTALL_INCLUDEDIR
. Furthermore, the include directories are already included in the imported target, so there are more maintainable ways of exporting this info ensuring that the package remains relocatable.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.
Do we really need this? Or is this a cargo-cult copy-pasta?
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's not needed, I guess, it originates from the ROS2 cmake template.
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.
Needed?
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.
Again, from the ROS2 cmake template. I will remove it.
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.
If you are already exporting properly configured CMAke exported targets, there is little use in having an explicit variable
${abb_libegm_INCLUDE_DIRS}
, as any use of this variable in downstream package will make them non-relocatable. However, if you want to include it, you can extract it directly from theabb_libegm
imported target:get_target_property(abb_libegm_INCLUDE_DIRS abb_libegm INTERFACE_INCLUDE_DIRECTORIES)
clearly this line should go after the inclusion of the
export_abb_libegm.cmake
file.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 classical trick is to use
${CMAKE_CURRENT_LIST_DIR}
to import file that are in the same directory,to avoid assuming that a variable calledabb_libegm_DIR
is present.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.
See https://cmake.org/cmake/help/v3.3/manual/cmake-packages.7.html#creating-a-package-configuration-file .
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 see, thanks for the pointer!
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 guess also this comes from the ros2 template, but unfortunately this template is based on the wrong section of the Wiki page https://gcc.gnu.org/wiki/Visibility . This is based on the section "How to use the new C++ visibility support" that is meant to be a quick overview of the functionality, while the template to be used is the one under "Step-by-step guide" . The difference are not enormous, but unfortunatly this version will probably create problems when compiling as static library in Windows, see ament/ament_cmake#201 (comment) . Again, I do not care too much about building as a static library per se, but supporting that case is useful to easily submit a port of a C++ library to https://github.com/microsoft/vcpkg , that is a great way to manage C++ libraries on Windows.
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, it comes from the ROS2 template and I will make an update to address this.
Also, thanks for all the insights! They are much appreciated!
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 imagined, I will try in the future to report this problems also there!
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
maintainer
already has your email address. We typicaly only list it there. If you ever stop maintaining, it's convenient to just have to remove themaintainer
tag, leave theauthor
one and everything is immediately up-to-date (as opposed to having to edit/remove the email address in two places).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.
If I interpret the rosdep entries for protobuf correctly, I believe
protobuf-dev
would only be abuild_depend
andbuild_export_depend
, andprotobuf
would still be theexec_depend
.The former resolves to the development package (providing the headers and compiler), while the latter contains just the library.
Headers are only needed for building things. The library is always needed.
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 took a peek at how Google Cartographer's package.xml looked like for a newer package format and assumed it was the "appropriate" way.
But I think your way is more reasonable.
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.
Well .. it is Google, but I'm not sure that is correct.
As I wrote: if I interpret things correctly.