From 1d3775f60537c76f03f44dba550f1cdb6b7cc0b4 Mon Sep 17 00:00:00 2001
From: Guilhem Saurel <guilhem.saurel@laas.fr>
Date: Thu, 16 Apr 2020 13:51:09 +0200
Subject: [PATCH] [CMake] Exports

---
 CMakeLists.txt         | 105 ++++++++++++++++++++++++++++++++---------
 cmake                  |   2 +-
 plugins/CMakeLists.txt |   9 ++--
 src/CMakeLists.txt     |  92 ------------------------------------
 tests/CMakeLists.txt   |  32 ++++---------
 5 files changed, 96 insertions(+), 144 deletions(-)
 delete mode 100644 src/CMakeLists.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e4a67b1..102950f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,6 @@
 #
-# Copyright (c) 2014 CNRS
-# Authors: Florent Lamiraux
+# Copyright (c) 2014, 2020 CNRS
+# Authors: Florent Lamiraux, Guilhem Saurel
 #
 #
 # This file is part of hpp-manipulation
@@ -17,12 +17,14 @@
 # hpp-manipulation  If not, see
 # <http://www.gnu.org/licenses/>.
 
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
+CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
 
 SET(PROJECT_NAME hpp-manipulation)
 SET(PROJECT_DESCRIPTION "Classes for manipulation planning.")
 
+SET(PROJECT_USE_CMAKE_EXPORT TRUE)
 SET(CXX_DISABLE_WERROR TRUE)
+
 INCLUDE(cmake/hpp.cmake)
 INCLUDE(cmake/boost.cmake)
 
@@ -32,7 +34,7 @@ PROJECT(${PROJECT_NAME} ${PROJECT_ARGS})
 LIST(APPEND PKG_CONFIG_ADDITIONAL_VARIABLES cmake_plugin)
 
 # Activate test using UR5 if requested
-SET (TEST_UR5 FALSE CACHE BOOL "Activate tests using ur5")
+SET(TEST_UR5 FALSE CACHE BOOL "Activate tests using ur5")
 
 # Ask Doxygen to create a tree view in html documentation
 SET(DOXYGEN_TREEVIEW "NO" CACHE STRING "Set to YES to generate a tree view in the html documentation")
@@ -40,27 +42,21 @@ SET(DOXYGEN_TREEVIEW "NO" CACHE STRING "Set to YES to generate a tree view in th
 SET(HPP_MANIPULATION_HAS_WHOLEBODY_STEP TRUE
   CACHE BOOL "Compile with dependency to hpp-wholebody-step")
 
-SET(BOOST_BUILD_COMPONENTS unit_test_framework)
-SET(BOOST_INSTALL_COMPONENTS regex)
-SET(BOOST_COMPONENTS ${BOOST_INSTALL_COMPONENTS} ${BOOST_BUILD_COMPONENTS})
+SET(BOOST_COMPONENTS unit_test_framework regex)
 
 SEARCH_FOR_BOOST()
-ADD_DOC_DEPENDENCY("hpp-pinocchio >= 4")
-ADD_DOC_DEPENDENCY("hpp-fcl >= 0.4.3")
-ADD_REQUIRED_DEPENDENCY("hpp-core >= 4")
-ADD_REQUIRED_DEPENDENCY("hpp-constraints >= 4")
-ADD_REQUIRED_DEPENDENCY("hpp-statistics >= 1.1")
-IF (HPP_MANIPULATION_HAS_WHOLEBODY_STEP)
-   ADD_REQUIRED_DEPENDENCY("hpp-wholebody-step >= 4")
-ENDIF ()
-IF (TEST_UR5)
+ADD_PROJECT_DEPENDENCY("hpp-core" REQUIRED)
+IF(HPP_MANIPULATION_HAS_WHOLEBODY_STEP)
+  ADD_PROJECT_DEPENDENCY("hpp-wholebody-step" REQUIRED)
+ENDIF()
+IF(TEST_UR5)
   ADD_REQUIRED_DEPENDENCY("hpp_universal_robot")
-ENDIF ()
+ENDIF()
 
-CONFIG_FILES (doc/main.hh
+CONFIG_FILES(doc/main.hh
   include/hpp/manipulation/package-config.hh)
 
-SET (${PROJECT_NAME}_HEADERS
+SET(${PROJECT_NAME}_HEADERS
   ${CMAKE_BINARY_DIR}/include/hpp/manipulation/package-config.hh
   include/hpp/manipulation/fwd.hh
   include/hpp/manipulation/handle.hh
@@ -103,10 +99,73 @@ SET (${PROJECT_NAME}_HEADERS
   include/hpp/manipulation/steering-method/end-effector-trajectory.hh
   )
 
-ADD_SUBDIRECTORY(src)
+SET(${PROJECT_NAME}_SOURCES
+  src/handle.cc
+  src/manipulation-planner.cc
+  src/problem-solver.cc
+  src/roadmap.cc
+  src/connected-component.cc
+  src/leaf-connected-comp.cc
+  src/constraint-set.cc
+  src/roadmap-node.cc
+  src/device.cc
+  src/weighed-distance.cc
+  src/problem.cc
+  src/graph-path-validation.cc
+  src/graph-optimizer.cc
+
+  src/graph/state.cc
+  src/graph/edge.cc
+  src/graph/graph.cc
+  src/graph/graph-component.cc
+  src/graph/state-selector.cc
+  src/graph/guided-state-selector.cc
+  src/graph/statistics.cc
+  src/graph/helper.cc
+
+  src/graph/dot.cc
+  src/graph/validation.cc
+
+  src/path-optimization/random-shortcut.cc
+  src/path-optimization/enforce-transition-semantic.cc
+
+  src/path-planner/end-effector-trajectory.cc
+
+  src/problem-target/state.cc
+
+  src/steering-method/end-effector-trajectory.cc
+  src/steering-method/cross-state-optimization.cc
+  src/steering-method/graph.cc
+  )
+
+IF(HPP_MANIPULATION_HAS_WHOLEBODY_STEP)
+  SET(${PROJECT_NAME}_SOURCES
+    ${${PROJECT_NAME}_SOURCES}
+    src/path-optimization/small-steps.cc
+    )
+ENDIF(HPP_MANIPULATION_HAS_WHOLEBODY_STEP)
+
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_HEADERS})
+TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC $<INSTALL_INTERFACE:include>)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} hpp-core::hpp-core ${Boost_REGEX_LIBRARY})
+IF(HPP_MANIPULATION_HAS_WHOLEBODY_STEP)
+  TARGET_LINK_LIBRARIES(${PROJECT_NAME} hpp-wholebody-step::hpp-wholebody-step)
+ENDIF(HPP_MANIPULATION_HAS_WHOLEBODY_STEP)
+
+INSTALL(TARGETS ${PROJECT_NAME} EXPORT ${TARGETS_EXPORT_NAME} DESTINATION lib)
+
+# GPL licenced part
+
+SET(${PROJECT_NAME}_SOURCES_GPL
+  src/path-optimization/spline-gradient-based.cc
+  )
+
+ADD_LIBRARY(${PROJECT_NAME}-gpl SHARED ${${PROJECT_NAME}_SOURCES_GPL})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME}-gpl ${PROJECT_NAME} hpp-core::hpp-core-gpl)
+
+INSTALL(TARGETS ${PROJECT_NAME}-gpl EXPORT ${TARGETS_EXPORT_NAME} DESTINATION lib)
+
 ADD_SUBDIRECTORY(plugins)
 ADD_SUBDIRECTORY(tests)
 
-# Add dependency toward hpp-manipulation library in pkg-config file.
-PKG_CONFIG_APPEND_LIBS("hpp-manipulation")
-PKG_CONFIG_APPEND_BOOST_LIBS(${BOOST_INSTALL_COMPONENTS})
+PKG_CONFIG_APPEND_LIBS(${PROJECT_NAME})
diff --git a/cmake b/cmake
index 7eca9ee..7ab756b 160000
--- a/cmake
+++ b/cmake
@@ -1 +1 @@
-Subproject commit 7eca9ee6c9d1c4ee20eb82272e94f9d11642053a
+Subproject commit 7ab756beff8729739c45731dfc1edb6f88d2dbc8
diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt
index 77bbad0..63a3024 100644
--- a/plugins/CMakeLists.txt
+++ b/plugins/CMakeLists.txt
@@ -1,5 +1,6 @@
-# Copyright (c) 2019, Joseph Mirabel
+# Copyright (c) 2019, 2020, CNRS
 # Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
+# Authors: Guilhem Saurel (guilhem.saurel@laas.fr)
 #
 # This file is part of hpp-manipulation.
 # hpp-manipulation is free software: you can redistribute it
@@ -18,10 +19,8 @@ INCLUDE(${HPP_CORE_CMAKE_PLUGIN})
 
 HPP_ADD_PLUGIN(manipulation-spline-gradient-based
   SOURCES spline-gradient-based.cc
-  LINK_DEPENDENCIES ${PROJECT_NAME} ${PROJECT_NAME}-gpl hpp-core-gpl
-  PKG_CONFIG_DEPENDENCIES hpp-core)
+  LINK_DEPENDENCIES ${PROJECT_NAME}-gpl)
 
 HPP_ADD_PLUGIN(end-effector-trajectory
   SOURCES end-effector-trajectory.cc
-  LINK_DEPENDENCIES ${PROJECT_NAME}
-  PKG_CONFIG_DEPENDENCIES hpp-core)
+  LINK_DEPENDENCIES ${PROJECT_NAME})
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
deleted file mode 100644
index 19c8702..0000000
--- a/src/CMakeLists.txt
+++ /dev/null
@@ -1,92 +0,0 @@
-#
-# Copyright (c) 2014 CNRS
-# Authors: Florent Lamiraux
-#
-#
-# This file is part of hpp-manipulation
-# hpp-manipulation is free software: you can redistribute it
-# and/or modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation, either version
-# 3 of the License, or (at your option) any later version.
-#
-# hpp-manipulation is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
-# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Lesser Public License for more details.  You should have
-# received a copy of the GNU Lesser General Public License along with
-# hpp-manipulation  If not, see
-# <http://www.gnu.org/licenses/>.
-
-SET(LIBRARY_NAME ${PROJECT_NAME})
-
-SET(SOURCES
-  handle.cc
-  manipulation-planner.cc
-  problem-solver.cc
-  roadmap.cc
-  connected-component.cc
-  leaf-connected-comp.cc
-  constraint-set.cc
-  roadmap-node.cc
-  device.cc
-  weighed-distance.cc
-  problem.cc
-  graph-path-validation.cc
-  graph-optimizer.cc
-
-  graph/state.cc
-  graph/edge.cc
-  graph/graph.cc
-  graph/graph-component.cc
-  graph/state-selector.cc
-  graph/guided-state-selector.cc
-  graph/statistics.cc
-  graph/helper.cc
-
-  graph/dot.cc
-  graph/validation.cc
-
-  path-optimization/random-shortcut.cc
-  path-optimization/enforce-transition-semantic.cc
-
-  path-planner/end-effector-trajectory.cc
-
-  problem-target/state.cc
-
-  steering-method/end-effector-trajectory.cc
-  steering-method/cross-state-optimization.cc
-  steering-method/graph.cc
-  )
-
-IF(HPP_WHOLEBODY_STEP_FOUND)
-  SET(SOURCES
-    ${SOURCES}
-    path-optimization/small-steps.cc
-    )
-ENDIF(HPP_WHOLEBODY_STEP_FOUND)
-
-ADD_LIBRARY(${LIBRARY_NAME} SHARED ${SOURCES})
-
-PKG_CONFIG_USE_DEPENDENCY(${LIBRARY_NAME} hpp-core)
-PKG_CONFIG_USE_DEPENDENCY(${LIBRARY_NAME} hpp-statistics)
-PKG_CONFIG_USE_DEPENDENCY(${LIBRARY_NAME} hpp-constraints)
-IF(HPP_WHOLEBODY_STEP_FOUND)
-  PKG_CONFIG_USE_DEPENDENCY(${LIBRARY_NAME} hpp-wholebody-step)
-ENDIF(HPP_WHOLEBODY_STEP_FOUND)
-TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${Boost_LIBRARIES})
-
-INSTALL(TARGETS ${LIBRARY_NAME} DESTINATION lib)
-
-ADD_LIBRARY(${LIBRARY_NAME}-gpl SHARED
-  path-optimization/spline-gradient-based.cc
-  )
-
-PKG_CONFIG_USE_DEPENDENCY(${LIBRARY_NAME}-gpl hpp-core)
-PKG_CONFIG_USE_DEPENDENCY(${LIBRARY_NAME}-gpl hpp-statistics)
-PKG_CONFIG_USE_DEPENDENCY(${LIBRARY_NAME}-gpl hpp-constraints)
-IF(HPP_WHOLEBODY_STEP_FOUND)
-  PKG_CONFIG_USE_DEPENDENCY(${LIBRARY_NAME}-gpl hpp-wholebody-step)
-ENDIF(HPP_WHOLEBODY_STEP_FOUND)
-TARGET_LINK_LIBRARIES(${LIBRARY_NAME}-gpl ${LIBRARY_NAME} hpp-core-gpl)
-
-INSTALL(TARGETS ${LIBRARY_NAME}-gpl DESTINATION lib)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 16fb181..d84cf1a 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,6 +1,6 @@
-# Copyright 2012, 2013, 2014 CNRS-LAAS
+# Copyright 2012, 2013, 2014, 2020 CNRS-LAAS
 #
-# Author: Mathieu Geisert
+# Authors: Mathieu Geisert, Guilhem Saurel
 #
 # This file is part of hpp-core
 # hpp-manipulation is free software: you can redistribute it and/or modify
@@ -15,8 +15,6 @@
 # You should have received a copy of the GNU Lesser General Public License
 # along with hpp-manipulation  If not, see <http://www.gnu.org/licenses/>.
 
-INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
-
 # Make Boost.Test generates the main function in test cases.
 ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN)
 
@@ -28,24 +26,12 @@ ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN)
 # This macro will create a binary from `NAME.cc', link it against
 # Boost and add it to the test suite.
 #
-MACRO(ADD_TESTCASE NAME GENERATED)
-  IF (${GENERATED} STREQUAL TRUE)
-    ADD_EXECUTABLE(${NAME} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.cc)
-  ELSE()
-    ADD_EXECUTABLE(${NAME} ${NAME}.cc)
-  ENDIF()
-  ADD_TEST(${NAME} ${RUNTIME_OUTPUT_DIRECTORY}/${NAME})
-
-  PKG_CONFIG_USE_DEPENDENCY (${NAME} hpp-constraints)
-  # Link against Boost and project library.
-  TARGET_LINK_LIBRARIES(${NAME}
-    ${PROJECT_NAME}
-    ${Boost_LIBRARIES}
-    )
-
+MACRO(ADD_TESTCASE NAME)
+  ADD_UNIT_TEST(${NAME} ${NAME}.cc)
+  TARGET_LINK_LIBRARIES(${NAME} ${PROJECT_NAME} ${Boost_LIBRARIES})
 ENDMACRO(ADD_TESTCASE)
 
-IF (TEST_UR5)
-  ADD_TESTCASE (test-constraintgraph FALSE)
-  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_UR5")
-ENDIF ()
+IF(TEST_UR5)
+  ADD_TESTCASE(test-constraintgraph)
+  TARGET_COMPILE_DEFINITIONS(test-constraintgraph -DTEST_UR5)
+ENDIF()
-- 
GitLab