tools/CMakeLists.txt
branchhedgeroid
changeset 15515 7030706266df
parent 15339 8951eaad20e5
--- a/tools/CMakeLists.txt	Sun Oct 28 15:18:26 2012 +0100
+++ b/tools/CMakeLists.txt	Fri Dec 06 22:20:53 2019 +0100
@@ -1,4 +1,4 @@
-if (NOT APPLE)
+if(NOT APPLE)
     configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
                    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
                     IMMEDIATE @ONLY)
@@ -6,49 +6,119 @@
     add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
 endif()
 
-if (APPLE)
-    find_package(Qt4 REQUIRED QUIET)
-    find_package(SDL REQUIRED)
-    find_package(SDL_image REQUIRED)
-    find_package(SDL_net REQUIRED)
-    find_package(SDL_ttf REQUIRED)
-    find_package(SDL_mixer REQUIRED)
-    find_package(OGGVORBIS REQUIRED)
+if(APPLE AND NOT SKIPBUNDLE)
+    find_package(Qt5 REQUIRED QUIET COMPONENTS Core Widgets Gui Network)
+    find_package(SDL2 REQUIRED)
+    find_package(SDL2_image 2 REQUIRED)
+    find_package(SDL2_net 2 REQUIRED)
+    find_package(SDL2_ttf 2 REQUIRED)
+    find_package(SDL2_mixer 2 REQUIRED)
+    find_package(OggVorbis REQUIRED)
+    find_package(PNG REQUIRED)
+
     if(NOT NOAUTOUPDATE)
-        #needed for SPARKLE_FOUND variable
-        find_package(Sparkle QUIET)
+        find_package(Sparkle) #needed for SPARKLE_FOUND variable
         #needed because the 'if' clause in the script prints silly policy warnings
-        if(${SPARKLE_FOUND})
+        if(SPARKLE_FOUND)
             set(SPARKLE_FOUND 1)
         else()
             set(SPARKLE_FOUND 0)
         endif()
     endif()
 
-    #use the associated tool from the libraries we've selected
-    string(REGEX REPLACE "(.*)/include.*" "\\1" qt_base_dir "${QT_INCLUDE_DIR}")
+    #remove the ";-framework Cocoa" from the SDL2_LIBRARY variable
+    string(REGEX REPLACE "(.*);-.*" "\\1" sdl_library_only "${SDL2_LIBRARY}")
+    #remove the "libSDLmain.a" from the SDL2_LIBRARY variable
+    string(REGEX REPLACE ".*;(.*)" "\\1" sdl_library_only "${sdl_library_only}")
 
-    #remove the ";-framework Cocoa" from the SDL_LIBRARY variable
-    string(REGEX REPLACE "(.*);-.*" "\\1" sdl_dir "${SDL_LIBRARY}")
+    #get the neme of the library (harmelss if it is static)
+    string(REGEX REPLACE ".*/(.*)$" "\\1" PNG_LIBNAME "${PNG_LIBRARY}")
+    string(REGEX REPLACE ".*/(.*)$" "\\1" ZLIB_LIBNAME "${ZLIB_LIBRARY}")
 
-    if(NOT NOPNG)
-        #get the neme of the library (harmelss if it is static)
-        string(REGEX REPLACE ".*/(.*)$" "\\1" PNG_LIBNAME "${PNG_LIBRARY}")
+    set(frameworks_dir ${CMAKE_INSTALL_PREFIX}/${target_library_install_dir})
+    
+    if(${BUILD_ENGINE_LIBRARY})
+        set(engine_full_path "${frameworks_dir}/${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}")
+    else()
+        set(engine_full_path "${CMAKE_INSTALL_PREFIX}/hwengine${CMAKE_EXECUTABLE_SUFFIX}")
     endif()
 
-    #this tool is present in qt 4.5 but only if you compile from sources
-    #from qt 4.6 is present also in the binary version
-    find_program(macdeployqt_executable NAMES macdeployqt macdeployqt-mac PATHS ${qt_base_dir}/bin)
-    if(NOT macdeployqt_executable)
-        message(FATAL_ERROR "The utility macdeployqt is required to create the bundle (seached: ${qt_base_dir})")
-    else()
-        message(STATUS "Found macdeployqt: ${macdeployqt_executable}")
+
+    #create the .app bundle using BundleUtilities instead of old macdeployqt
+    set(APP_DIR "Hedgewars.app")
+    set(APP_BASE_DIR "${CMAKE_INSTALL_PREFIX}/../")  # should be, Hedgewars.app/Contents/MacOS/../
+
+    # macro to install qt5 plugins 
+    # modified from https://github.com/Kitware/CMake/blob/master/Source/QtDialog/CMakeLists.txt
+    macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var)
+      get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION)
+      if(EXISTS "${_qt_plugin_path}")
+        get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME)
+        get_filename_component(_qt_plugin_type "${_qt_plugin_path}" PATH)
+        get_filename_component(_qt_plugin_type "${_qt_plugin_type}" NAME)
+        set(_qt_plugin_dir "PlugIns")
+        set(_qt_plugin_dest "${_qt_plugin_dir}/${_qt_plugin_type}")
+        install(FILES "${_qt_plugin_path}"
+          DESTINATION "../${_qt_plugin_dest}" # relative to install dir
+          ${COMPONENT})
+        list(APPEND ${_qt_plugins_var}
+          "\${CMAKE_BINARY_DIR}/${APP_BASE_DIR}/${_qt_plugin_dest}/${_qt_plugin_file}")
+      else()
+        message(FATAL_ERROR "QT plugin ${_qt_plugin_name} not found")
+      endif()
+    endmacro()
+
+    # install cocoa plugin and build list to send to fixup_bundle
+    install_qt5_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS)
+    file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
+        "[Paths]\nPlugins = ${_qt_plugin_dir}\n")
+    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
+        DESTINATION "../Resources"  # relative to install dir
+        ${COMPONENT})
+
+    # Build up search directories for fixup_bundle
+    set(DIRS "")
+    # Add QT bin and lib paths
+    if(CMAKE_PREFIX_PATH)
+        foreach(dir ${CMAKE_PREFIX_PATH})
+            list(APPEND DIRS "${dir}/bin" "${dir}/lib")
+        endforeach()
     endif()
+    # Add other lib folder from around the system
+    list(APPEND DIRS 
+        ~/Library/Frameworks
+        /Library/Frameworks
+        /usr/local/lib
+        /opt/local/lib
+    )
 
-    #dummy target, we're interested in the postscript file
-    add_custom_target(bundle)
-    set_target_properties(bundle PROPERTIES POST_INSTALL_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/CreateMacBundle.cmake)
+    # operate on the Hedgewars.app
+    set(APPS ${CMAKE_BINARY_DIR}/${APP_DIR})
+    
+    # debugging
+    message(STATUS "APPS: ${APPS}")
+    message(STATUS "QT_PLUGINS: ${QT_PLUGINS}")
+    message(STATUS "DIRS: ${DIRS}")
 
-    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CreateMacBundle.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CreateMacBundle.cmake)
+    # properly fixup the .app to include all dependencies    
+    install(CODE "include(BundleUtilities)
+        fixup_bundle(\"${APPS}\" \"${QT_PLUGINS}\" \"${DIRS}\")")
+    
+    
+    #create the .dmg for deployment
+    #first make sure .app exists, then remove any old .dmg with same name, finally run the script
+    add_custom_target(dmg COMMAND make install
+                          COMMAND rm -f ${CMAKE_BINARY_DIR}/Hedgewars-${HEDGEWARS_VERSION}.dmg
+                          COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/create-dmg.sh
+                                  --volname "Hedgewars ${HEDGEWARS_VERSION}"
+                                # --volicon icon.icns
+                                  --window-size 600 470
+                                  --icon-size 96
+                                  --icon "Hedgewars" 190 190
+                                  --app-drop-link 410 190
+                                  --background "${CMAKE_CURRENT_SOURCE_DIR}/../misc/dmgBackground.png"
+                                  ${CMAKE_BINARY_DIR}/Hedgewars-${HEDGEWARS_VERSION}.dmg
+                                  ${CMAKE_BINARY_DIR}/${APP_DIR}
+                          WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
 endif()