-
Notifications
You must be signed in to change notification settings - Fork 410
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
Modern CMake adjustements #91
base: master
Are you sure you want to change the base?
Conversation
The current cmake implementation provides target modern cmake but those targets does not hold their include. This aims to correct it.
Same problem as ./CMakeLists.txt
Wrong install path
Added minimum version 3.2 to support new technologies
@@ -1,7 +1,7 @@ | |||
# | |||
# Test CMake version | |||
# | |||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) | |||
CMAKE_MINIMUM_REQUIRED(VERSION 3.2) |
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'm hesitant to require newer cmake version higher then 2.8 because: "2.8.12 is the version shipped starting from Ubuntu Trusty (April 2014) or Debian Jessie (April 2015). Other Linux distributions released at approximately the same time have typically newer versions. So that's where we would cut off. Ubuntu Precise (cmake 2.8.7) goes EOL in April 2017, Debian Wheezy (cmake 2.8.9) in May 2018, so probably its a good idea to stay compatible with 2.8.9 until at least next year."
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 3.5 was backported to Trusty a few months ago: https://packages.ubuntu.com/trusty/cmake3.
Updated to new Eigen exportefd target
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) | ||
TARGET_LINK_LIBRARIES(orocos-kdl ${Boost_LIBRARIES}) | ||
TARGET_INCLUDE_DIRECTORIES(orocos-kdl PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> ) | ||
TARGET_LINK_LIBRARIES(orocos-kdl PUBLIC ${Boost_LIBRARIES} Eigen3::Eigen) |
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 target was introduced in Eigen 3.3.1, you'll need to add some fallback behavior (if(TARGET Eigen3::Eigen)...else()...endif()
).
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 the (very) long absence, is this still relevant?
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.
Since KDL doesn't enforce a minimum version, anyone trying to use Eigen<3.3.1 can experience errors, so I think this is still an issue. However, you could just tweak FindEigen3.cmake so that modern CMake targets are made available for use both by KDL itself and projects consuming KDL (make sure this gives precedence to the local file or just add OR NOT TARGET Eigen3::Eigen
in the if
clause). See upstream find module, especially the last few lines:
if(EIGEN3_FOUND AND NOT TARGET Eigen3::Eigen)
add_library(Eigen3::Eigen INTERFACE IMPORTED)
set_target_properties(Eigen3::Eigen PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${EIGEN3_INCLUDE_DIR}")
endif()
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.
currently if Eigen is not found there is no error? Adding eigen with the TARGET_LINK_LIBRARIES
will print an error when generating.
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 Eigen is a required dependency, there should be a check somewhere else (and before those lines) to issue an error. I wouldn't delegate such responsibility to the target_link_libraries
call, typically you would use find_package(<pkg> REQUIRED)
or a simple if(NOT <pkg>_FOUND)
-then-message(FATAL_ERROR ...)
condition instead.
Hey, I'm running into a similar issue, where the find module generated from
In any case, the oldest Ubuntu LTS at this point is Xenial, and it has CMake 3.5.1. :) |
Hmm, that's strange. Normally # Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
set(_IMPORT_PREFIX "")
endif() The reason why it is not hard-coded at configure-time (of Are you using colcon or catkin with a symlinked install-space or something like that? I could imagine that my version with |
Well, how about that. 😂 I am indeed using colcon, though not with the symlink-install space. And yes, I think the problem is indeed with the
And of course in
But when I build that package on its own separately (attempting to produce a MWE), I end up with the reasonable, expected path instead:
So yeah, it's not at all clear to me how it ends up referencing the |
@@ -80,14 +80,15 @@ ENDIF() | |||
#####end RPATH | |||
|
|||
# Needed so that the generated config.h can be used | |||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) | |||
TARGET_LINK_LIBRARIES(orocos-kdl ${Boost_LIBRARIES}) | |||
TARGET_INCLUDE_DIRECTORIES(orocos-kdl PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> ) |
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 additionally needs a $<INSTALL_INTERFACE:include>
to export an include directory in the install case.
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.
Isn't that what
install(TARGETS ...
INCLUDES DESTINATION include
)
is supposed to do here?
From the documentation:
INCLUDES DESTINATION
This option specifies a list of directories which will be added to theINTERFACE_INCLUDE_DIRECTORIES
target property of the<targets>
when exported by theinstall(EXPORT)
command. If a relative path is specified, it is treated as relative to the$<INSTALL_PREFIX>
.
So probably both are valid approaches to achieve the same at the end. But having both might be redundant.
I would agree to that.
What exact version of Also feel free to mention me again when you can reproduce it. |
Okay, so I think the issue here has to do with how If I populate and build a workspace, but switch that dependency over:
Then I end up with the correct result:
So I'm not sure how to really make this better— |
About that, we could actually use the cmake export structure to create orocos_kdl-config.cmake instead of the custom in file. https://cmake.org/cmake/help/git-stage/guide/importing-exporting/index.html#id10 let me know if that would be of interest. |
I think this is already implemented, see orocos_kinematics_dynamics/orocos_kdl/CMakeLists.txt Lines 114 to 128 in 7372114
As far as I can tell, CMake can take care for you of creating the include("${CMAKE_CURRENT_LIST_DIR}/OrocosKDLTargets.cmake") Since KDL must take care of its dependencies (i.e. Eigen+Boost, here one could use Well, actually the version .in could be replaced by some sort of CMake automation, see CMakePackageConfigHelpers. |
…ration Eigen3 is offering CMake target from 3.3.1, we add in the local find module a target mechanism and fall back to it when FindEigen3.cmake did not create a target. Use cmake CMakePackageConfigHelpers to generate the .config file.
I added the CMakePackageConfigHelpers as suggested to create the config and version files. I also forced the usage of the local FindEigen3.cmake when the default does not create a target. The local FindEigen3.cmake now also creates a target, as proposed. I also added a check if the target is defined in order to not fail at generate or build time. This was not there before as finding eigen was flagged as QUIET. I hope this does not break anything. |
Hi all,
First of all, thx for your amazing work! I just commit this minor change to your CMake. It's really good but I ran into two issues:
The cmake currently exports the target which means that when find_package(ing) for orocos, cmake looks directly in the build directory. Although it's really convinient to use, the interface is different than the installed interface eg. : in the build the file chain.hpp is in src/chain.hpp and in the install dir it's kdl/chain.hpp so that's really not easy.
Second issue, in the installed exported targets, the include where saved in a config file while they could just be added to the targets themselves, which removes the issue of using include_directories on the user-side. I just added a line INCLUDE DESTINATION include/kdl in the src/CMakeLists.txt
If you are concerned about the dependency with Eigen, know that it is possible to use the modern cmake on Eigen too and use it as target_link_library(orocos-kdl PUBLIC Eigen) which will create a cleaner dependency in the config file.
All the best,
XB32Z