From ba696b74c768e79bae3796910912299200348ce6 Mon Sep 17 00:00:00 2001
From: Andreas Schenk <andreas_schenk@hms.harvard.edu>
Date: Thu, 13 Sep 2012 12:29:50 -0400
Subject: [PATCH] cleaned up CMakeLists.txt structure in deployment folders
 added skeleton for Linux deployment with CPack

---
 CMakeLists.txt                       |   1 -
 cmake_support/CheckLSBTypes.cmake    |  70 ++++++++++
 cmake_support/CopyDependencies.cmake | 197 +++++++++++++++++++++++++--
 cmake_support/Deployment.cmake       |  77 -----------
 deployment/CMakeLists.txt            |  40 ++++--
 deployment/linux/CMakeLists.txt      |  42 ++++++
 deployment/macos/CMakeLists.txt      |  41 ++++++
 deployment/macos/Info.plist          |  35 -----
 deployment/win/CMakeLists.txt        |  24 ++--
 9 files changed, 380 insertions(+), 147 deletions(-)
 create mode 100644 cmake_support/CheckLSBTypes.cmake
 delete mode 100644 cmake_support/Deployment.cmake
 create mode 100644 deployment/linux/CMakeLists.txt
 create mode 100644 deployment/macos/CMakeLists.txt
 delete mode 100644 deployment/macos/Info.plist

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 69a37ae1b..a6a8f7174 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,7 +46,6 @@ option(USE_DOUBLE_PRECISION "whether to compile in double precision"
 option(ENABLE_SPNAV "whether 3DConnexion devices should be supported"
       OFF)
 option(STATIC_PROPERTY_WORKAROUND "workaround for static property bug with some boost/boost_python combinations" OFF)
-option(DEPLOYMENT "switch on deployment settings" OFF)
 option(COMPILE_TESTS "whether unit tests should be compiled by default" OFF)
 option(ENABLE_STATIC "whether static libraries should be compiled" OFF)
 option(DEBIAN_STYLE_LIBEXEC "whether 'libexec' should be put under 'lib/openstructure" OFF)
diff --git a/cmake_support/CheckLSBTypes.cmake b/cmake_support/CheckLSBTypes.cmake
new file mode 100644
index 000000000..93857bfa4
--- /dev/null
+++ b/cmake_support/CheckLSBTypes.cmake
@@ -0,0 +1,70 @@
+# - If included, system dependent information types like lsb_release name, architecture type
+#   and some other useful information stored for global CMAKE use
+#
+#   !!! The content of these variables should not be used in cross compilation projects !!!
+#
+# Copyright (C) 2011 by Michael Goetting  <mgoettin at techfak dot uni-bielefeld dot de>
+#
+# This file may be licensed under the terms of the
+# GNU Lesser General Public License Version 3 (the ``LGPL''),
+# or (at your option) any later version.
+#
+# Software distributed under the License is distributed
+# on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
+# express or implied. See the LGPL for the specific language
+# governing rights and limitations.
+#
+# You should have received a copy of the LGPL along with this
+# program. If not, go to http://www.gnu.org/licenses/lgpl.html
+# or write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# The development of this software was supported by:
+#   CoR-Lab, Research Institute for Cognition and Robotics
+#     Bielefeld University
+
+SET(LSB_DISTRIBUTOR_ID "unkown")
+SET(LSB_RELEASE "unkown")
+SET(LSB_CODENAME "unkown")
+SET(LSB_BIT_TYPE "unkown")
+SET(LSB_ARCH_TYPE "unkown")
+
+# ---- (mgoettin 10/17/2011) TODO: Update this to match all OS ----
+SET(LSB_PROCESSOR_ARCH ${CMAKE_SYSTEM_PROCESSOR})
+
+# ---- Get the system bit type ----
+IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
+  SET(LSB_BIT_TYPE 64)
+ELSE()
+  SET(LSB_BIT_TYPE 32)    
+ENDIF() 
+
+# ---- Get the system LSB data ----
+IF(UNIX)
+  
+    FIND_PROGRAM(LSB_RELEASE_EXECUTABLE lsb_release)
+    IF(LSB_RELEASE_EXECUTABLE)
+        # ---- Get the distribution codename ----
+        EXECUTE_PROCESS(COMMAND ${LSB_RELEASE_EXECUTABLE} -s -c
+          OUTPUT_VARIABLE TMP_LSB_CODENAME
+          OUTPUT_STRIP_TRAILING_WHITESPACE)
+        STRING(TOLOWER ${TMP_LSB_CODENAME} LSB_CODENAME)
+        # ---- Get the release name ----
+        EXECUTE_PROCESS(COMMAND ${LSB_RELEASE_EXECUTABLE} -s -r
+          OUTPUT_VARIABLE TMP_LSB_RELEASE
+          OUTPUT_STRIP_TRAILING_WHITESPACE)
+        STRING(TOLOWER ${TMP_LSB_RELEASE} LSB_RELEASE)
+        # ---- Get the distributor id ----
+        EXECUTE_PROCESS(COMMAND ${LSB_RELEASE_EXECUTABLE} -s -i
+          OUTPUT_VARIABLE TMP_LSB_DISTRIBUTOR_ID
+          OUTPUT_STRIP_TRAILING_WHITESPACE)
+        STRING(TOLOWER ${TMP_LSB_DISTRIBUTOR_ID} LSB_DISTRIBUTOR_ID)
+        
+        MESSAGE(STATUS "LSB-Release system information::
+           LSB Distributor-ID: ${LSB_DISTRIBUTOR_ID}
+           LSB Release: ${LSB_RELEASE}
+           LSB Codename: ${LSB_CODENAME}
+           System bit type: ${LSB_BIT_TYPE} bit")
+       
+    ENDIF(LSB_RELEASE_EXECUTABLE) 
+ENDIF(UNIX)
diff --git a/cmake_support/CopyDependencies.cmake b/cmake_support/CopyDependencies.cmake
index 1f522a2ec..28422d45e 100644
--- a/cmake_support/CopyDependencies.cmake
+++ b/cmake_support/CopyDependencies.cmake
@@ -119,7 +119,7 @@ function(collect_dependencies binaries keys_var)
   # Get dependencies and add them to the keys.
   foreach(exe ${binaries})
     get_filename_component(exepath "${exe}" PATH)
-    add_dependencies_for_item(${keys_var}  "${exe}" "${exe}" "${exepath}")
+    add_dependencies_for_item(${keys_var}  "${exe}" "${exepath}")
   endforeach(exe)
 
   # Propagate values to caller's scope:
@@ -301,29 +301,64 @@ endfunction(copy_resolved_item)
 
 
 #=============================================================================
-# function get_rpath
+# macro get_rpath
 #=============================================================================
-function(get_rpath target rpath_var)
+macro(get_rpath target rpath_var)
   if(APPLE)
-    set(rpath_cmd "otool")
-    set(rpath_cmd_args "-l")
-    set(rpath_cmd_regex ".*LC_RPATH\n *cmdsize [0-9]*\n\ *path ([^\n ]*) \\(offset.*")
-  else(APPLE)
+    get_rpath_apple(${target} ${rpath_var})
+  elseif(WIN32)
     MESSAGE( FATAL_ERROR rpath extraction not implemented for non APPLE platform)
+  elseif(UNIX)
+    get_rpath_linux(${target} ${rpath_var})
   endif(APPLE)
-  execute_process(
-    COMMAND ${rpath_cmd} ${rpath_cmd_args} ${target}
+endmacro(get_rpath)
+
+#=============================================================================
+# function get_rpath_apple
+#=============================================================================
+function(get_rpath_apple target rpath_var)
+  find_program(rpath_exe "otool" PATHS "/usr/local/bin" "/usr/bin")
+  if(NOT rpath_exe)
+    message(FATAL_ERROR "Could not find otool - cannot resolve rpath.")
+  endif(NOT rpath_exe)
+ execute_process(
+    COMMAND ${rpath_exe} "-l" ${target}
     OUTPUT_VARIABLE rpath_cmd_ov
     RESULT_VARIABLE retcode
   )
   if(retcode)
     MESSAGE(FATAL_ERROR "otool stopped with return code: '${retcode}'")
   endif(retcode)
+  set(rpath_cmd_regex ".*LC_RPATH\n *cmdsize [0-9]*\n\ *path ([^\n ]*) \\(offset.*")
   if(rpath_cmd_ov MATCHES ${rpath_cmd_regex})
     string(REGEX REPLACE ${rpath_cmd_regex} "\\1"  rpath ${rpath_cmd_ov})
     set(${rpath_var} ${rpath} PARENT_SCOPE)
   endif(rpath_cmd_ov MATCHES ${rpath_cmd_regex})
-endfunction(get_rpath)
+endfunction(get_rpath_apple)
+
+#=============================================================================
+# function get_rpath_linux
+#=============================================================================
+function(get_rpath_linux target rpath_var)
+  find_program(rpath_exe "readelf" PATHS "/usr/local/bin" "/usr/bin")
+  if(NOT rpath_exe)
+    message(FATAL_ERROR "Could not find readelf - cannot resolve rpath.")
+  endif(NOT rpath_exe)
+ execute_process(
+    COMMAND ${rpath_exe} "-d" ${target}
+    OUTPUT_VARIABLE rpath_cmd_ov
+    RESULT_VARIABLE retcode
+  )
+  if(retcode)
+    MESSAGE(FATAL_ERROR "readelf stopped with return code: '${retcode}'")
+  endif(retcode)
+  
+  set(rpath_cmd_regex "Library rpath: \[([^\n ]*):\]")
+  if(rpath_cmd_ov MATCHES ${rpath_cmd_regex})
+    string(REGEX REPLACE ${rpath_cmd_regex} "\\1"  rpath ${rpath_cmd_ov})
+    set(${rpath_var} ${rpath} PARENT_SCOPE)
+  endif(rpath_cmd_ov MATCHES ${rpath_cmd_regex})
+endfunction(get_rpath_linux)
 
 
 #=============================================================================
@@ -418,7 +453,6 @@ function(get_dependencies_for_item_apple  item list_var)
   find_program(otool_cmd "otool" PATHS "/usr/local/bin" "/usr/bin")
   if(NOT otool_cmd)
     message(FATAL_ERROR "Could not find otool - cannot analyze dependencies.")
-    return()
   endif(NOT otool_cmd)
 
   execute_process( COMMAND ${otool_cmd} -L ${item} OUTPUT_VARIABLE otool_cmd_ov RESULT_VARIABLE retcode )
@@ -532,14 +566,14 @@ endfunction(get_dependencies_for_item_win)
 #=============================================================================
 # function add_dependencies_for_item
 #=============================================================================
-function(add_dependencies_for_item keys_var context item exepath)
+function(add_dependencies_for_item keys_var  item exepath)
   if(NOT IS_ABSOLUTE "${item}" AND EXISTS "${item}")
     message(FATAL_ERROR "Item '${item}' does not exist.")
   endif(NOT IS_ABSOLUTE "${item}" AND EXISTS "${item}")
 
   get_dependencies_for_item(${item} dependencies)
   foreach(dep ${dependencies})
-    resolve_item("${context}" "${dep}" "${exepath}" resolved_dep)
+    resolve_item("${item}" "${dep}" "${exepath}" resolved_dep)
     get_item_key("${resolved_dep}" dep_key)
     list(FIND ${keys_var} ${dep_key} dep_found)
     if(dep_found EQUAL -1)
@@ -550,7 +584,7 @@ function(add_dependencies_for_item keys_var context item exepath)
         set_keys_for_item(${keys_var} ${item} ${resolved_dep} 0 1)
       else(${system_flag})
         set_keys_for_item(${keys_var} ${item} ${resolved_dep} 1   0)
-        add_dependencies_for_item(${keys_var} ${item} ${resolved_dep} ${exepath})
+        add_dependencies_for_item(${keys_var} ${resolved_dep} ${exepath})
       endif(${system_flag})
     endif(dep_found EQUAL -1)
   endforeach(dep ${dependencies})
@@ -617,3 +651,138 @@ function(append_unique list_var value)
     set(${list_var} ${${list_var}} "${value}" PARENT_SCOPE)
   endif(NOT contains)
 endfunction(append_unique)
+
+#=============================================================================
+# function copy_qt
+#=============================================================================
+function(copy_qt library_dir plugin_dir plugins)
+  file(COPY "${library_dir}/Resources/qt_menu.nib"
+       DESTINATION "${CMAKE_INSTALL_PREFIX}/libexec/openstructure/"
+       FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
+  file(COPY ${plugin_dir}
+       DESTINATION ${CMAKE_INSTALL_PREFIX}/libexec/openstructure) 
+  file(GLOB_RECURSE QT_PLUGINS "${CMAKE_INSTALL_PREFIX}/libexec/openstructure/*.dylib")
+  set(${plugins} ${QT_PLUGINS} PARENT_SCOPE)
+  file(WRITE "${CMAKE_INSTALL_PREFIX}/libexec/openstructure/qt.conf" "[Paths]\nPlugins=../plugins\n")
+endfunction(copy_qt)
+
+#=============================================================================
+# function copy_python
+#=============================================================================
+function(copy_python include_path version new_binary_path)
+
+
+  get_filename_component(real_python_include_path ${include_path} REALPATH)
+  get_filename_component(python_root_dir ${real_python_include_path}/../.. REALPATH) 
+    if ("${CMAKE_NATIVE_ARCH}" MATCHES "64")
+      file(COPY ${python_root_dir}/lib64/python${version}/ DESTINATION ${CMAKE_INSTALL_PREFIX}/lib64/python${version})
+    else()
+      file(COPY ${python_root_dir}/lib/python${version}/ DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/python${version})
+    endif()
+  file(COPY ${include_path}/pyconfig.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/python${version})
+ 
+  read_config(ost_config)
+  if(APPLE)
+    file(COPY ${python_root_dir}/Resources/Python.app/Contents/MacOS/Python DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
+    set(${new_binary_path} "${CMAKE_INSTALL_PREFIX}/bin/Python" PARENT_SCOPE)
+    string(REGEX REPLACE "pyexec=\"[^\n\$]*\"" "pyexec=\"\$DNG_BINDIR/Python\"" ost_config "${ost_config}")
+  elseif(APPLE)
+    file(COPY ${python_root_dir}/bin/python${version} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
+    set(${new_binary_path} "${CMAKE_INSTALL_PREFIX}/bin/python${version}" PARENT_SCOPE)
+    string(REGEX REPLACE "pyexec=\"[^\n\$]*\"" "pyexec=\"\$DNG_BINDIR/python${version}\"" ost_config "${ost_config}")
+  endif(APPLE)
+  write_config("${ost_config}")
+endfunction(copy_python)
+
+#=============================================================================
+# function read_config
+#=============================================================================
+function(read_config ost_config_var)
+  file(READ "${CMAKE_INSTALL_PREFIX}/libexec/openstructure/ost_config" ost_config)
+  set(${ost_config_var} "${ost_config}" PARENT_SCOPE)
+endfunction(read_config)
+
+#=============================================================================
+# function write_config
+#=============================================================================
+function(write_config ost_config)
+  file(WRITE "${CMAKE_INSTALL_PREFIX}/libexec/openstructure/ost_config" "${ost_config}")
+endfunction(write_config)
+
+#=============================================================================
+# function write_bundle_binary
+#=============================================================================
+function(write_bundle_binary binary_name real_binary)
+  file(WRITE "${CMAKE_INSTALL_PREFIX}/../MacOS/${binary_name}" "#!/bin/sh\nexec \"\${0%/*}/${real_binary}\"\n")
+  execute_process(COMMAND chmod ugo+x "${CMAKE_INSTALL_PREFIX}/../MacOS/${binary_name}")
+endfunction(write_bundle_binary)
+
+#=============================================================================
+# function add_linked_bundle
+#=============================================================================
+function(add_linked_bundle parent_bundle_name bundle_name binary_name bundle_identifier bundle_icon)
+  get_filename_component(dmg_main_path ${CMAKE_INSTALL_PREFIX}/../../../../ PATH)
+  file(MAKE_DIRECTORY "${dmg_main_path}/${bundle_name}.app/Contents/MacOS/")
+  file(MAKE_DIRECTORY "${dmg_main_path}/${bundle_name}.app/Contents/Resources/")
+  file(WRITE "${dmg_main_path}/${bundle_name}.app/Contents/MacOS/${binary_name}" "#!/bin/sh\nexec \"\${0%/*}/../../../${parent_bundle_name}.app/Contents/Resources/bin/${binary_name}\"\n")
+  get_filename_component(icon_name ${bundle_icon} NAME)
+  file(COPY ${bundle_icon} DESTINATION "${dmg_main_path}/${bundle_name}.app/Contents/Resources")
+  create_plist(${binary_name} ${bundle_name} ${bundle_identifier} ${icon_name} "${dmg_main_path}/${bundle_name}.app/Contents/Info.plist")
+  execute_process(COMMAND chmod ugo+x "${dmg_main_path}/${bundle_name}.app/Contents/MacOS/${binary_name}")
+endfunction(add_linked_bundle)
+
+#=============================================================================
+# function create_plist
+#=============================================================================
+function(create_plist BUNDLE_EXECUTABLE BUNDLE_NAME BUNDLE_IDENTIFIER BUNDLE_ICON FILENAME)
+  set( info_plist "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
+<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" 
+    \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
+<plist version=\"1.0\">
+<dict>
+  <key>CFBundleDevelopmentRegion</key>
+  <string>English</string>
+  <key>CFBundleExecutable</key>
+  <string>\@BUNDLE_EXECUTABLE\@</string>
+  <key>CFBundleName</key>
+  <string>\@BUNDLE_NAME\@</string>  
+  <key>CFBundleDisplayName</key>
+  <string>\@BUNDLE_NAME\@</string>  
+  <key>CFBundleHelpBookFolder</key>
+  <string>\@BUNDLE_NAME\@ Manual</string>
+  <key>CFBundleHelpBookName</key>
+  <string>OpenStructure Help</string>
+  <key>CFBundleIconFile</key>
+  <string>\@BUNDLE_ICON\@</string>
+  <key>CFBundleIdentifier</key>
+  <string>\@BUNDLE_IDENTIFIER\@</string>
+  <key>CFBundleInfoDictionaryVersion</key>
+  <string>6.0</string>
+  <key>CFBundlePackageType</key>
+  <string>APPL</string>
+  <key>CFBundleSignature</key>
+  <string>????</string>
+  <key>CFBundleVersion</key>
+  <string></string>
+  <key>NSMainNibFile</key>
+  <string>MainMenu</string>
+  <key>NSPrincipalClass</key>
+  <string>NSApplication</string>
+</dict>
+</plist>")
+  string(CONFIGURE "${info_plist}" info_plist_replaced)
+  file(WRITE  ${FILENAME} "${info_plist_replaced}")
+endfunction(create_plist)
+
+#=============================================================================
+# function echo_all_cmake_variable_values
+#=============================================================================
+
+function(echo_all_cmake_variable_values)
+  message("")
+  get_cmake_property(vs VARIABLES)
+  foreach(v ${vs})
+    message("${v}='${${v}}'")
+  endforeach(v)
+  message("")
+endfunction()
\ No newline at end of file
diff --git a/cmake_support/Deployment.cmake b/cmake_support/Deployment.cmake
deleted file mode 100644
index 2c4a6f5ce..000000000
--- a/cmake_support/Deployment.cmake
+++ /dev/null
@@ -1,77 +0,0 @@
-#-------------------------------------------------------------------------------
-#  Author:  Andreas Schenk
-#
-#  This file contains the configuration for the bundle/installer creation
-#  with CPack.
-#
-#-------------------------------------------------------------------------------
-
-
-INCLUDE(InstallRequiredSystemLibraries)
-
-set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OpenStructure Framework")
-set(CPACK_PACKAGE_VENDOR "2008-2010 -- The OpenStructure Team")
-set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/ReadMe.txt")
-set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE.txt")
-set(CPACK_PACKAGE_VERSION_MAJOR ${OST_VERSION_MAJOR})
-set(CPACK_PACKAGE_VERSION_MINOR ${OST_VERSION_MINOR})
-set(CPACK_PACKAGE_VERSION_PATCH ${OST_VERSION_PATCH})
-if(APPLE)
-  set(CPACK_GENERATOR Bundle)
-  set(CPACK_BUNDLE_NAME DNG)
-  set(CPACK_BUNDLE_PLIST ${PROJECT_SOURCE_DIR}/deployment/macos/Info.plist)
-  set (CPACK_PACKAGE_ICON ${PROJECT_SOURCE_DIR}/graphics/icon.icns)
-  set (CPACK_BUNDLE_ICON ${PROJECT_SOURCE_DIR}/graphics/icon.icns)
-  install(CODE "if(NOT ${CMAKE_INSTALL_PREFIX} STREQUAL \${CMAKE_INSTALL_PREFIX})
-                  #read ost_config to apply modifications
-                  file(READ \"\${CMAKE_INSTALL_PREFIX}/libexec/openstructure/ost_config\" ost_config)
-                  
-                  set(OST_BINARIES \"\${CMAKE_INSTALL_PREFIX}/bin/lddt\"
-                                   \"\${CMAKE_INSTALL_PREFIX}/bin/chemdict_tool\"
-                                   \"\${CMAKE_INSTALL_PREFIX}/libexec/openstructure/gosty\")
-                  
-                  #copy python into bundle if a version different from the system version is used
-                  if(NOT ${PYTHON_BINARY} MATCHES /usr/bin/)
-                    get_filename_component(real_python_include_path ${PYTHON_INCLUDE_PATH} REALPATH)
-                    get_filename_component(python_root_dir \${real_python_include_path}/../.. REALPATH) 
-                    file(COPY \${python_root_dir}/${LIB_DIR}/python${PYTHON_VERSION}/
-                         DESTINATION \${CMAKE_INSTALL_PREFIX}/${LIB_DIR}/python${PYTHON_VERSION})
-                    file(COPY \${python_root_dir}/Resources/Python.app/Contents/MacOS/Python
-                         DESTINATION \${CMAKE_INSTALL_PREFIX}/bin)
-                    file(COPY ${PYTHON_INCLUDE_PATH}/pyconfig.h
-                         DESTINATION \${CMAKE_INSTALL_PREFIX}/include/python${PYTHON_VERSION})
-
-                    list(APPEND OST_BINARIES \"\${CMAKE_INSTALL_PREFIX}/bin/Python\")
-                    string(REGEX REPLACE \"pyexec=\\\"[^\n\$]*\\\"\"
-                                         \"pyexec=\$DNG_BINDIR/Python\"
-                                         ost_config \"\${ost_config}\")
-                  endif(NOT ${PYTHON_BINARY} MATCHES /usr/bin/)  
-  
-                  file(GLOB_RECURSE OST_PYMODS \"\${CMAKE_INSTALL_PREFIX}/${LIB_DIR}/*.so\")
-                  list(APPEND  OST_BINARIES \${OST_PYMODS})
-                  
-                  #copy Qt stuff
-                  file(COPY \"${QT_LIBRARY_DIR}/Resources/qt_menu.nib\"
-                       DESTINATION \"\${CMAKE_INSTALL_PREFIX}/libexec/openstructure/\"
-                       FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
-                  file(COPY ${QT_PLUGINS_DIR}
-                       DESTINATION \${CMAKE_INSTALL_PREFIX}/libexec/openstructure) 
-                  file(GLOB_RECURSE QT_PLUGINS \"\${CMAKE_INSTALL_PREFIX}/libexec/openstructure/*.dylib\")
-                  list(APPEND  OST_BINARIES \${QT_PLUGINS})
-                  file(WRITE \"\${CMAKE_INSTALL_PREFIX}/libexec/openstructure/qt.conf\" \"[Paths]\nPlugins=../plugins\n\")
-
-                  file(WRITE \"\${CMAKE_INSTALL_PREFIX}/../MacOS/dng\" \"#!/bin/sh\nexec \\\"\\\${0%/*}/../Resources/bin/dng\\\"\n\")
-                  execute_process(COMMAND chmod ugo+x \"\${CMAKE_INSTALL_PREFIX}/../MacOS/dng\")
-                  file(WRITE \"\${CMAKE_INSTALL_PREFIX}/libexec/openstructure/ost_config\" \"\${ost_config}\")
-  
-                  set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake_support)
-                  include(CopyDependencies)
-                  copy_dependencies(\"\${OST_BINARIES}\") 
-                 endif(NOT ${CMAKE_INSTALL_PREFIX} STREQUAL \${CMAKE_INSTALL_PREFIX})")
-  set(CPACK_PACKAGE_INSTALL_DIRECTORY "openstructure ${OST_VERSION_STRING}" )
-endif(APPLE)
-
-
-if(${PROJECT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
-  INCLUDE(CPack) #only include CPack for the main project and not for subprojects
-endif(${PROJECT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
diff --git a/deployment/CMakeLists.txt b/deployment/CMakeLists.txt
index 1a5558547..19d084aec 100644
--- a/deployment/CMakeLists.txt
+++ b/deployment/CMakeLists.txt
@@ -1,8 +1,32 @@
-# todo implement get_ost_rev for git
-#get_ost_rev()
-include(Deployment)
-set(SUBST_DIC OST_VERSION="${OST_VERSION}")
-add_custom_target(deploymnt ALL)
-substitute(IN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.html.in OUT_FILE README.html 
-               DICT ${SUBST_DIC})
-add_subdirectory(win)
+#-------------------------------------------------------------------------------
+#  Author:  Andreas Schenk
+#
+#  This file contains the CPack configuration common to all platforms.
+#
+#-------------------------------------------------------------------------------
+
+#only include deployment configureation for the main project and not for subprojects
+if(${PROJECT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
+
+  INCLUDE(InstallRequiredSystemLibraries)
+  
+  set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OpenStructure Framework")
+  set(CPACK_PACKAGE_VENDOR "2008-2010 -- The OpenStructure Team")
+  set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/ReadMe.txt")
+  set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE.txt")
+  set(CPACK_PACKAGE_VERSION_MAJOR ${OST_VERSION_MAJOR})
+  set(CPACK_PACKAGE_VERSION_MINOR ${OST_VERSION_MINOR})
+  set(CPACK_PACKAGE_VERSION_PATCH ${OST_VERSION_PATCH})
+  
+  # using include instead of add_subdirectory avoid creating a child scope
+  if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+    include(macos/CMakeLists.txt) 
+  elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+    include(linux/CMakeLists.txt) 
+  elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
+    include(windows/CMakeLists.txt) 
+  endif()
+
+  INCLUDE(CPack) 
+
+endif(${PROJECT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
diff --git a/deployment/linux/CMakeLists.txt b/deployment/linux/CMakeLists.txt
new file mode 100644
index 000000000..cc93b5251
--- /dev/null
+++ b/deployment/linux/CMakeLists.txt
@@ -0,0 +1,42 @@
+#-------------------------------------------------------------------------------
+#  Author:  Andreas Schenk
+#
+#  This file contains the Linux specific CPack configuration.
+#
+#-------------------------------------------------------------------------------
+
+include(CheckLSBTypes)
+
+if(( ${LSB_DISTRIBUTOR_ID} MATCHES "centos" AND ${LSB_RELEASE} GREATER 5.9)
+ OR (${LSB_DISTRIBUTOR_ID} MATCHES "redhat" AND ${LSB_RELEASE} GREATER 5.9)
+ OR (${LSB_DISTRIBUTOR_ID} MATCHES "fedora"))
+  set(CPACK_GENERATOR "RPM")
+elseif(${LSB_DISTRIBUTOR_ID} MATCHES "debian")
+  set(CPACK_GENERATOR "DEB")
+  set(CPACK_DEBIAN_PACKAGE_MAINTAINER "The OpenStructure developers")
+else()
+  install(CODE "
+    if(NOT ${CMAKE_INSTALL_PREFIX} STREQUAL \${CMAKE_INSTALL_PREFIX})
+      set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/ost/cmake_support)
+      include(CopyDependencies)
+      set(OST_BINARIES \"\${CMAKE_INSTALL_PREFIX}/bin/lddt\"
+                       \"\${CMAKE_INSTALL_PREFIX}/bin/chemdict_tool\
+                       \"\${CMAKE_INSTALL_PREFIX}/bin/molck\
+                       \"\${CMAKE_INSTALL_PREFIX}/libexec/openstructure/gosty\")
+      
+      copy_python(${PYTHON_INCLUDE_PATH} ${PYTHON_VERSION} new_python_binary)
+      list(APPEND OST_BINARIES \${new_python_binary})
+
+      file(GLOB_RECURSE OST_PYMODS \"\${CMAKE_INSTALL_PREFIX}/${LIB_DIR}/*.so\")
+      list(APPEND  OST_BINARIES \${OST_PYMODS})
+      
+      #copy Qt stuff
+      copy_qt(${QT_LIBRARY_DIR} ${QT_PLUGINS_DIR} qt_plugins)
+      list(APPEND  OST_BINARIES \${qt_plugins})
+
+      copy_dependencies(\"\${OST_BINARIES}\")
+    endif(NOT ${CMAKE_INSTALL_PREFIX} STREQUAL \${CMAKE_INSTALL_PREFIX})
+  ")
+  set(CPACK_GENERATOR "TGZ")
+  #set(CPACK_INSTALL_CMAKE_PROJECTS "")
+endif()
diff --git a/deployment/macos/CMakeLists.txt b/deployment/macos/CMakeLists.txt
new file mode 100644
index 000000000..b593abfb9
--- /dev/null
+++ b/deployment/macos/CMakeLists.txt
@@ -0,0 +1,41 @@
+#-------------------------------------------------------------------------------
+#  Author:  Andreas Schenk
+#
+#  This file contains OSX specific CPack configuration.
+#
+#-------------------------------------------------------------------------------
+
+
+set(CPACK_GENERATOR Bundle)
+set(CPACK_BUNDLE_NAME DNG)
+set(CPACK_BUNDLE_PLIST ${PROJECT_SOURCE_DIR}/deployment/macos/Info.plist)
+set (CPACK_PACKAGE_ICON ${PROJECT_SOURCE_DIR}/graphics/icon.icns)
+set (CPACK_BUNDLE_ICON ${PROJECT_SOURCE_DIR}/graphics/icon.icns)
+set(CPACK_PACKAGE_INSTALL_DIRECTORY "openstructure ${OST_VERSION_STRING}" )
+install(CODE "
+  if(NOT ${CMAKE_INSTALL_PREFIX} STREQUAL \${CMAKE_INSTALL_PREFIX})
+    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake_support)
+    include(CopyDependencies)
+  
+    set(OST_BINARIES \"\${CMAKE_INSTALL_PREFIX}/bin/lddt\"
+                     \"\${CMAKE_INSTALL_PREFIX}/bin/chemdict_tool\"
+                     \"\${CMAKE_INSTALL_PREFIX}/libexec/openstructure/gosty\")
+  
+    #copy python into bundle if a version different from the system version is used
+    if(NOT ${PYTHON_BINARY} MATCHES /usr/bin/)
+      copy_python(${PYTHON_INCLUDE_PATH} ${PYTHON_VERSION} new_python_binary)
+      list(APPEND OST_BINARIES \${new_python_binary})
+    endif(NOT ${PYTHON_BINARY} MATCHES /usr/bin/)  
+  
+    file(GLOB_RECURSE OST_PYMODS \"\${CMAKE_INSTALL_PREFIX}/${LIB_DIR}/*.so\")
+    list(APPEND  OST_BINARIES \${OST_PYMODS})
+    
+    #copy Qt stuff
+    copy_qt(${QT_LIBRARY_DIR} ${QT_PLUGINS_DIR} qt_plugins)
+    list(APPEND  OST_BINARIES \${qt_plugins})
+  
+    write_bundle_binary(dng ../Resources/bin/dng)
+    copy_dependencies(\"\${OST_BINARIES}\") 
+  endif(NOT ${CMAKE_INSTALL_PREFIX} STREQUAL \${CMAKE_INSTALL_PREFIX})
+")
+
diff --git a/deployment/macos/Info.plist b/deployment/macos/Info.plist
deleted file mode 100644
index 5169acff8..000000000
--- a/deployment/macos/Info.plist
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" 
-    "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-  <key>CFBundleDevelopmentRegion</key>
-  <string>English</string>
-  <key>CFBundleExecutable</key>
-  <string>dng</string>
-  <key>CFBundleName</key>
-  <string>DNG</string>  
-  <key>CFBundleDisplayName</key>
-  <string>DNG</string>  
-  <key>CFBundleHelpBookFolder</key>
-  <string>OpenStructure Manual</string>
-  <key>CFBundleHelpBookName</key>
-  <string>OpenStructure Help</string>
-  <key>CFBundleIconFile</key>
-  <string>DNG.icns</string>
-  <key>CFBundleIdentifier</key>
-  <string>org.openstructure.OpenStructure</string>
-  <key>CFBundleInfoDictionaryVersion</key>
-  <string>6.0</string>
-  <key>CFBundlePackageType</key>
-  <string>APPL</string>
-  <key>CFBundleSignature</key>
-  <string>????</string>
-  <key>CFBundleVersion</key>
-  <string></string>
-  <key>NSMainNibFile</key>
-  <string>MainMenu</string>
-  <key>NSPrincipalClass</key>
-  <string>NSApplication</string>
-</dict>
-</plist>
diff --git a/deployment/win/CMakeLists.txt b/deployment/win/CMakeLists.txt
index 01c1a1d7a..f8b2c1c77 100644
--- a/deployment/win/CMakeLists.txt
+++ b/deployment/win/CMakeLists.txt
@@ -1,13 +1,13 @@
-if(DEPLOYMENT)
-#  get_ost_rev()
-  include(Deployment)
-  set(SUBST_DICT OST_VERSION="${OST_VERSION}")
-  add_custom_target(deployment ALL)
-
-
-
-  if(WIN32)
-    script(NAME create_archive.bat INPUT create_archive.bat.in SUBSTITUTE ${SUBST_DICT} TARGET deployment)
-  endif()
-endif()
+#-------------------------------------------------------------------------------
+#  Author:  Andreas Schenk
+#
+#  This file contains the Windows specific CPack configuration.
+#
+#-------------------------------------------------------------------------------
+
+install(CODE "
+  if(NOT ${CMAKE_INSTALL_PREFIX} STREQUAL \${CMAKE_INSTALL_PREFIX})
+    message(FATAL_ERROR "The Windows installer cannot yet be created with CPack.")            
+  endif(NOT ${CMAKE_INSTALL_PREFIX} STREQUAL \${CMAKE_INSTALL_PREFIX})
+")
 
-- 
GitLab