-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Major revamp of the ament_cmake documentation. #3812
Conversation
Rearrange the document to more closely follow the order a typical CMakeLists.txt is arranged in. While doing that, update the documentation to match our current best practices, and add in additional advice for building/installing executables as opposed to libraries. Signed-off-by: Chris Lalancette <[email protected]>
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.
Overall, the changes look good. A few touch-ups here and there. Great improvement.
|
||
When building a reusable library, some information needs to be exported for downstream packages to easily use it. | ||
- Only ``.c/.cpp`` files are explicitly referenced in the call to ``add_library`` |
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.
Perhaps consider target_sources
? I actually really like this by adding a CMakeLists in src
and include
folders to make the top level one more digestable. However, neither splitting the CMake code nor using target_sources
is common the ROS core.
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.
We don't use this in the core currently, so I don't think I'll add this here.
|
||
There are two additional functions which can be used but are superfluous for target based installs: | ||
The first and recommended way is to use the ament macro ``ament_target_dependencies``. |
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.
Could be useful to explain why we are still recommending ament_target_dependencies
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 a hard one to explain, to be honest. The fact is that you can do almost everything you want with target_link_libraries
nowadays, and I've been (slowly) converting the core over to using that over ament_target_dependencies
. The one big thing that doesn't work is message packages; you can't depend on sensor_msgs::sensor_msgs
, you have to instead depend on ${sensor_msgs_TARGETS}
. That's the main reason to still recommend ament_target_dependencies
, but I'm not convinced that explanation is necessary/useful here.
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 special case for using messages is already covered in other tutorials. I use target_link_libraries
for basically every library except message packages. It could be useful to instead acknowledge the fact that both may be used together.
|
||
The following best practice is proposed: | ||
if(NOT CMAKE_C_STANDARD) |
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.
Might want to add the DEFINED
keyword because it could be defined, but empty, in which case you end up not setting the standard.
https://github.com/cpp-best-practices/cmake_template/blob/d19d8921771ba582824948f0cc57f849a5c6efd8/CMakeLists.txt#L8
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 ended up not doing this, because this isn't what we do in the core.
Actually, this is one place where what ros2 pkg create
does and what the core does differ. In the core, we use:
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
But in ros2 pkg create
, we generate:
target_compile_features(mylib PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
I'm not sure which is better, and we don't use DEFINED
in either place. I think I'm going to leave this one as-is for now, though we should probably rectify this situation one way or the other.
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'll create another ticket in ros2/ros2.
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.
Converted to ros2/ros2#1467
Signed-off-by: Chris Lalancette <[email protected]>
|
||
In principle, using generator expressions here is not necessary if both folders are called ``include`` and top-level with respect to ``${CMAKE_CURRENT_SOURCE_DIR}`` and ``${CMAKE_INSTALL_DIR}``, but it is very common. | ||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
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.
CMAKE_COMPILER_IS_GNUCXX
is deprecated.
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | |
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
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.
In the core, we use CMAKE_COMPILER_IS_GNUCXX
everywhere. This could probably also be changed as part of ros2/ros2#1467, but I think here we should document what we currently use.
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 you have any automatic refactoring and/or PR tools? There's 167 instances of it in ros2 rolling repos, and it looks like a simple sed replacement would work.
Signed-off-by: Chris Lalancette <[email protected]>
I'm going to go ahead and merge and backport this one. Thanks for all of your feedback. |
* Major revamp of the ament_cmake documentation. Rearrange the document to more closely follow the order a typical CMakeLists.txt is arranged in. While doing that, update the documentation to match our current best practices, and add in additional advice for building/installing executables as opposed to libraries. Signed-off-by: Chris Lalancette <[email protected]> Co-authored-by: Ryan Friedman <[email protected]> (cherry picked from commit 38d8e74)
* Major revamp of the ament_cmake documentation. Rearrange the document to more closely follow the order a typical CMakeLists.txt is arranged in. While doing that, update the documentation to match our current best practices, and add in additional advice for building/installing executables as opposed to libraries. Signed-off-by: Chris Lalancette <[email protected]> Co-authored-by: Ryan Friedman <[email protected]> (cherry picked from commit 38d8e74)
* Major revamp of the ament_cmake documentation. Rearrange the document to more closely follow the order a typical CMakeLists.txt is arranged in. While doing that, update the documentation to match our current best practices, and add in additional advice for building/installing executables as opposed to libraries. Signed-off-by: Chris Lalancette <[email protected]> Co-authored-by: Ryan Friedman <[email protected]> (cherry picked from commit 38d8e74) Co-authored-by: Chris Lalancette <[email protected]>
* Major revamp of the ament_cmake documentation. Rearrange the document to more closely follow the order a typical CMakeLists.txt is arranged in. While doing that, update the documentation to match our current best practices, and add in additional advice for building/installing executables as opposed to libraries. Signed-off-by: Chris Lalancette <[email protected]> Co-authored-by: Ryan Friedman <[email protected]> (cherry picked from commit 38d8e74) Co-authored-by: Chris Lalancette <[email protected]>
Rearrange the document to more closely follow the order a typical CMakeLists.txt is arranged in. While doing that, update the documentation to match our current best practices, and add in additional advice for building/installing executables as opposed to libraries.
@Ryanf55 FYI. I'm very interested to hear your feedback about this revamp.