Verified Commit d1a7f8da authored by Justin Carpentier's avatar Justin Carpentier
Browse files

cmake: use standard CMake procedure to link against external dependencies

parent 62b1b502
......@@ -90,34 +90,36 @@ SET(PINOCCHIO_MODEL_DIR "${PROJECT_SOURCE_DIR}/models")
# ----------------------------------------------------
# --- DEPENDENCIES -----------------------------------
# ----------------------------------------------------
ADD_REQUIRED_DEPENDENCY("eigen3 >= 3.0.5")
ADD_PROJECT_DEPENDENCY(eigen3 3.0.5 REQUIRED PKG_CONFIG_REQUIRES "eigen3 >= 3.0.5")
# Variable containing all the cflags definition relative to optional dependencies
SET(CFLAGS_DEPENDENCIES)
IF(BUILD_WITH_URDF_SUPPORT)
ADD_REQUIRED_DEPENDENCY("urdfdom >= 0.2.0")
ADD_PROJECT_DEPENDENCY(urdfdom_headers)
ADD_PROJECT_DEPENDENCY(urdfdom PKG_CONFIG_REQUIRES "urdfdom >= 0.2.0")
SET(urdfdom_VERSION ${urdfdom_headers_VERSION})
ADD_DEFINITIONS(-DPINOCCHIO_WITH_URDFDOM)
LIST(APPEND CFLAGS_DEPENDENCIES "-DPINOCCHIO_WITH_URDFDOM")
IF(${URDFDOM_VERSION} VERSION_GREATER "0.4.2")
IF(${urdfdom_VERSION} VERSION_GREATER "0.4.2")
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
MESSAGE(STATUS "Since urdfdom >= 1.0.0, the default C++ standard is C++11. The project is then compiled with C++11 standard.")
ENDIF(${URDFDOM_VERSION} VERSION_GREATER "0.4.2")
ENDIF(${urdfdom_VERSION} VERSION_GREATER "0.4.2")
ENDIF(BUILD_WITH_URDF_SUPPORT)
IF(BUILD_WITH_AUTODIFF_SUPPORT)
# Check first CppADCodeGen
IF(BUILD_WITH_CODEGEN_SUPPORT)
ADD_REQUIRED_DEPENDENCY("cppadcg >= 2.4.1") # CppADCodeGen 2.4.1 is the first version to check the minimal version of CppAD
ADD_PROJECT_DEPENDENCY(cppadcg 2.4.1 REQUIRED PKG_CONFIG_REQUIRES "cppadcg >= 2.4.1") # CppADCodeGen 2.4.1 is the first version to check the minimal version of CppAD
IF(CPPADCG_FOUND AND BUILD_WITH_CODEGEN_SUPPORT)
ADD_DEFINITIONS(-DPINOCCHIO_WITH_CPPADCG_SUPPORT)
PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_WITH_CPPADCG_SUPPORT")
ENDIF(CPPADCG_FOUND AND BUILD_WITH_CODEGEN_SUPPORT)
ENDIF(BUILD_WITH_CODEGEN_SUPPORT)
ADD_REQUIRED_DEPENDENCY("cppad >= 20180000.0")
ADD_PROJECT_DEPENDENCY(cppad 20180000.0 REQUIRED PKG_CONFIG_REQUIRES "cppad >= 20180000.0")
ADD_DEFINITIONS(-DPINOCCHIO_WITH_CPPAD_SUPPORT)
PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_WITH_CPPAD_SUPPORT")
IF(NOT ${EIGEN3_VERSION} VERSION_GREATER "3.3.0")
......@@ -127,13 +129,10 @@ IF(BUILD_WITH_AUTODIFF_SUPPORT)
ENDIF(BUILD_WITH_AUTODIFF_SUPPORT)
IF(BUILD_WITH_CASADI_SUPPORT)
ADD_REQUIRED_DEPENDENCY("casadi >= 3.4.5")
ENDIF(BUILD_WITH_CASADI_SUPPORT)
IF(CASADI_FOUND AND BUILD_WITH_CASADI_SUPPORT)
ADD_PROJECT_DEPENDENCY(casadi 3.4.5 REQUIRED PKG_CONFIG_REQUIRES "casadi >= 3.4.5")
ADD_DEFINITIONS(-DPINOCCHIO_WITH_CASADI_SUPPORT)
PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_WITH_CASADI_SUPPORT")
ENDIF(CASADI_FOUND AND BUILD_WITH_CASADI_SUPPORT)
ENDIF(BUILD_WITH_CASADI_SUPPORT)
SET(BOOST_REQUIRED_COMPONENTS filesystem serialization system)
SET(BOOST_BUILD_COMPONENTS unit_test_framework)
......@@ -142,12 +141,13 @@ SET(BOOST_OPTIONAL_COMPONENTS "")
IF(BUILD_PYTHON_INTERFACE)
SET(BOOST_OPTIONAL_COMPONENTS ${BOOST_OPTIONAL_COMPONENTS} python)
FINDPYTHON()
ADD_PROJECT_DEPENDENCY(eigenpy 2.2.0 REQUIRED)
ENDIF(BUILD_PYTHON_INTERFACE)
IF(BUILD_WITH_HPP_FCL_SUPPORT)
ADD_DEFINITIONS(-DPINOCCHIO_WITH_HPP_FCL)
LIST(APPEND CFLAGS_DEPENDENCIES "-DPINOCCHIO_WITH_HPP_FCL")
ADD_REQUIRED_DEPENDENCY("hpp-fcl >= 1.4.0")
ADD_PROJECT_DEPENDENCY(hpp-fcl 1.4.0 REQUIRED PKG_CONFIG_REQUIRES "hpp-fcl >= 1.4.0")
# Check whether hpp-fcl python bindings are available.
SET(BUILD_WITH_HPP_FCL_PYTHON_BINDINGS FALSE)
IF(BUILD_PYTHON_INTERFACE)
......
#
# Copyright (c) 2015-2019 CNRS INRIA
# Copyright (c) 2015-2020 CNRS INRIA
#
# ----------------------------------------------------
......@@ -24,16 +24,6 @@ MACRO(ADD_BENCH bench_name)
IF(link_to_main_lib)
SET_TARGET_PROPERTIES(${bench_name} PROPERTIES COMPILE_DEFINITIONS PINOCCHIO_MODEL_DIR="${PINOCCHIO_MODEL_DIR}")
TARGET_LINK_LIBRARIES(${bench_name} PUBLIC ${PROJECT_NAME})
PKG_CONFIG_USE_DEPENDENCY(${bench_name} eigen3)
IF(HPP_FCL_FOUND)
PKG_CONFIG_USE_DEPENDENCY(${bench_name} hpp-fcl)
ENDIF(HPP_FCL_FOUND)
IF(URDFDOM_FOUND)
PKG_CONFIG_USE_DEPENDENCY(${bench_name} urdfdom)
ENDIF(URDFDOM_FOUND)
ENDIF(link_to_main_lib)
ENDIF()
......@@ -50,7 +40,7 @@ ADD_BENCH(timings TRUE)
IF(CPPADCG_FOUND)
ADD_BENCH(timings-cg TRUE)
SET_PROPERTY(TARGET timings-cg PROPERTY CXX_STANDARD 11)
PKG_CONFIG_USE_DEPENDENCY(timings-cg "cppadcg")
TARGET_LINK_LIBRARIES(timings-cg PUBLIC cppadcg::cppadcg)
TARGET_LINK_LIBRARIES(timings-cg PUBLIC ${CMAKE_DL_LIBS})
ENDIF(CPPADCG_FOUND)
......@@ -62,17 +52,17 @@ ADD_BENCH(timings-cholesky TRUE)
ADD_BENCH(timings-derivatives TRUE)
IF(CPPAD_FOUND)
PKG_CONFIG_USE_DEPENDENCY(timings-derivatives "cppad")
TARGET_LINK_LIBRARIES(timings-derivatives PUBLIC cppad::cppad)
ENDIF(CPPAD_FOUND)
IF(CPPADCG_FOUND)
SET_PROPERTY(TARGET timings-derivatives PROPERTY CXX_STANDARD 11)
PKG_CONFIG_USE_DEPENDENCY(timings-derivatives "cppadcg")
TARGET_LINK_LIBRARIES(timings-derivatives PUBLIC cppadcg::cppadcg)
ENDIF(CPPADCG_FOUND)
# timings-eigen
#
ADD_BENCH(timings-eigen)
PKG_CONFIG_USE_DEPENDENCY(timings-eigen "eigen3")
TARGET_LINK_LIBRARIES(timings-eigen PUBLIC Eigen3::Eigen)
# timings-geometry
#
......
......@@ -45,9 +45,6 @@ IF(BUILD_PYTHON_INTERFACE)
include_directories(${EIGEN3_INCLUDE_DIR})
endif()
SET(PKG_CONFIG_PYWRAP_REQUIRES "eigenpy >= 2.2.0")
FOREACH(dep ${PKG_CONFIG_PYWRAP_REQUIRES})
ADD_COMPILE_DEPENDENCY(${dep})
ENDFOREACH(dep ${PKG_CONFIG_PYWRAP_REQUIRES})
# --- LIBRARY --- #
SET(${PYWRAP}_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/${PYTHON_SITELIB}/${PROJECT_NAME})
......@@ -128,15 +125,14 @@ IF(BUILD_PYTHON_INTERFACE)
ENDIF(BUILD_WITH_COMMIT_VERSION)
ADD_HEADER_GROUP(${PYWRAP}_HEADERS)
ADD_SOURCE_GROUP(${PYWRAP}_SOURCES)
PKG_CONFIG_USE_DEPENDENCY(${PYWRAP} eigenpy)
TARGET_LINK_LIBRARIES(${PYWRAP} PUBLIC ${PROJECT_NAME})
TARGET_LINK_LIBRARIES(${PYWRAP} PUBLIC ${PROJECT_NAME} eigenpy::eigenpy)
TARGET_LINK_BOOST_PYTHON(${PYWRAP} PUBLIC)
IF(URDFDOM_FOUND)
PKG_CONFIG_USE_DEPENDENCY(${PYWRAP} urdfdom)
ENDIF(URDFDOM_FOUND)
IF(HPP_FCL_FOUND)
PKG_CONFIG_USE_DEPENDENCY(${PYWRAP} hpp-fcl)
TARGET_LINK_LIBRARIES(${PYWRAP} PUBLIC ${PROJECT_NAME} hpp-fcl::hpp-fcl)
ENDIF(HPP_FCL_FOUND)
IF(BUILD_WITH_HPP_FCL_PYTHON_BINDINGS)
TARGET_COMPILE_DEFINITIONS(${PYWRAP} PRIVATE -DPINOCCHIO_WITH_HPP_FCL_PYTHON_BINDINGS)
......@@ -146,14 +142,6 @@ IF(BUILD_PYTHON_INTERFACE)
TARGET_LINK_LIBRARIES(${PYWRAP} PUBLIC ${PYTHON_LIBRARY})
ENDIF(WIN32)
IF(CPPAD_FOUND)
PKG_CONFIG_USE_DEPENDENCY(${PYWRAP} "cppad")
ENDIF(CPPAD_FOUND)
IF(CPPADCG_FOUND)
SET_PROPERTY(TARGET ${PYWRAP} PROPERTY CXX_STANDARD 11)
PKG_CONFIG_USE_DEPENDENCY(${PYWRAP} "cppadcg")
ENDIF(CPPADCG_FOUND)
IF(APPLE)
# We need to change the extension for Python bindings
SET_TARGET_PROPERTIES(${PYWRAP} PROPERTIES SUFFIX ".so")
......
......@@ -28,36 +28,36 @@ IF(UNIX OR "${CMAKE_GENERATOR_TOOLSET}" MATCHES "ClangCl")
TAG_LIBRARY_VERSION(${PROJECT_NAME})
ENDIF(BUILD_WITH_COMMIT_VERSION)
PKG_CONFIG_USE_DEPENDENCY(${PROJECT_NAME} eigen3)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC Eigen3::Eigen)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_SERIALIZATION_LIBRARY})
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC $<INSTALL_INTERFACE:include>)
# Special care of urdfdom version
IF(URDFDOM_FOUND)
IF(${URDFDOM_VERSION} VERSION_LESS "0.3.0")
IF(urdfdom_FOUND)
IF(${urdfdom_VERSION} VERSION_LESS "0.3.0")
TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} PRIVATE -DPINOCCHIO_URDFDOM_COLLISION_WITH_GROUP_NAME)
ENDIF(${URDFDOM_VERSION} VERSION_LESS "0.3.0")
ENDIF(${urdfdom_VERSION} VERSION_LESS "0.3.0")
# defines types from version 0.4.0
IF(NOT ${URDFDOM_VERSION} VERSION_LESS "0.4.0")
IF(NOT ${urdfdom_VERSION} VERSION_LESS "0.4.0")
TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} PRIVATE -DPINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR)
ENDIF(NOT ${URDFDOM_VERSION} VERSION_LESS "0.4.0")
ENDIF(NOT ${urdfdom_VERSION} VERSION_LESS "0.4.0")
# std::shared_ptr appears from version 1.0.0
IF(${URDFDOM_VERSION} VERSION_GREATER "0.4.2")
IF(${urdfdom_VERSION} VERSION_GREATER "0.4.2")
TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} PRIVATE -DPINOCCHIO_URDFDOM_USE_STD_SHARED_PTR)
ENDIF(${URDFDOM_VERSION} VERSION_GREATER "0.4.2")
ENDIF(${urdfdom_VERSION} VERSION_GREATER "0.4.2")
PKG_CONFIG_USE_DEPENDENCY(${PROJECT_NAME} urdfdom)
ENDIF(URDFDOM_FOUND)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC ${urdfdom_LIBRARIES})
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC ${urdfdom_INCLUDE_DIRS})
ENDIF(urdfdom_FOUND)
IF(HPP_FCL_FOUND)
PKG_CONFIG_USE_DEPENDENCY(${PROJECT_NAME} hpp-fcl)
ENDIF(HPP_FCL_FOUND)
IF(hpp_fcl_FOUND)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC hpp-fcl::hpp-fcl)
ENDIF(hpp_fcl_FOUND)
ADD_HEADER_GROUP(HEADERS)
ADD_SOURCE_GROUP(${PROJECT_NAME}_SOURCES)
INSTALL(TARGETS ${PROJECT_NAME}
EXPORT ${TARGETS_EXPORT_NAME}
......
......@@ -28,17 +28,16 @@ MACRO(ADD_PINOCCHIO_UNIT_TEST NAME)
ADD_TEST_CFLAGS(${NAME} "-DNOMINMAX -D_USE_MATH_DEFINES")
ENDIF(WIN32)
PKG_CONFIG_USE_DEPENDENCY(${TEST_NAME} eigen3)
FOREACH(PKG ${PKGS})
PKG_CONFIG_USE_DEPENDENCY(${TEST_NAME} ${PKG})
TARGET_LINK_LIBRARIES(${TEST_NAME} PUBLIC ${PKG}::${PKG})
ENDFOREACH(PKG)
IF(URDFDOM_FOUND AND (UNIX OR "${CMAKE_GENERATOR_TOOLSET}" MATCHES "ClangCl"))
PKG_CONFIG_USE_DEPENDENCY(${TEST_NAME} urdfdom)
TARGET_LINK_LIBRARIES(${TEST_NAME} PUBLIC urdfdom::urdfdom)
ENDIF(URDFDOM_FOUND AND (UNIX OR "${CMAKE_GENERATOR_TOOLSET}" MATCHES "ClangCl"))
IF(HPP_FCL_FOUND)
PKG_CONFIG_USE_DEPENDENCY(${TEST_NAME} hpp-fcl)
TARGET_LINK_LIBRARIES(${TEST_NAME} PUBLIC hpp-fcl::hpp-fcl)
ENDIF(HPP_FCL_FOUND)
TARGET_LINK_LIBRARIES(${TEST_NAME} PUBLIC ${PROJECT_NAME})
......
......@@ -5,7 +5,7 @@
# --- MACROS ------------------------------------------------------------------
# --- MACROS ------------------------------------------------------------------
# --- MACROS ------------------------------------------------------------------
MACRO(ADD_UTIL NAME UTIL_SRC PKGS)
MACRO(ADD_UTIL NAME UTIL_SRC)
IF(BUILD_UTILS)
ADD_EXECUTABLE(${NAME} ${UTIL_SRC})
......@@ -13,27 +13,19 @@ MACRO(ADD_UTIL NAME UTIL_SRC PKGS)
ADD_EXECUTABLE(${NAME} EXCLUDE_FROM_ALL ${UTIL_SRC})
ENDIF(BUILD_UTILS)
FOREACH(PKG ${PKGS})
PKG_CONFIG_USE_DEPENDENCY(${NAME} ${PKG})
ENDFOREACH(PKG)
TARGET_LINK_LIBRARIES (${NAME} PUBLIC ${PROJECT_NAME})
TARGET_LINK_LIBRARIES(${NAME} PUBLIC ${PROJECT_NAME})
IF(BUILD_PYTHON_INTERFACE)
TARGET_INCLUDE_DIRECTORIES(${NAME} SYSTEM PUBLIC ${PYTHON_INCLUDE_DIRS})
TARGET_LINK_BOOST_PYTHON(${NAME} PUBLIC)
TARGET_LINK_LIBRARIES(${NAME} PUBLIC ${PYTHON_LIBRARIES})
ENDIF(BUILD_PYTHON_INTERFACE)
IF(HPP_FCL_FOUND)
PKG_CONFIG_USE_DEPENDENCY(${NAME} hpp-fcl)
ENDIF(HPP_FCL_FOUND)
ADD_DEPENDENCIES(utils ${NAME})
IF(BUILD_UTILS)
INSTALL(TARGETS ${NAME} DESTINATION bin)
ENDIF(BUILD_UTILS)
ENDMACRO(ADD_UTIL)
# --- RULES -------------------------------------------------------------------
......@@ -41,7 +33,7 @@ ENDMACRO(ADD_UTIL)
# --- RULES -------------------------------------------------------------------
ADD_CUSTOM_TARGET(utils)
IF(URDFDOM_FOUND)
ADD_UTIL(pinocchio_read_model pinocchio_read_model "eigen3;urdfdom")
ENDIF(URDFDOM_FOUND)
IF(urdfdom_FOUND)
ADD_UTIL(pinocchio_read_model pinocchio_read_model)
ENDIF(urdfdom_FOUND)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment