From 1e7c6d99a1990008658fc2645e45e787541aee0c Mon Sep 17 00:00:00 2001
From: Peter Kaiser <peter.kaiser@kit.edu>
Date: Thu, 9 Aug 2018 11:53:42 +0200
Subject: [PATCH] Revert "Move urdf importer to a separate lib and always build
 it when all dependencies are available"

This reverts commit 7cd6f1605dc051c8db5968d3ed7dfdc297b1b119.
---
 VirtualRobot/CMakeLists.txt                   | 38 ++++++++++++++++-
 VirtualRobot/Import/URDF/CMakeLists.txt       | 41 +++++++++++++------
 .../examples/loadURDFRobot/CMakeLists.txt     |  4 +-
 3 files changed, 67 insertions(+), 16 deletions(-)

diff --git a/VirtualRobot/CMakeLists.txt b/VirtualRobot/CMakeLists.txt
index 657b629bf..5b3ec859c 100644
--- a/VirtualRobot/CMakeLists.txt
+++ b/VirtualRobot/CMakeLists.txt
@@ -465,7 +465,43 @@ endif ()
 #    )
 #endif ()
 
-ADD_SUBDIRECTORY(Import/URDF)
+
+#check for URDF
+if (Simox_USE_URDF)
+    include(SearchForTinyXML)
+    FIND_PACKAGE(urdfdom)
+    #FIND_PACKAGE(PkgConfig)
+    #PKG_CHECK_MODULES(URDFDOM REQUIRED urdfdom>=0.2.9)
+    #PKG_CHECK_MODULES(URDFDOM_HEADERS REQUIRED urdfdom_headers>=0.2.3)
+
+    if (tinyxml_library AND URDF_FOUND)
+        MESSAGE(STATUS " ** Including URDF importer")
+
+        include_directories(SYSTEM ${tinyxml_include_dirs})
+        link_directories(${tinyxml_library_dirs})
+        add_definitions(${tinyxml_cflags})
+        add_definitions(" -DTIXML_USE_STL ")
+
+        INCLUDE_DIRECTORIES (SYSTEM
+            ${URDFDOM_INCLUDE_DIRS}
+            ${URDFDOM_PARSER_INCLUDE_DIRS}
+            ${URDFDOM_HEADERS_INCLUDE_DIRS}
+        )
+
+        SET(SOURCES
+          ${SOURCES}
+            Import/URDF/SimoxURDFFactory.cpp
+            )
+        SET(INCLUDES
+          ${INCLUDES}
+            Import/URDF/SimoxURDFFactory.h
+            )
+
+        SET(Simox_EXTERNAL_LIBRARIES ${Simox_EXTERNAL_LIBRARIES} ${URDFDOM_LIBRARIES})
+    else()
+        MESSAGE(STATUS " *** urdfDom or TinyXML not found: skipping URDF importer...")
+    endif()
+endif()
 
 # include collision detection
 INCLUDE (CollisionDetection/CMakeLists.txt)
diff --git a/VirtualRobot/Import/URDF/CMakeLists.txt b/VirtualRobot/Import/URDF/CMakeLists.txt
index 01b3e2505..f01dc5cb3 100644
--- a/VirtualRobot/Import/URDF/CMakeLists.txt
+++ b/VirtualRobot/Import/URDF/CMakeLists.txt
@@ -1,32 +1,47 @@
-PROJECT (VirtualRobotImportUrdf)
+PROJECT (SIMOX_URDFREADER)
+
+LIST( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake )
 
 include(SearchForTinyXML)
 FIND_PACKAGE(urdfdom)
+#FIND_PACKAGE(PkgConfig)
+#PKG_CHECK_MODULES(URDFDOM REQUIRED urdfdom>=0.2.9)
+#PKG_CHECK_MODULES(URDFDOM_HEADERS REQUIRED urdfdom_headers>=0.2.3)
+
 if (tinyxml_library AND URDF_FOUND)
-    message(STATUS "Building VirtualRobotImportUrdf")
 
     include_directories(SYSTEM ${tinyxml_include_dirs})
     link_directories(${tinyxml_library_dirs})
     add_definitions(${tinyxml_cflags})
     add_definitions("-DTIXML_USE_STL")
 
+    FIND_PACKAGE(simox REQUIRED)
     INCLUDE_DIRECTORIES (
 	    ${URDFDOM_INCLUDE_DIRS}
 	    ${URDFDOM_PARSER_INCLUDE_DIRS}
 	    ${URDFDOM_HEADERS_INCLUDE_DIRS}
     )
+    setupSimoxExternalLibraries()
+
 
-    SET ( SOURCES SimoxURDFFactory.cpp)
-    SET ( HEADERS SimoxURDFFactory.h  )
+    SET (CMAKE_SKIP_BUILD_RPATH FALSE)
+    SET (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
+    SET (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
+    SET (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
 
-    ADD_LIBRARY ( VirtualRobotImportUrdf SHARED ${SOURCES}  ${HEADERS}  )
+    SET ( URDFIMPORT_SOURCES
+	    SimoxURDFFactory.cpp
+	    )
+    SET ( URDFIMPORT_HEADERS
+	    SimoxURDFFactory.h
+	    )
+
+    ADD_LIBRARY ( simox_urdfimport SHARED ${URDFIMPORT_SOURCES}  ${URDFIMPORT_HEADERS}  )
+
+    add_definitions("-DDEMO_BASE_PATH=\"${PROJECT_SOURCE_DIR}\"")
+    ADD_EXECUTABLE (loadURDFobot loadURDFobot.cpp)
     
-    TARGET_LINK_LIBRARIES (VirtualRobotImportUrdf VirtualRobot ${URDFDOM_LIBRARIES})
-else()
-    if (NOT tinyxml_library)
-    message(STATUS "Not building VirtualRobotImportUrdf: tinyxml not found")
-    endif()
-    if (NOT URDF_FOUND)
-    message(STATUS "Not building VirtualRobotImportUrdf: urdfdom not found")
-    endif()
+    TARGET_LINK_LIBRARIES (simox_urdfimport VirtualRobot ${URDFDOM_LIBRARIES})
+    TARGET_LINK_LIBRARIES(loadURDFobot simox_urdfimport VirtualRobot ${URDFDOM_LIBRARIES})
+
 endif()
diff --git a/VirtualRobot/examples/loadURDFRobot/CMakeLists.txt b/VirtualRobot/examples/loadURDFRobot/CMakeLists.txt
index de5a88701..c5f9fa933 100644
--- a/VirtualRobot/examples/loadURDFRobot/CMakeLists.txt
+++ b/VirtualRobot/examples/loadURDFRobot/CMakeLists.txt
@@ -1,6 +1,6 @@
 PROJECT ( loadURDFRobot )
 
-if (TARGET VirtualRobotImportUrdf)
+if (tinyxml_library AND URDF_FOUND)
 
   include_directories(SYSTEM ${tinyxml_include_dirs})
   link_directories(${tinyxml_library_dirs})
@@ -17,7 +17,7 @@ if (TARGET VirtualRobotImportUrdf)
   SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${Simox_BIN_DIR})
   SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES FOLDER "Examples")
 
-  TARGET_LINK_LIBRARIES(${PROJECT_NAME} VirtualRobot VirtualRobotImportUrdf ${URDFDOM_LIBRARIES})
+  TARGET_LINK_LIBRARIES(${PROJECT_NAME} VirtualRobot ${URDFDOM_LIBRARIES})
   
   
   #######################################################################################
-- 
GitLab