From 549365c02b622460da6e6251b6c3064c1ea4dc0a Mon Sep 17 00:00:00 2001
From: Marina Ganeva <m.ganeva@fz-juelich.de>
Date: Tue, 2 Sep 2014 13:10:18 +0200
Subject: [PATCH] Option CREATE_BUNDLE created. Minor refactoring.

---
 CMakeLists.txt                             |  1 +
 GUI/coregui/CMakeLists.txt                 |  4 +-
 GUI/main/CMakeLists.txt                    | 29 ++++--------
 cmake/CMakeLists.txt                       |  2 +-
 cmake/modules/BornAgainConfiguration.cmake |  4 +-
 cmake/modules/DarwinSetup.cmake            | 55 +---------------------
 6 files changed, 15 insertions(+), 80 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 473397acd9e..d8d6f46942b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,6 +17,7 @@ option(BORNAGAIN_APP "Build test application" OFF)
 option(BORNAGAIN_GUI "Build a graphical user interface" OFF)
 option(BORNAGAIN_MAN "Build a user manual" OFF)
 option(BUILD_DEBIAN "Build a debian package" OFF)
+option(CREATE_BUNDLE "Create a Mac OS X bundle" ON)
 option(ROOT_SUPPORT "Build with dependencies from ROOT" ON)
 option(BORNAGAIN_OPENMPI "Build with OpenMPI support" OFF)
 option(BORNAGAIN_RELEASE "Special option for making release" OFF)
diff --git a/GUI/coregui/CMakeLists.txt b/GUI/coregui/CMakeLists.txt
index f3bee2ab9af..6b926a36d6f 100644
--- a/GUI/coregui/CMakeLists.txt
+++ b/GUI/coregui/CMakeLists.txt
@@ -130,9 +130,9 @@ target_link_libraries(${library_name}
 
 # --- Installation ---
 install (TARGETS ${library_name} DESTINATION ${destination_lib} COMPONENT Libraries)
-if(APPLE)
+if(APPLE AND CREATE_BUNDLE)
   set(source_files ${source_files} ${CMAKE_SOURCE_DIR}/Images/BAicon.icns)
-endif(APPLE)
+endif(APPLE AND CREATE_BUNDLE)
 # system libraries: ROOT installation
 if(WIN32)
 #     install(FILES 
diff --git a/GUI/main/CMakeLists.txt b/GUI/main/CMakeLists.txt
index 806894b084e..fde4b003552 100644
--- a/GUI/main/CMakeLists.txt
+++ b/GUI/main/CMakeLists.txt
@@ -17,7 +17,7 @@ include_directories(
     ${GSL_INCLUDE_DIR}
 )
 
-if(APPLE)
+if(APPLE AND CREATE_BUNDLE)
   add_executable(${executable_name} MACOSX_BUNDLE main.cpp)
   get_filename_component(PYTHON_REAL_LIBRARY "${PYTHON_LIBRARY}" REALPATH)
   add_library(Python SHARED IMPORTED)
@@ -47,7 +47,7 @@ else()
     ${BornAgainFit_LIBRARY}
     ${BornAgainGUI_LIBRARY}
   )
-endif(APPLE)
+endif(APPLE AND CREATE_BUNDLE)
 
 #target_link_libraries(${executable_name}
 #    ${ManhattanStyle_LIBRARY}
@@ -61,12 +61,12 @@ endif(APPLE)
 #)
 
 # --- Installation ---
-IF(APPLE)
-  set(plugin_dest_dir ${INBUNDLE}/Contents/MacOS/plugins)
+IF(APPLE AND CREATE_BUNDLE)
+  set(plugin_dest_dir ${INBUNDLE}/Contents/PlugIns)
   set(qtconf_dest_dir ${INBUNDLE}/Contents/Resources)
   set(APPS "\${CMAKE_INSTALL_PREFIX}/${INBUNDLE}")
 
-  message("PYTHON_LIBRARY: ${PYTHON_LIBRARY}")
+#  message("PYTHON_LIBRARY: ${PYTHON_LIBRARY}")
 
   get_filename_component(ManhattanStyle_LIBRARY_DIR "${ManhattanStyle_LIBRARY}" REALPATH)
   get_filename_component(qcustomplot_LIBRARY_DIR "${qcustomplot_LIBRARY}" REALPATH)
@@ -74,20 +74,7 @@ IF(APPLE)
   get_filename_component(Boost_Real_LIBRARY_DIR "${Boost_LIBRARY_DIR}" REALPATH)
   get_filename_component(PYTHON_LIBRARY_DIR "${PYTHON_REAL_LIBRARY}" PATH)
 
-  message("PYTHON_LIBRARY_DIR: ${PYTHON_LIBRARY_DIR}")
-
-#  set(DEPLIBS
-#    ${ManhattanStyle_LIBRARY}
-#    ${qcustomplot_LIBRARY}
-#    ${qtpropertybrowser_LIBRARY}
-#    ${PYTHON_LIBRARY}
-#    ${PYTHON_REAL_LIBRARY}
-#    ${Boost_LIBRARIES}
-#    ${BornAgainCore_LIBRARY}
-#    ${BornAgainFit_LIBRARY}
-#    ${BornAgainGUI_LIBRARY}
-#  )
-
+#  message("PYTHON_LIBRARY_DIR: ${PYTHON_LIBRARY_DIR}")
 
   set(DIRS
     ${ManhattanStyle_LIBRARY_DIR}
@@ -108,7 +95,7 @@ IF(APPLE)
 
   set(qtconf_text "
 [Paths]
-Plugins = MacOS/plugins
+Plugins = PlugIns
   ")
 
   install(CODE "
@@ -126,5 +113,5 @@ Plugins = MacOS/plugins
 
 else()
   install (TARGETS ${executable_name} DESTINATION ${destination_bin} COMPONENT Applications)
-endif(APPLE)
+endif(APPLE AND CREATE_BUNDLE)
 
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index e7ec1e54210..6b74f93a9e1 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -1,6 +1,6 @@
 # this script is a trick to print the message at the end of installation
 
-if(NOT WIN32)
+if(NOT WIN32 AND NOT CREATE_BUNDLE)
 set(after_install_text "
 Installation done. Please read below.
 -------------------------------------------------------------------------------
diff --git a/cmake/modules/BornAgainConfiguration.cmake b/cmake/modules/BornAgainConfiguration.cmake
index 604e364dca9..420e51188ac 100644
--- a/cmake/modules/BornAgainConfiguration.cmake
+++ b/cmake/modules/BornAgainConfiguration.cmake
@@ -63,6 +63,6 @@ if(NOT WIN32)
             DESTINATION bin)
 endif()
 
-if(APPLE)
+if(APPLE AND CREATE_BUNDLE)
   include(DarwinSetup)
-endif(APPLE)
+endif(APPLE AND CREATE_BUNDLE)
diff --git a/cmake/modules/DarwinSetup.cmake b/cmake/modules/DarwinSetup.cmake
index 2c21664fae7..6a3d81541c8 100644
--- a/cmake/modules/DarwinSetup.cmake
+++ b/cmake/modules/DarwinSetup.cmake
@@ -8,58 +8,9 @@ set ( INBUNDLE BornAgain.app )
 
 set(destination_bin ${INBUNDLE}/Contents/MacOs)
 set(destination_lib ${INBUNDLE}/Contents/MacOs)
-set(destination_include ${INBUNDLE}/Contents/Resources/include)
+set(destination_include ${INBUNDLE}/Contents/Resources/Headers)
 set(destination_examples ${INBUNDLE}/Contents/SharedSupport/Examples)
 
-#set ( BIN_DIR ${INBUNDLE}/Contents/MacOS )
-#set ( LIB_DIR ${INBUNDLE}/Contents/MacOS )
-#set ( PLUGINS_DIR ${INBUNDLE}/Contents/PlugIns )
-#set ( PVPLUGINS_DIR MantidPlot.app/pvplugins )
-
-#if (OSX_VERSION VERSION_LESS 10.9)
-# set ( PYQT4_PYTHONPATH /Library/Python/${PY_VER}/site-packages/PyQt4 )
-# set ( SITEPACKAGES /Library/Python/${PY_VER}/site-packages )
-#else()
-# # Assume we are using homebrew for now
-# set ( PYQT4_PYTHONPATH /usr/local/lib/python${PY_VER}/site-packages/PyQt4 )
-# set ( SITEPACKAGES /usr/local/lib/python${PY_VER}/site-packages )
-#endif()
-
-# Python packages
-
-#install ( PROGRAMS ${SITEPACKAGES}/sip.so DESTINATION ${BIN_DIR} )
-
-# Explicitly specify which PyQt libraries we want because just taking the whole
-# directory will swell the install kit unnecessarily.
-#install ( FILES ${PYQT4_PYTHONPATH}/Qt.so
-#                ${PYQT4_PYTHONPATH}/QtCore.so
-#                ${PYQT4_PYTHONPATH}/QtGui.so
-#                ${PYQT4_PYTHONPATH}/QtOpenGL.so
-#                ${PYQT4_PYTHONPATH}/QtSql.so
-#                ${PYQT4_PYTHONPATH}/QtSvg.so
-#                ${PYQT4_PYTHONPATH}/QtXml.so
-#                ${PYQT4_PYTHONPATH}/__init__.py
-#          DESTINATION ${BIN_DIR}/PyQt4 )
-# Newer PyQt versions have a new internal library that we need to take
-#if ( EXISTS ${PYQT4_PYTHONPATH}/_qt.so )
-#  install ( FILES ${PYQT4_PYTHONPATH}/_qt.so
-#            DESTINATION ${BIN_DIR}/PyQt4 )
-#endif ()
-
-#install ( DIRECTORY ${PYQT4_PYTHONPATH}/uic DESTINATION ${BIN_DIR}/PyQt4 )
-
-# Python packages in Third_Party need copying to build directory and the final package
-#file ( GLOB THIRDPARTY_PYTHON_PACKAGES ${CMAKE_LIBRARY_PATH}/Python/* )
-#foreach ( PYPACKAGE ${THIRDPARTY_PYTHON_PACKAGES} )
-#  if ( IS_DIRECTORY ${PYPACKAGE} )
-#    install ( DIRECTORY ${PYPACKAGE} DESTINATION ${BIN_DIR} )
-#  endif()
-#  file ( COPY ${PYPACKAGE} DESTINATION ${PROJECT_BINARY_DIR}/bin )
-#endforeach( PYPACKAGE )
-
-#install ( DIRECTORY ${QT_PLUGINS_DIR}/imageformats DESTINATION ${INBUNDLE}/Contents/Frameworks/plugins )
-#install ( DIRECTORY ${QT_PLUGINS_DIR}/sqldrivers DESTINATION ${INBUNDLE}/Contents/Frameworks/plugins )
-
 install ( FILES ${CMAKE_SOURCE_DIR}/Images/BAicon.icns
           DESTINATION ${INBUNDLE}/Contents/Resources/
 )
@@ -68,7 +19,3 @@ install ( FILES ${CMAKE_SOURCE_DIR}/Images/BAicon.icns
 #set ( CPACK_DMG_DS_STORE ${CMAKE_SOURCE_DIR}/Installers/MacInstaller/osx_DS_Store)
 set ( MACOSX_BUNDLE_ICON_FILE BAicon.icns )
 SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/Images/BAicon.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
-
-#string (REPLACE " " "" CPACK_SYSTEM_NAME ${OSX_CODENAME})
-
-#set ( CPACK_GENERATOR DragNDrop )
-- 
GitLab