diff --git a/orocos_kdl/CMakeLists.txt b/orocos_kdl/CMakeLists.txt index a21460ddd..f855965e4 100644 --- a/orocos_kdl/CMakeLists.txt +++ b/orocos_kdl/CMakeLists.txt @@ -1,10 +1,7 @@ # # Test CMake version # -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -IF(POLICY CMP0048) - CMAKE_POLICY(SET CMP0048 NEW) -ENDIF() +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) #MARK_AS_ADVANCED( FORCE CMAKE_BACKWARDS_COMPATIBILITY ) @@ -54,10 +51,14 @@ ENDIF ( NOT CMAKE_BUILD_TYPE ) SET( KDL_CFLAGS "") find_package(Eigen3 QUIET) -if(NOT EIGEN3_FOUND) +if(NOT EIGEN3_FOUND OR NOT TARGET Eigen3::Eigen) include(${PROJ_SOURCE_DIR}/cmake/FindEigen3.cmake) endif() -include_directories(${EIGEN3_INCLUDE_DIR}) + +if(NOT TARGET Eigen3::Eigen) + message(FATAL_ERROR "Eigen3 NOT FOUND") +endif() + SET(KDL_CFLAGS "${KDL_CFLAGS} -I${EIGEN3_INCLUDE_DIR}") # Check the platform STL containers capabilities @@ -104,28 +105,33 @@ ENDIF(ENABLE_TESTS ) OPTION(ENABLE_EXAMPLES OFF "Enable building of examples") +# Configuration variables +set(orocos_kdl_TARGETS_EXPORT_NAME "OrocosKDLTargets") +set(orocos_kdl_VERSION_CONFIG_FILENAME "${PROJECT_NAME}-config-version.cmake") +set(orocos_kdl_CONFIG_FILENAME "${PROJECT_NAME}-config.cmake") + ADD_SUBDIRECTORY( doc ) ADD_SUBDIRECTORY( src ) ADD_SUBDIRECTORY( tests ) ADD_SUBDIRECTORY( models ) ADD_SUBDIRECTORY( examples ) - -export(TARGETS orocos-kdl - FILE "${PROJECT_BINARY_DIR}/OrocosKDLTargets.cmake") - -export(PACKAGE orocos_kdl) - # Generate CMake package configuration -CONFIGURE_FILE(orocos_kdl-config.cmake.in - ${PROJECT_BINARY_DIR}/orocos_kdl-config.cmake @ONLY) -CONFIGURE_FILE(orocos_kdl-config-version.cmake.in - ${PROJECT_BINARY_DIR}/orocos_kdl-config-version.cmake @ONLY) - -INSTALL(FILES cmake/FindEigen3.cmake DESTINATION share/orocos_kdl/cmake) -INSTALL(FILES ${PROJECT_BINARY_DIR}/orocos_kdl-config.cmake DESTINATION share/orocos_kdl/cmake) -INSTALL(FILES ${PROJECT_BINARY_DIR}/orocos_kdl-config-version.cmake DESTINATION share/orocos_kdl/cmake) -INSTALL(EXPORT OrocosKDLTargets DESTINATION share/orocos_kdl/cmake) +include(CMakePackageConfigHelpers) + +set(orocos_kdl_CMAKE_INSTALL_SUFFIX share/orocos_kdl/cmake) + +configure_package_config_file(orocos_kdl-config.cmake.in ${orocos_kdl_CONFIG_FILENAME} + INSTALL_DESTINATION ${orocos_kdl_CMAKE_INSTALL_SUFFIX}) +write_basic_package_version_file(${orocos_kdl_VERSION_CONFIG_FILENAME} + VERSION ${KDL_VERSION} + COMPATIBILITY AnyNewerVersion) + +INSTALL(FILES cmake/FindEigen3.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${orocos_kdl_CONFIG_FILENAME} + ${CMAKE_CURRENT_BINARY_DIR}/${orocos_kdl_VERSION_CONFIG_FILENAME} + DESTINATION ${orocos_kdl_CMAKE_INSTALL_SUFFIX}) +INSTALL(EXPORT OrocosKDLTargets DESTINATION ${orocos_kdl_CMAKE_INSTALL_SUFFIX}) # Generate pkg-config package configuration CONFIGURE_FILE(orocos_kdl.pc.in ${CMAKE_CURRENT_BINARY_DIR}/orocos-kdl.pc @ONLY) diff --git a/orocos_kdl/cmake/FindEigen3.cmake b/orocos_kdl/cmake/FindEigen3.cmake index 17307fc07..e36e7d843 100644 --- a/orocos_kdl/cmake/FindEigen3.cmake +++ b/orocos_kdl/cmake/FindEigen3.cmake @@ -87,3 +87,10 @@ else (EIGEN3_INCLUDE_DIR) mark_as_advanced(EIGEN3_INCLUDE_DIR) endif(EIGEN3_INCLUDE_DIR) + +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() + diff --git a/orocos_kdl/orocos_kdl-config-version.cmake.in b/orocos_kdl/orocos_kdl-config-version.cmake.in deleted file mode 100644 index 796eddc19..000000000 --- a/orocos_kdl/orocos_kdl-config-version.cmake.in +++ /dev/null @@ -1,11 +0,0 @@ -set(PACKAGE_VERSION "@KDL_VERSION@") - -# Check whether the requested PACKAGE_FIND_VERSION is compatible -if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") - set(PACKAGE_VERSION_COMPATIBLE FALSE) -else() - set(PACKAGE_VERSION_COMPATIBLE TRUE) - if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") - set(PACKAGE_VERSION_EXACT TRUE) - endif() -endif() \ No newline at end of file diff --git a/orocos_kdl/orocos_kdl-config.cmake.in b/orocos_kdl/orocos_kdl-config.cmake.in index 4cc8bc598..31b71c54d 100644 --- a/orocos_kdl/orocos_kdl-config.cmake.in +++ b/orocos_kdl/orocos_kdl-config.cmake.in @@ -4,8 +4,7 @@ # orocos_kdl_LIBRARIES - libraries to link against for Orocos KDL # orocos_kdl_PKGCONFIG_DIR - directory containing the .pc pkgconfig files -# Compute paths -get_filename_component(orocos_kdl_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE) + @PACKAGE_INIT@ # Find dependencies find_package(Eigen3 QUIET) @@ -19,15 +18,21 @@ if(KDL_USE_NEW_TREE_INTERFACE) endif() if(NOT TARGET orocos-kdl) - include("${CMAKE_CURRENT_LIST_DIR}/OrocosKDLTargets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/@orocos_kdl_TARGETS_EXPORT_NAME@.cmake") endif() +get_target_property(orocos_kdl_INCLUDE_DIR orocos-kdl INTERFACE_INCLUDE_DIRECTORIES) + +set_and_check(orocos_kdl_INCLUDE_DIR "${orocos_kdl_INCLUDE_DIR}") + set(orocos_kdl_INCLUDE_DIRS - ${orocos_kdl_PREFIX}/include + ${orocos_kdl_INCLUDE_DIR} ${Boost_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIR} ) set(orocos_kdl_LIBRARIES orocos-kdl) # where the .pc pkgconfig files are installed -set(orocos_kdl_PKGCONFIG_DIR "${orocos_kdl_PREFIX}/lib/pkgconfig") +set(orocos_kdl_PKGCONFIG_DIR "${PACKAGE_PREFIX_DIR}/lib/pkgconfig") + +check_required_components("@PROJECT_NAME@") diff --git a/orocos_kdl/src/CMakeLists.txt b/orocos_kdl/src/CMakeLists.txt index 40c8717ba..3e3cb3fcc 100644 --- a/orocos_kdl/src/CMakeLists.txt +++ b/orocos_kdl/src/CMakeLists.txt @@ -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 $ ) +TARGET_LINK_LIBRARIES(orocos-kdl PUBLIC ${Boost_LIBRARIES} Eigen3::Eigen) INSTALL(TARGETS orocos-kdl - EXPORT OrocosKDLTargets + EXPORT ${orocos_kdl_TARGETS_EXPORT_NAME} ARCHIVE DESTINATION lib${LIB_SUFFIX} LIBRARY DESTINATION lib${LIB_SUFFIX} PUBLIC_HEADER DESTINATION include/kdl + INCLUDES DESTINATION include ) INSTALL(FILES ${UTIL_HPPS} DESTINATION include/kdl/utilities)