Skip to content
Permalink
Browse files

more mac bundling cleanup and streamlining

  • Loading branch information
kyngchaos committed Jul 24, 2011
1 parent e6558be commit dbd9e22817cb52670222e41373dee8f49ff3e7d6
Showing with 204 additions and 294 deletions.
  1. +132 −7 cmake/MacBundleMacros.cmake
  2. +1 −0 mac/CMakeLists.txt
  3. +1 −31 mac/cmake/0qgis.cmake.in
  4. +42 −0 mac/cmake/0vars.cmake.in
  5. +25 −92 mac/cmake/1qt.cmake.in
  6. +1 −86 mac/cmake/2lib.cmake.in
  7. +2 −78 mac/cmake/3fw.cmake.in
@@ -1,11 +1,32 @@
# Mac Bundle Macros
# QGIS Mac Bundle Macros

# BundleUtilities has functions to bundle and fixup libraries into an
# application package, but it's all-or-nothing and is missing some features:
#
# - @loader_path
# - helper functions can't get install_name, just dependencies

# the following cmakecache vars must be set, redefine them
# with config-file substitutions in install-run scripts:
#
# CPACK_PACKAGE_VERSION_MAJOR, CPACK_PACKAGE_VERSION_MINOR
# CMAKE_INSTALL_PREFIX, CMAKE_VERBOSE_MAKEFILE, CMAKE_BUILD_TYPE
# CMAKE_OSX_ARCHITECTURES, OSX_HAVE_LOADERPATH
# QGIS_APP_NAME
# QGIS_MACAPP_PREFIX
# QGIS_*_SUBDIR, QGIS_*_SUBDIR_REV
# WITH_*

# this file must only be included after target installation is complete

# message only if verbose makefiles

FUNCTION (MYMESSAGE MSG)
IF (@CMAKE_VERBOSE_MAKEFILE@)
MESSAGE (STATUS "${MSG}")
ENDIF (@CMAKE_VERBOSE_MAKEFILE@)
ENDFUNCTION (MYMESSAGE)

# get the install_name of a library or framework
# regex stuff taken from GetPrerequisites

@@ -26,9 +47,9 @@ FUNCTION (INSTALLNAMETOOL_CHANGE CHANGE CHANGETO CHANGEBIN)
EXECUTE_PROCESS (COMMAND install_name_tool -change ${CHANGE} ${CHANGETO} "${CHANGEBIN}")
ENDFUNCTION (INSTALLNAMETOOL_CHANGE)

# copy a framework, only specified archs, current version
# pass CMAKE_BUILD_TYPE to FWDEBUG
FUNCTION (COPY_FRAMEWORK FWPREFIX FWNAME FWARCHS FWDEBUG FWDEST)
# copy a framework, only specified archs, current version, debug dep on CMAKE_BUILD_TYPE

FUNCTION (COPY_FRAMEWORK FWPREFIX FWNAME FWDEST)
# reconstruct framework to avoid excessive copying, then deleting
# especially when debug variants are present
# find current version
@@ -41,7 +62,7 @@ FUNCTION (COPY_FRAMEWORK FWPREFIX FWNAME FWARCHS FWDEBUG FWDEST)
STRING (REGEX MATCH "[^/\n]+$" FWVER "${FWDIRPHYS}")
EXECUTE_PROCESS (COMMAND mkdir -p "${FWDEST}/${FWNAME}.framework/Versions/${FWVER}")
EXECUTE_PROCESS (COMMAND ln -sfh ${FWVER} "${FWDEST}/${FWNAME}.framework/Versions/Current")
EXECUTE_PROCESS (COMMAND ditto ${FWARCHS} "${FWPREFIX}/${FWNAME}.framework/Versions/${FWVER}/${FWNAME}" "${FWDEST}/${FWNAME}.framework/Versions/${FWVER}/${FWNAME}")
EXECUTE_PROCESS (COMMAND ditto ${QARCHS} "${FWPREFIX}/${FWNAME}.framework/Versions/${FWVER}/${FWNAME}" "${FWDEST}/${FWNAME}.framework/Versions/${FWVER}/${FWNAME}")
EXECUTE_PROCESS (COMMAND ln -sf Versions/Current/${FWNAME} "${FWDEST}/${FWNAME}.framework/${FWNAME}")
IF (IS_DIRECTORY "${FWPREFIX}/${FWNAME}.framework/Versions/${FWVER}/Resources")
EXECUTE_PROCESS (COMMAND cp -Rfp "${FWPREFIX}/${FWNAME}.framework/Versions/${FWVER}/Resources" "${FWDEST}/${FWNAME}.framework/Versions/${FWVER}")
@@ -50,10 +71,114 @@ FUNCTION (COPY_FRAMEWORK FWPREFIX FWNAME FWARCHS FWDEBUG FWDEST)
# debug variants
SET (FWD "${FWNAME}_debug")
IF ("${FWDEBUG}" STREQUAL "Debug" AND EXISTS "${FWPREFIX}/${FWNAME}.framework/Versions/${FWVER}/${FWD}")
EXECUTE_PROCESS (COMMAND ditto ${FWARCHS} "${FWPREFIX}/${FWNAME}.framework/Versions/${FWVER}/${FWD}" "${FWDEST}/${FWNAME}.framework/Versions/${FWVER}/${FWD}")
EXECUTE_PROCESS (COMMAND ditto ${QARCHS} "${FWPREFIX}/${FWNAME}.framework/Versions/${FWVER}/${FWD}" "${FWDEST}/${FWNAME}.framework/Versions/${FWVER}/${FWD}")
EXECUTE_PROCESS (COMMAND ln -sf Versions/Current/${FWD} "${FWDEST}/${FWNAME}.framework/${FWD}")
IF (IS_DIRECTORY "${FWPREFIX}/${FWNAME}.framework/${FWD}.dSYM")
EXECUTE_PROCESS (COMMAND ditto -X ${FWARCHS} "${FWPREFIX}/${FWNAME}.framework/${FWD}.dSYM" "${FWDEST}/${FWNAME}.framework")
EXECUTE_PROCESS (COMMAND ditto -X ${QARCHS} "${FWPREFIX}/${FWNAME}.framework/${FWD}.dSYM" "${FWDEST}/${FWNAME}.framework")
ENDIF ()
ENDIF ()
ENDFUNCTION (COPY_FRAMEWORK)

# update a library path in all QGIS binary files
# if dylib, change LIBFROM to LIBTO as is
# else assumes it's a framework, change LIBFROM to LIBTO.framework/LIBTO

FUNCTION (UPDATEQGISPATHS LIBFROM LIBTO)
IF (LIBFROM)
STRING (REGEX MATCH "\\.dylib$" ISLIB "${LIBTO}")
IF (ISLIB)
SET (LIBPOST "${LIBTO}")
SET (LIBMID "${QGIS_LIB_SUBDIR}")
ElSE ()
SET (LIBPOST "${LIBTO}.framework/${LIBTO}")
SET (LIBMID "${QGIS_FW_SUBDIR}")
ENDIF ()
SET (LIB_CHG_TO "${ATEXECUTABLE}/${LIBMID}/${LIBPOST}")
# app - always @executable_path
INSTALLNAMETOOL_CHANGE (${LIBFROM} ${LIB_CHG_TO} "${QAPPDIR}/${QGIS_APP_NAME}")
# qgis_help, qbrowser - doesn't link anything else than Qt/Qgis
INSTALLNAMETOOL_CHANGE (${LIBFROM} ${LIB_CHG_TO} "${QBINDIR}/qgis_help.app/Contents/MacOS/qgis_help")
INSTALLNAMETOOL_CHANGE (${LIBFROM} ${LIB_CHG_TO} "${QBINDIR}/qbrowser.app/Contents/MacOS/qbrowser")
# qgis-mapserver
IF (${WITH_MAPSERVER})
IF (${OSX_HAVE_LOADERPATH})
SET (LIB_CHG_TO "${ATEXECUTABLE}/${QGIS_CGIBIN_SUBDIR_REV}/${LIBMID}/${LIBPOST}")
ENDIF ()
INSTALLNAMETOOL_CHANGE (${LIBFROM} ${LIB_CHG_TO} "${QCGIDIR}/qgis_mapserv.fcgi")
ENDIF ()
# libs
IF (${OSX_HAVE_LOADERPATH})
# bundled frameworks can use short relative path
IF (ISLIB})
SET (LIB_CHG_TO "${ATLOADER}/${QGIS_FW_SUBDIR_REV}/${LIBMID}/${LIBPOST}")
ElSE ()
SET (LIB_CHG_TO "${ATLOADER}/../../../${LIBPOST}")
ENDIF ()
ENDIF ()
FOREACH (QL ${QGFWLIST})
INSTALLNAMETOOL_CHANGE (${LIBFROM} ${LIB_CHG_TO} "${QFWDIR}/${QL}.framework/${QL}")
ENDFOREACH (QL)
# libqgispython is not a framework
IF (${OSX_HAVE_LOADERPATH})
SET (LIB_CHG_TO "${ATLOADER}/${QGIS_LIB_SUBDIR_REV}/${LIBMID}/${LIBPOST}")
ENDIF ()
INSTALLNAMETOOL_CHANGE (${LIBFROM} ${LIB_CHG_TO} "${QLIBDIR}/libqgispython.dylib")
# GRASS libexec stuff
IF (EXISTS "${QLIBXDIR}/grass/bin/qgis.g.browser")
IF (${OSX_HAVE_LOADERPATH})
SET (LIB_CHG_TO "${ATLOADER}/../../${QGIS_LIBEXEC_SUBDIR_REV}/${LIBMID}/${LIBPOST}")
ENDIF ()
INSTALLNAMETOOL_CHANGE (${LIBFROM} ${LIB_CHG_TO} "${QLIBXDIR}/grass/bin/qgis.g.browser")
ENDIF ()
# plugins
IF (${OSX_HAVE_LOADERPATH})
SET (LIB_CHG_TO "${ATLOADER}/${QGIS_PLUGIN_SUBDIR_REV}/${LIBMID}/${LIBPOST}")
ENDIF ()
FOREACH (QP ${QGPLUGLIST})
INSTALLNAMETOOL_CHANGE (${LIBFROM} ${LIB_CHG_TO} "${QP}")
ENDFOREACH (QP)
# qgis python
IF (${OSX_HAVE_LOADERPATH})
SET (LIB_CHG_TO "${ATLOADER}/../../${QGIS_DATA_SUBDIR_REV}/${LIBMID}/${LIBPOST}")
ENDIF ()
FOREACH (PG ${QGPYLIST})
INSTALLNAMETOOL_CHANGE (${LIBFROM} ${LIB_CHG_TO} "${PG}")
ENDFOREACH (PG)
# bin - nothing yet
#IF (${OSX_HAVE_LOADERPATH})
# SET (LIB_CHG_TO "${ATLOADER}/${QGIS_BIN_SUBDIR_REV}/${LIBMID}/${LIBPOST}")
#ENDIF ()
#FOREACH (PB ...)
# INSTALLNAMETOOL_CHANGE (${LIBFROM} ${LIB_CHG_TO} "${QBINDIR}/${PB}")
#ENDFOREACH (PB)
ENDIF (LIBFROM)
ENDFUNCTION (UPDATEQGISPATHS)

SET (ATEXECUTABLE "@executable_path")
SET (ATLOADER "@loader_path")
SET (Q_FWVER ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR})

# install destinations
SET (QAPPDIRC "$ENV{DESTDIR}${QGIS_MACAPP_PREFIX}")
SET (QAPPDIR "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}")
SET (QFWDIR "${QAPPDIR}/${QGIS_FW_SUBDIR}")
SET (QBINDIR "${QAPPDIR}/${QGIS_BIN_SUBDIR}")
SET (QCGIDIR "${QAPPDIR}/${QGIS_CGIBIN_SUBDIR}")
SET (QLIBDIR "${QAPPDIR}/${QGIS_LIB_SUBDIR}")
SET (QLIBXDIR "${QAPPDIR}/${QGIS_LIBEXEC_SUBDIR}")
SET (QDATADIR "${QAPPDIR}/${QGIS_DATA_SUBDIR}")
SET (QPLUGDIR "${QAPPDIR}/${QGIS_PLUGIN_SUBDIR}")
SET (QGISPYDIR "${QAPPDIR}/${QGIS_DATA_SUBDIR}/python")

# build arches
SET (QARCHS "")
FOREACH (QARCH ${CMAKE_OSX_ARCHITECTURES})
SET (QARCHS ${QARCHS} "--arch" "${QARCH}")
ENDFOREACH (QARCH)

# common file lists
FILE (GLOB QGFWLIST RELATIVE ${QFWDIR} ${QFWDIR}/qgis*.framework)
# for some reason, REPLACE is stripping list seps
STRING(REPLACE ".framework" ";" QGFWLIST ${QGFWLIST})
FILE (GLOB QGPLUGLIST ${QPLUGDIR}/*.so)
FILE (GLOB QGPYLIST ${QGISPYDIR}/qgis/*.so)
@@ -3,6 +3,7 @@
IF (APPLE)
# for included scripts that set policies (ie OS X bundling)
INSTALL (CODE "cmake_policy(SET CMP0011 NEW)")
CONFIGURE_FILE (cmake/0vars.cmake.in 0vars.cmake @ONLY)
CONFIGURE_FILE (cmake/0qgis.cmake.in 0qgis.cmake @ONLY)
INSTALL (SCRIPT ${CMAKE_BINARY_DIR}/mac/0qgis.cmake)
IF (QGIS_MACAPP_BUNDLE GREATER 0)
@@ -6,39 +6,9 @@
# kill boolean warnings
CMAKE_POLICY (SET CMP0012 NEW)

SET (QAPPDIRC "$ENV{DESTDIR}@QGIS_MACAPP_PREFIX@")
SET (QAPPDIR "$ENV{DESTDIR}@CMAKE_INSTALL_PREFIX@")
SET (QFWDIR "${QAPPDIR}/@QGIS_FW_SUBDIR@")
SET (QBINDIR "${QAPPDIR}/@QGIS_BIN_SUBDIR@")
SET (QCGIDIR "${QAPPDIR}/@QGIS_CGIBIN_SUBDIR@")
SET (QLIBDIR "${QAPPDIR}/@QGIS_LIB_SUBDIR@")
SET (QLIBXDIR "${QAPPDIR}/@QGIS_LIBEXEC_SUBDIR@")
SET (QDATADIR "${QAPPDIR}/@QGIS_DATA_SUBDIR@")
SET (QPLUGDIR "${QAPPDIR}/@QGIS_PLUGIN_SUBDIR@")
SET (QGISPYDIR "${QAPPDIR}/@QGIS_DATA_SUBDIR@/python")
SET (Q_FWVER @CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@)
# Qt framework version is major version
SET (QT_FWVER @QT_VERSION_MAJOR@)

# so config-file doesn't try to replace @
SET (ATEXECUTABLE "@executable_path")
SET (ATLOADER "@loader_path")

INCLUDE (@CMAKE_BINARY_DIR@/mac/0vars.cmake)
INCLUDE (@CMAKE_SOURCE_DIR@/cmake/MacBundleMacros.cmake)

# message only if verbose makefiles
FUNCTION (MYMESSAGE MSG)
IF (@CMAKE_VERBOSE_MAKEFILE@)
MESSAGE (STATUS "${MSG}")
ENDIF (@CMAKE_VERBOSE_MAKEFILE@)
ENDFUNCTION (MYMESSAGE)

FILE (GLOB QGFWLIST RELATIVE ${QFWDIR} ${QFWDIR}/qgis*.framework)
# for some reason, REPLACE is stripping list seps
STRING(REPLACE ".framework" ";" QGFWLIST ${QGFWLIST})
FILE (GLOB QGPLUGLIST ${QPLUGDIR}/*.so)
FILE (GLOB QGPYLIST ${QGISPYDIR}/qgis/*.so)

# assume all install_names start with CMAKE_INSTALL_NAME_DIR
# so we don't have to extract it from binaries
# leave main qgis executable and qgis_help with executable_paths
@@ -0,0 +1,42 @@
# 0vars - redefine cmakecache vars, needed by all other bundling scripts
# ! cmakecache vars not available to external scripts
# so we configure it first to do substitutions
# make sure to use @varname@

# kill boolean warnings
CMAKE_POLICY (SET CMP0012 NEW)

# cmake
SET (CPACK_PACKAGE_VERSION_MAJOR @CPACK_PACKAGE_VERSION_MAJOR@)
SET (CPACK_PACKAGE_VERSION_MINOR @CPACK_PACKAGE_VERSION_MINOR@)
SET (CMAKE_VERBOSE_MAKEFILE "@CMAKE_VERBOSE_MAKEFILE@")
SET (CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@")
SET (CMAKE_BUILD_TYPE "@CMAKE_BUILD_TYPE@")

# OS X options
SET (CMAKE_OSX_ARCHITECTURES "@CMAKE_OSX_ARCHITECTURES@")
SET (OSX_HAVE_LOADERPATH @OSX_HAVE_LOADERPATH@)

# QGIS
SET (QGIS_APP_NAME "@QGIS_APP_NAME@")
SET (QGIS_MACAPP_PREFIX "@QGIS_MACAPP_PREFIX@")
SET (QGIS_FW_SUBDIR "@QGIS_FW_SUBDIR@")
SET (QGIS_FW_SUBDIR_REV "@QGIS_FW_SUBDIR_REV@")
SET (QGIS_BIN_SUBDIR "@QGIS_BIN_SUBDIR@")
SET (QGIS_BIN_SUBDIR_REV "@QGIS_BIN_SUBDIR_REV@")
SET (QGIS_CGIBIN_SUBDIR "@QGIS_CGIBIN_SUBDIR@")
SET (QGIS_CGIBIN_SUBDIR_REV "@QGIS_CGIBIN_SUBDIR_REV@")
SET (QGIS_LIB_SUBDIR "@QGIS_LIB_SUBDIR@")
SET (QGIS_LIB_SUBDIR_REV "@QGIS_LIB_SUBDIR_REV@")
SET (QGIS_LIBEXEC_SUBDIR "@QGIS_LIBEXEC_SUBDIR@")
SET (QGIS_LIBEXEC_SUBDIR_REV "@QGIS_LIBEXEC_SUBDIR_REV@")
SET (QGIS_PLUGIN_SUBDIR "@QGIS_PLUGIN_SUBDIR@")
SET (QGIS_PLUGIN_SUBDIR_REV "@QGIS_PLUGIN_SUBDIR_REV@")
SET (QGIS_DATA_SUBDIR "@QGIS_DATA_SUBDIR@")
SET (QGIS_DATA_SUBDIR_REV "@QGIS_DATA_SUBDIR_REV@")

# optional components
SET (WITH_GLOBE "@WITH_GLOBE@")
SET (WITH_GRASS "@WITH_GRASS@")
SET (WITH_MAPSERVER "@WITH_MAPSERVER@")
SET (WITH_POSTGRESQL "@WITH_POSTGRESQL@")

0 comments on commit dbd9e22

Please sign in to comment.
You can’t perform that action at this time.