From 80ad101bc6c69cd455d55567390239624a577b9a Mon Sep 17 00:00:00 2001
From: Johannes Wienke <languitar@semipol.de>
Date: Fri, 3 Aug 2012 19:28:32 +0200
Subject: [PATCH] Make RSC installable in parallel with several versions. This
 means: * provide a subdirectory for include files * install
 share files in a versioned subfolder * rename the
 pkg-config file to rsc0.X.pc (this breaks backwards
 compatibility) * fix pkg-config and cmake config files to
 include the new directories

refs #1127
---
 3rdparty/CMakeLists.txt |  2 +-
 CMakeLists.txt          | 23 +++++++++++++----------
 RSCConfig.cmake.in      |  4 ++--
 rsc.pc.in               |  2 +-
 src/CMakeLists.txt      | 12 ++++++------
 5 Dateien geändert, 23 Zeilen hinzugefügt(+), 20 Zeilen entfernt(-)

diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt
index b854531..be8eb32 100644
--- a/3rdparty/CMakeLists.txt
+++ b/3rdparty/CMakeLists.txt
@@ -1,5 +1,5 @@
 
 IF(USE_INTERNAL_BOOST_UUID)
     FILE(GLOB_RECURSE UUID_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" *.hpp)
-    INSTALL(FILES ${UUID_FILES} DESTINATION include/rsc/3rdparty/boost.uuid/boost/uuid)
+    INSTALL(FILES ${UUID_FILES} DESTINATION "include/${INSTALL_PATH_PREFIX}/3rdparty/boost.uuid/boost/uuid")
 ENDIF()
diff --git a/CMakeLists.txt b/CMakeLists.txt
index edb5140..99dfc2b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,7 +35,10 @@ SET(SO_VERSION "${RSC_VERSION_MAJOR}.${RSC_VERSION_MINOR}")
 SET(RSC_NAME "rsc")
 SET(RSC_TEST_NAME "rsctest")
 
-SET(RSC_CMAKE_PATH "share/cmake")
+SET(INSTALL_PATH_PREFIX "rsc${RSC_VERSION_MAJOR}.${RSC_VERSION_MINOR}"
+    CACHE STRING "Prefix path applied to all non-versioned installed files in order to prevent version clashes.")
+
+SET(RSC_CMAKE_PATH "share/${INSTALL_PATH_PREFIX}/cmake")
 SET(RSC_CMAKE_MODULE_PATH "${RSC_CMAKE_PATH}/Modules")
 SET(RSC_CMAKE_TOOLCHAIN_PATH "${RSC_CMAKE_PATH}/Toolchains")
 
@@ -130,15 +133,15 @@ SET(EXTERNAL_INCLUDES ${Boost_INCLUDE_DIRS})
 IF(NOT USE_INTERNAL_BOOST_UUID)
     LIST(APPEND EXTERNAL_INCLUDES ${BOOSTUUID_INCLUDE_DIRS})
 ELSE()
-    LIST(APPEND EXTERNAL_INCLUDES "\${includedir}/rsc/3rdparty/boost.uuid/")
+    LIST(APPEND EXTERNAL_INCLUDES "\${includedir}/${INSTALL_PATH_PREFIX}/3rdparty/boost.uuid/")
 ENDIF()
 STRING(REPLACE ";" " -I" EXTERNAL_INCLUDE_COMMANDS "${EXTERNAL_INCLUDES}")
 STRING(LENGTH "${EXTERNAL_INCLUDE_COMMANDS}" EXT_LENGTH)
 IF(${EXT_LENGTH} GREATER 0)
     SET(EXTERNAL_INCLUDE_COMMANDS "-I${EXTERNAL_INCLUDE_COMMANDS}")
 ENDIF()
-CONFIGURE_FILE(rsc.pc.in ${CMAKE_BINARY_DIR}/rsc.pc @ONLY)
-INSTALL(FILES ${CMAKE_BINARY_DIR}/rsc.pc DESTINATION lib/pkgconfig)
+CONFIGURE_FILE(rsc.pc.in "${CMAKE_BINARY_DIR}/rsc${RSC_VERSION_MAJOR}.${RSC_VERSION_MINOR}.pc" @ONLY)
+INSTALL(FILES "${CMAKE_BINARY_DIR}/rsc${RSC_VERSION_MAJOR}.${RSC_VERSION_MINOR}.pc" DESTINATION lib/pkgconfig)
 
 # --- cmake config files ---
 
@@ -154,16 +157,16 @@ SET(LIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
 IF(CMAKE_LINK_LIBRARY_SUFFIX)
     SET(LIB_SUFFIX ${CMAKE_LINK_LIBRARY_SUFFIX})
 ENDIF()
-CONFIGURE_FILE(RSCConfig.cmake.in ${CMAKE_BINARY_DIR}/RSCConfig.cmake @ONLY)
-INSTALL(FILES ${CMAKE_BINARY_DIR}/RSCConfig.cmake DESTINATION share/rsc)
-CONFIGURE_FILE(RSCConfigVersion.cmake.in ${CMAKE_BINARY_DIR}/RSCConfigVersion.cmake @ONLY)
-INSTALL(FILES ${CMAKE_BINARY_DIR}/RSCConfigVersion.cmake DESTINATION share/rsc)
+CONFIGURE_FILE(RSCConfig.cmake.in "${CMAKE_BINARY_DIR}/RSCConfig.cmake" @ONLY)
+INSTALL(FILES "${CMAKE_BINARY_DIR}/RSCConfig.cmake" DESTINATION "share/${INSTALL_PATH_PREFIX}")
+CONFIGURE_FILE(RSCConfigVersion.cmake.in "${CMAKE_BINARY_DIR}/RSCConfigVersion.cmake" @ONLY)
+INSTALL(FILES "${CMAKE_BINARY_DIR}/RSCConfigVersion.cmake" DESTINATION "share/${INSTALL_PATH_PREFIX}")
 
 EXPORT(TARGETS ${RSC_NAME} FILE "${CMAKE_BINARY_DIR}/RSCDepends.cmake")
 INSTALL(EXPORT RSCDepends
-        DESTINATION "share/rsc")
+        DESTINATION "share/${INSTALL_PATH_PREFIX}")
 
-INSTALL(FILES COPYING.txt DESTINATION share/doc/rsc RENAME copyright)
+INSTALL(FILES COPYING.txt DESTINATION "share/doc/${INSTALL_PATH_PREFIX}" RENAME copyright)
 
 # --- enable unit tests if desired ---
 
diff --git a/RSCConfig.cmake.in b/RSCConfig.cmake.in
index 49d0dc7..7059107 100644
--- a/RSCConfig.cmake.in
+++ b/RSCConfig.cmake.in
@@ -7,8 +7,8 @@ IF(NOT RSC_CONFIG_PROCESSED)
         INCLUDE("${RSC_CONFIG_DIR}/RSCBuildTreeSettings.cmake")
     ELSE()
 
-        SET(RSC_INCLUDE_DIRS "${RSC_CONFIG_DIR}/../../include"
-                             "${RSC_CONFIG_DIR}/../../include/rsc/3rdparty/boost.uuid")
+        SET(RSC_INCLUDE_DIRS "${RSC_CONFIG_DIR}/../../include/@INSTALL_PATH_PREFIX@"
+                             "${RSC_CONFIG_DIR}/../../include/@INSTALL_PATH_PREFIX@/3rdparty/boost.uuid")
         SET(RSC_RUNTIME_LIBRARY_DIRS "${RSC_CONFIG_DIR}/../../bin")
         SET(RSC_CMAKE_MODULE_PATH "${RSC_CONFIG_DIR}/../../@RSC_CMAKE_MODULE_PATH@")
         SET(RSC_CMAKE_TOOLCHAINS_PATH "${RSC_CONFIG_DIR}/../../@RSC_CMAKE_TOOLCHAIN_PATH@")
diff --git a/rsc.pc.in b/rsc.pc.in
index 510dcb7..8a2cc94 100644
--- a/rsc.pc.in
+++ b/rsc.pc.in
@@ -1,6 +1,6 @@
 prefix=@CMAKE_INSTALL_PREFIX@
 libdir=${prefix}/lib
-includedir=${prefix}/include
+includedir=${prefix}/include/@INSTALL_PATH_PREFIX@
 
 Name: Robotics Systems Commons
 Description: RSC is a Code.CoR-Lab project focused on all aspects of reusable library functions in robotics systems.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 8898710..5bfc1cb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -8,10 +8,10 @@ ELSE()
     SET(INIT_METHOD_NAME RSC_HAVE_NO_INIT_METHOD_ERROR)
 ENDIF()
 CONFIGURE_FILE(rsc/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/rsc/config.h @ONLY)
-INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/rsc/config.h DESTINATION include/rsc)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/rsc/config.h DESTINATION "include/${INSTALL_PATH_PREFIX}/rsc")
 
 CONFIGURE_FILE(rsc/rscexports.h.in ${CMAKE_CURRENT_BINARY_DIR}/rsc/rscexports.h @ONLY)
-INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/rsc/rscexports.h DESTINATION include/rsc)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/rsc/rscexports.h DESTINATION "include/${INSTALL_PATH_PREFIX}/rsc")
 
 # version stuff
 INCLUDE(PadString)
@@ -19,8 +19,8 @@ PAD_STRING(MAJOR_PADDED 2 "0" ${RSC_VERSION_MAJOR})
 PAD_STRING(MINOR_PADDED 2 "0" ${RSC_VERSION_MINOR})
 PAD_STRING(PATCH_PADDED 2 "0" ${RSC_VERSION_PATCH})
 SET(RSC_VERSION_NUMERIC "${MAJOR_PADDED}${MINOR_PADDED}${PATCH_PADDED}")
-CONFIGURE_FILE(rsc/RSCVersion.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/rsc/RSCVersion.cpp @ONLY)
-CONFIGURE_FILE(rsc/RSCVersion.h.in ${CMAKE_CURRENT_BINARY_DIR}/rsc/RSCVersion.h @ONLY)
+CONFIGURE_FILE(rsc/RSCVersion.cpp.in "${CMAKE_CURRENT_BINARY_DIR}/rsc/RSCVersion.cpp" @ONLY)
+CONFIGURE_FILE(rsc/RSCVersion.h.in "${CMAKE_CURRENT_BINARY_DIR}/rsc/RSCVersion.h" @ONLY)
 
 INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/rsc)
 
@@ -35,7 +35,7 @@ FILE(GLOB SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
 SET(SOURCES ${SOURCES}
             rsc/debug/DebugTools.cpp
             rsc/subprocess/Subprocess.cpp
-            ${CMAKE_CURRENT_BINARY_DIR}/rsc/RSCVersion.cpp)
+            "${CMAKE_CURRENT_BINARY_DIR}/rsc/RSCVersion.cpp")
 
 FILE(GLOB HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
                   "rsc/logging/*.h"
@@ -90,4 +90,4 @@ INSTALL(TARGETS ${RSC_NAME}
         RUNTIME DESTINATION bin
         LIBRARY DESTINATION lib
         ARCHIVE DESTINATION lib)
-INSTALL_FILES_RECURSIVE(include HEADERS)
+INSTALL_FILES_RECURSIVE("include/${INSTALL_PATH_PREFIX}" HEADERS)
-- 
1.7.11.4

