From 5693656daafe61d43af515c5d0def3790cee70ff Mon Sep 17 00:00:00 2001
From: Gennady Pospelov <g.pospelov@fz-juelich.de>
Date: Thu, 13 Nov 2014 16:49:52 +0100
Subject: [PATCH] CMake: refactoring in GUI's main

---
 GUI/CMakeLists.txt                            |   2 -
 GUI/coregui/CMakeLists.txt                    |   1 -
 .../qt-manhattan-style/CMakeLists.txt         |   3 +-
 GUI/main/CMakeLists.txt                       | 274 +++++++++++-------
 4 files changed, 164 insertions(+), 116 deletions(-)

diff --git a/GUI/CMakeLists.txt b/GUI/CMakeLists.txt
index 6a07b65a38b..ba6f0a7f56f 100644
--- a/GUI/CMakeLists.txt
+++ b/GUI/CMakeLists.txt
@@ -14,8 +14,6 @@ endif()
 
 message(STATUS "Configuring BornAgain GUI")
 
-#Widgets Core Gui Script Designer PrintSupport
-
 find_package(Qt5Widgets REQUIRED)
 find_package(Qt5Core REQUIRED)
 find_package(Qt5GUI REQUIRED)
diff --git a/GUI/coregui/CMakeLists.txt b/GUI/coregui/CMakeLists.txt
index 1b584bec8df..9423e8c9c76 100644
--- a/GUI/coregui/CMakeLists.txt
+++ b/GUI/coregui/CMakeLists.txt
@@ -113,7 +113,6 @@ set(${library_name}_LIBRARY ${library_name} PARENT_SCOPE)
 
 
 # --- dependencies ---------
-#qt5_use_modules(${library_name} Widgets Core Gui Script Designer PrintSupport)
 include_directories(
     ${qcustomplot_INCLUDE_DIRS}
     ${qtpropertybrowser_INCLUDE_DIRS}
diff --git a/GUI/externals/qt-manhattan-style/CMakeLists.txt b/GUI/externals/qt-manhattan-style/CMakeLists.txt
index 95bc1721660..0b87af83013 100644
--- a/GUI/externals/qt-manhattan-style/CMakeLists.txt
+++ b/GUI/externals/qt-manhattan-style/CMakeLists.txt
@@ -71,13 +71,14 @@ set(UI_FILES
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 set(CMAKE_AUTOMOC ON)
 
+qt5_wrap_ui(UI_HDRS ${UI_FILES})
 
 # --- definitions ---------
 add_definitions(-DQTMANHATTANSTYLE_LIBRARY)
 
 
 # --- library ---------
-add_library(${library_name} STATIC ${SRCS} ${UI_FILES} ${RCS})
+add_library(${library_name} STATIC ${SRCS} ${UI_HDRS} ${RCS})
 set(${library_name}_INCLUDE_DIRS ${include_dirs} PARENT_SCOPE)
 set(${library_name}_LIBRARY ${library_name} PARENT_SCOPE)
 
diff --git a/GUI/main/CMakeLists.txt b/GUI/main/CMakeLists.txt
index dc0d06a439a..1360f43559d 100644
--- a/GUI/main/CMakeLists.txt
+++ b/GUI/main/CMakeLists.txt
@@ -1,3 +1,6 @@
+############################################################################
+# CMakeLists.txt file for building BornAgain/GUI executable
+############################################################################
 cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR)
 if(POLICY CMP0020)
 cmake_policy(SET CMP0020 NEW)
@@ -8,9 +11,10 @@ endif()
 if(POLICY CMP0028)
     cmake_policy(SET CMP0028 NEW)
 endif()
-
 set(executable_name BornAgain)
 
+
+# --- source files ---------
 include_directories(
     ${BornAgainGUI_INCLUDE_DIRS}
     ${ManhattanStyle_INCLUDE_DIRS}
@@ -23,9 +27,14 @@ set(source_files
 
 set(include_files)
 
+# --- Qt configuration ---------
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+set(CMAKE_AUTOMOC ON)
+
+
 # Application icon
 if(WIN32)
-    set(RC_FILE bornagain.rc)
+    set(WIN_RC_FILE bornagain.rc)
    if ( CONSOLE )
      set ( WIN_CONSOLE )
    else ()
@@ -34,29 +43,12 @@ if(WIN32)
 endif()
 
 
-if(APPLE AND CREATE_BUNDLE)
-#  set(CMAKE_MACOSX_RPATH 0)
-  add_executable(${executable_name} MACOSX_BUNDLE ${source_files} ${include_files})
-#  get_filename_component(PYTHON_REAL_LIBRARY "${PYTHON_LIBRARY}" REALPATH)
-#  add_library(Python SHARED IMPORTED)
-#  set_property(TARGET Python PROPERTY IMPORTED_LOCATION ${PYTHON_REAL_LIBRARY})
+# --- executable ---------
+add_executable(${executable_name} ${WIN_CONSOLE} ${source_files} ${include_files} ${WIN_RC_FILE})
 
-  target_link_libraries(${executable_name}
-    ${ManhattanStyle_LIBRARY}
-    ${qcustomplot_LIBRARY}
-    ${qtpropertybrowser_LIBRARY}
-    ${PYTHON_LIBRARY}
-    ${Boost_LIBRARIES}
-    ${BornAgainCore_LIBRARY}
-    ${BornAgainFit_LIBRARY}
-    ${BornAgainGUI_LIBRARY}
-#    Python
-  )
-else()
-  add_executable(${executable_name} ${WIN_CONSOLE} ${source_files} ${include_files} ${RC_FILE})
-#  qt5_use_modules(${executable_name} Widgets Core Gui Script Designer PrintSupport)
 
-  target_link_libraries(${executable_name}
+# --- dependencies ---------
+target_link_libraries(${executable_name}
     ${ManhattanStyle_LIBRARY}
     ${qcustomplot_LIBRARY}
     ${qtpropertybrowser_LIBRARY}
@@ -65,11 +57,19 @@ else()
     ${BornAgainCore_LIBRARY}
     ${BornAgainFit_LIBRARY}
     ${BornAgainGUI_LIBRARY}
-  )
-endif(APPLE AND CREATE_BUNDLE)
+)
+
+target_link_libraries(${executable_name}
+    Qt5::Widgets
+    Qt5::Core
+    Qt5::Gui
+    Qt5::Script
+    Qt5::Designer
+    Qt5::PrintSupport
+)
 
 
-# Entry point flag for Windows to ensure we always link to standard main
+# --- extra properties ---------
 if( WIN32 )
     set_target_properties( ${executable_name} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup" )
     if ( CONSOLE )
@@ -77,7 +77,21 @@ if( WIN32 )
     endif ( CONSOLE )
 endif( WIN32 )
 
-#target_link_libraries(${executable_name}
+
+# --- installation ---------
+install (TARGETS ${executable_name} DESTINATION ${destination_bin} COMPONENT Applications)
+set(image_files ${CMAKE_SOURCE_DIR}/GUI/main/BornAgain.ico ${CMAKE_SOURCE_DIR}/GUI/main/BornAgain.icns ${CMAKE_SOURCE_DIR}/GUI/coregui/images/BornAgain_48x48.png  ${CMAKE_SOURCE_DIR}/GUI/coregui/images/BornAgain_64x64.png)
+install (FILES ${image_files} DESTINATION ${destination_images} COMPONENT Applications)
+
+
+#if(APPLE AND CREATE_BUNDLE)
+##  set(CMAKE_MACOSX_RPATH 0)
+#  add_executable(${executable_name} MACOSX_BUNDLE ${source_files} ${include_files})
+##  get_filename_component(PYTHON_REAL_LIBRARY "${PYTHON_LIBRARY}" REALPATH)
+##  add_library(Python SHARED IMPORTED)
+##  set_property(TARGET Python PROPERTY IMPORTED_LOCATION ${PYTHON_REAL_LIBRARY})
+
+#  target_link_libraries(${executable_name}
 #    ${ManhattanStyle_LIBRARY}
 #    ${qcustomplot_LIBRARY}
 #    ${qtpropertybrowser_LIBRARY}
@@ -86,90 +100,126 @@ endif( WIN32 )
 #    ${BornAgainCore_LIBRARY}
 #    ${BornAgainFit_LIBRARY}
 #    ${BornAgainGUI_LIBRARY}
-#)
-
-# --- Installation ---
-IF(APPLE AND CREATE_BUNDLE)
-
-    set(link_flags "-Wl,-rpath,@loader_path/../")
-    set_target_properties(${executable_name}
-        PROPERTIES
-#        INSTALL_RPATH "@loader_path/.."
-        LINK_FLAGS ${link_flags}
-    )
-
-#    set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
-#    set(CMAKE_INSTALL_RPATH "@loader_path/..")
-
-  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}")
+##    Python
+#  )
+#else()
+#  add_executable(${executable_name} ${WIN_CONSOLE} ${source_files} ${include_files} ${RC_FILE})
+##  qt5_use_modules(${executable_name} Widgets Core Gui Script Designer PrintSupport)
 
-  get_filename_component(ManhattanStyle_LIBRARY_DIR "${ManhattanStyle_LIBRARY}" REALPATH)
-  get_filename_component(qcustomplot_LIBRARY_DIR "${qcustomplot_LIBRARY}" REALPATH)
-  get_filename_component(qtpropertybrowser_LIBRARY_DIR "${qtpropertybrowser_LIBRARY}" REALPATH)
-  get_filename_component(Boost_Real_LIBRARY_DIR "${Boost_LIBRARY_DIR}" REALPATH)
-#  get_filename_component(PYTHON_LIBRARY_DIR "${PYTHON_LIBRARIES}" REALPATH)
-  get_filename_component(PYTHON_REAL_LIBRARY_DIR "${PYTHON_LIBRARY}" REALPATH)
-
-  message("OOO PYTHON_LIBRARY_DIR: ${PYTHON_LIBRARY_DIR}  PYTHON_LIBRARY:${PYTHON_LIBRARY}  PYTHON_LIBRARIES:${PYTHON_LIBRARIES}")
-  message("OOO2 PYTHON_REAL_LIBRARY_DIR:${PYTHON_REAL_LIBRARY_DIR}")
-  message("OOO3 CMAKE_LIBRARY_OUTPUT_DIRECTORY:${CMAKE_LIBRARY_OUTPUT_DIRECTORY} CMAKE_LIBRARY_PATH:${CMAKE_LIBRARY_PATH}")
-
-  set(DIRS
-#    ${ManhattanStyle_LIBRARY_DIR}
-#    ${qcustomplot_LIBRARY_DIR}
-#    ${qtpropertybrowser_LIBRARY_DIR}
-    ${PYTHON_REAL_LIBRARY_DIR}
-    ${Boost_Real_LIBRARY_DIR}
-    "${CMAKE_BINARY_DIR}/lib"
-    "$ENV{QTDIR}"
-    "$ENV{QTDIR}/plugins"
-  )
-
-
-  install (TARGETS ${executable_name}
-    BUNDLE DESTINATION  . COMPONENT Applications
-    RUNTIME DESTINATION ${destination_bin} COMPONENT Runtime)
-
-#    set_target_properties(${executable_name} PROPERTIES INSTALL_RPATH "@loader_path/../" MACOSX_RPATH 1)
-
-  message("WWWWWWW ${plugin_dest_dir}")
-  install(DIRECTORY "$ENV{QTDIR}/plugins/platforms" DESTINATION ${plugin_dest_dir} COMPONENT Runtime)
-
-#  set(qtconf_text "
-#[Paths]
-#Plugins = PlugIns
-#  ")
-
-#  install(CODE "
-#    file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"${qtconf_text}\")
-#    " COMPONENT Runtime)
-
-#  install(CODE "
-#    file(GLOB_RECURSE QTPLUGINS
-#      \"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
-#    set(BU_CHMOD_BUNDLE_ITEMS True)
-#    set(BU_COPY_FULL_FRAMEWORK_CONTENTS False)
-#    include(${CMAKE_MODULE_PATH}/BABundleUtilities.cmake)
-#    fixup_bundle(\"${APPS}\" \"\${QTPLUGINS}\" \"${DIRS}\")
-#    " COMPONENT Runtime)
-
-#    configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/bundle.cmake.in ${CMAKE_BINARY_DIR}/bundle.cmake @ONLY)
-#    install(SCRIPT ${CMAKE_BINARY_DIR}/bundle.cmake COMPONENT Runtime)
-
-    set(fixup_path @rpath)
-    configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/FixBundle.cmake.in ${CMAKE_BINARY_DIR}/FixBundle.cmake @ONLY)
-    install(SCRIPT ${CMAKE_BINARY_DIR}/FixBundle.cmake COMPONENT Runtime)
-
-
-else()
-  install (TARGETS ${executable_name} DESTINATION ${destination_bin} COMPONENT Applications)
-
-    set(image_files ${CMAKE_SOURCE_DIR}/GUI/main/BornAgain.ico ${CMAKE_SOURCE_DIR}/GUI/main/BornAgain.icns ${CMAKE_SOURCE_DIR}/GUI/coregui/images/BornAgain_48x48.png  ${CMAKE_SOURCE_DIR}/GUI/coregui/images/BornAgain_64x64.png)
-    install (FILES ${image_files} DESTINATION ${destination_images} COMPONENT Applications)
-
-endif(APPLE AND CREATE_BUNDLE)
+#  target_link_libraries(${executable_name}
+#    ${ManhattanStyle_LIBRARY}
+#    ${qcustomplot_LIBRARY}
+#    ${qtpropertybrowser_LIBRARY}
+#    ${PYTHON_LIBRARY}
+#    ${Boost_LIBRARIES}
+#    ${BornAgainCore_LIBRARY}
+#    ${BornAgainFit_LIBRARY}
+#    ${BornAgainGUI_LIBRARY}
+#  )
+#endif(APPLE AND CREATE_BUNDLE)
+
+
+## Entry point flag for Windows to ensure we always link to standard main
+#if( WIN32 )
+#    set_target_properties( ${executable_name} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup" )
+#    if ( CONSOLE )
+#        set_target_properties( ${executable_name} PROPERTIES COMPILE_DEFINITIONS "_CONSOLE" )
+#    endif ( CONSOLE )
+#endif( WIN32 )
+
+##target_link_libraries(${executable_name}
+##    ${ManhattanStyle_LIBRARY}
+##    ${qcustomplot_LIBRARY}
+##    ${qtpropertybrowser_LIBRARY}
+##    ${PYTHON_LIBRARY}
+##    ${Boost_LIBRARIES}
+##    ${BornAgainCore_LIBRARY}
+##    ${BornAgainFit_LIBRARY}
+##    ${BornAgainGUI_LIBRARY}
+##)
+
+## --- Installation ---
+#IF(APPLE AND CREATE_BUNDLE)
+
+#    set(link_flags "-Wl,-rpath,@loader_path/../")
+#    set_target_properties(${executable_name}
+#        PROPERTIES
+##        INSTALL_RPATH "@loader_path/.."
+#        LINK_FLAGS ${link_flags}
+#    )
+
+##    set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
+##    set(CMAKE_INSTALL_RPATH "@loader_path/..")
+
+#  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}")
+
+#  get_filename_component(ManhattanStyle_LIBRARY_DIR "${ManhattanStyle_LIBRARY}" REALPATH)
+#  get_filename_component(qcustomplot_LIBRARY_DIR "${qcustomplot_LIBRARY}" REALPATH)
+#  get_filename_component(qtpropertybrowser_LIBRARY_DIR "${qtpropertybrowser_LIBRARY}" REALPATH)
+#  get_filename_component(Boost_Real_LIBRARY_DIR "${Boost_LIBRARY_DIR}" REALPATH)
+##  get_filename_component(PYTHON_LIBRARY_DIR "${PYTHON_LIBRARIES}" REALPATH)
+#  get_filename_component(PYTHON_REAL_LIBRARY_DIR "${PYTHON_LIBRARY}" REALPATH)
+
+#  message("OOO PYTHON_LIBRARY_DIR: ${PYTHON_LIBRARY_DIR}  PYTHON_LIBRARY:${PYTHON_LIBRARY}  PYTHON_LIBRARIES:${PYTHON_LIBRARIES}")
+#  message("OOO2 PYTHON_REAL_LIBRARY_DIR:${PYTHON_REAL_LIBRARY_DIR}")
+#  message("OOO3 CMAKE_LIBRARY_OUTPUT_DIRECTORY:${CMAKE_LIBRARY_OUTPUT_DIRECTORY} CMAKE_LIBRARY_PATH:${CMAKE_LIBRARY_PATH}")
+
+#  set(DIRS
+##    ${ManhattanStyle_LIBRARY_DIR}
+##    ${qcustomplot_LIBRARY_DIR}
+##    ${qtpropertybrowser_LIBRARY_DIR}
+#    ${PYTHON_REAL_LIBRARY_DIR}
+#    ${Boost_Real_LIBRARY_DIR}
+#    "${CMAKE_BINARY_DIR}/lib"
+#    "$ENV{QTDIR}"
+#    "$ENV{QTDIR}/plugins"
+#  )
+
+
+#  install (TARGETS ${executable_name}
+#    BUNDLE DESTINATION  . COMPONENT Applications
+#    RUNTIME DESTINATION ${destination_bin} COMPONENT Runtime)
+
+##    set_target_properties(${executable_name} PROPERTIES INSTALL_RPATH "@loader_path/../" MACOSX_RPATH 1)
+
+#  message("WWWWWWW ${plugin_dest_dir}")
+#  install(DIRECTORY "$ENV{QTDIR}/plugins/platforms" DESTINATION ${plugin_dest_dir} COMPONENT Runtime)
+
+##  set(qtconf_text "
+##[Paths]
+##Plugins = PlugIns
+##  ")
+
+##  install(CODE "
+##    file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"${qtconf_text}\")
+##    " COMPONENT Runtime)
+
+##  install(CODE "
+##    file(GLOB_RECURSE QTPLUGINS
+##      \"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
+##    set(BU_CHMOD_BUNDLE_ITEMS True)
+##    set(BU_COPY_FULL_FRAMEWORK_CONTENTS False)
+##    include(${CMAKE_MODULE_PATH}/BABundleUtilities.cmake)
+##    fixup_bundle(\"${APPS}\" \"\${QTPLUGINS}\" \"${DIRS}\")
+##    " COMPONENT Runtime)
+
+##    configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/bundle.cmake.in ${CMAKE_BINARY_DIR}/bundle.cmake @ONLY)
+##    install(SCRIPT ${CMAKE_BINARY_DIR}/bundle.cmake COMPONENT Runtime)
+
+#    set(fixup_path @rpath)
+#    configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/FixBundle.cmake.in ${CMAKE_BINARY_DIR}/FixBundle.cmake @ONLY)
+#    install(SCRIPT ${CMAKE_BINARY_DIR}/FixBundle.cmake COMPONENT Runtime)
+
+
+#else()
+#  install (TARGETS ${executable_name} DESTINATION ${destination_bin} COMPONENT Applications)
+
+#    set(image_files ${CMAKE_SOURCE_DIR}/GUI/main/BornAgain.ico ${CMAKE_SOURCE_DIR}/GUI/main/BornAgain.icns ${CMAKE_SOURCE_DIR}/GUI/coregui/images/BornAgain_48x48.png  ${CMAKE_SOURCE_DIR}/GUI/coregui/images/BornAgain_64x64.png)
+#    install (FILES ${image_files} DESTINATION ${destination_images} COMPONENT Applications)
+
+#endif(APPLE AND CREATE_BUNDLE)
 
-- 
GitLab