~ubuntu-branches/ubuntu/saucy/texworks/saucy

« back to all changes in this revision

Viewing changes to CMake/packaging/mac/MacPackagingTasks.cmake.in

  • Committer: Bazaar Package Importer
  • Author(s): Atsuhito KOHDA
  • Date: 2011-08-18 11:22:40 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20110818112240-d2vmclt5llf8vano
Tags: 0.5~svn930-1
New upstream release (rev 930).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# OS X packaging tasks
 
2
 
 
3
# This file is processed by `CONFIGURE_FILE` in `../CMakeLists.txt` which inserts
 
4
# values for `@VARIABLE@` declarations. This is done to import values for some
 
5
# variables that would otherwise be undefined when CPack is running.
 
6
SET(PROJECT_NAME @PROJECT_NAME@)
 
7
SET(PROJECT_SOURCE_DIR @PROJECT_SOURCE_DIR@)
 
8
SET(PROJECT_BINARY_DIR @PROJECT_BINARY_DIR@)
 
9
SET(TeXworks_LIB_DIRS @TeXworks_LIB_DIRS@)
 
10
SET(CMAKE_SHARED_LIBRARY_SUFFIX @CMAKE_SHARED_LIBRARY_SUFFIX@)
 
11
SET(QT_PLUGINS @QT_PLUGINS@)
 
12
 
 
13
# This `IF` statement ensures that the following commands are executed only when
 
14
# CPack is running---i.e. when a user executes `make package` but not `make install`
 
15
IF ( ${CMAKE_INSTALL_PREFIX} MATCHES .*/_CPack_Packages/.* )
 
16
 
 
17
  # Download and install Poppler data
 
18
  # ---------------------------------
 
19
  IF ( NOT EXISTS ${PROJECT_SOURCE_DIR}/poppler-data-0.4.4.tar.gz )
 
20
    MESSAGE(STATUS "Downloading Poppler data files")
 
21
    FILE(DOWNLOAD "http://poppler.freedesktop.org/poppler-data-0.4.4.tar.gz"
 
22
      ${PROJECT_SOURCE_DIR}/poppler-data-0.4.4.tar.gz
 
23
      EXPECTED_MD5 f3a1afa9218386b50ffd262c00b35b31
 
24
      SHOW_PROGRESS
 
25
    )
 
26
  ENDIF ()
 
27
 
 
28
  IF ( NOT EXISTS ${PROJECT_SOURCE_DIR}/poppler-data-0.4.4 )
 
29
    EXECUTE_PROCESS(COMMAND tar xzf ${PROJECT_SOURCE_DIR}/poppler-data-0.4.4.tar.gz
 
30
      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
 
31
    )
 
32
  ENDIF ()
 
33
 
 
34
  FILE(INSTALL ${PROJECT_SOURCE_DIR}/poppler-data-0.4.4/
 
35
    DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app/Contents/poppler-data
 
36
    PATTERN CMakeLists.txt EXCLUDE
 
37
    PATTERN Makefile EXCLUDE
 
38
  )
 
39
 
 
40
 
 
41
  # Download and install TeXworks manual
 
42
  # ------------------------------------
 
43
  IF ( NOT EXISTS ${PROJECT_SOURCE_DIR}/TeXworks-manual-html-r814.zip )
 
44
    MESSAGE(STATUS "Downloading TeXworks HTML manual")
 
45
    FILE(DOWNLOAD "http://texworks.googlecode.com/files/TeXworks-manual-html-r814.zip"
 
46
      ${PROJECT_SOURCE_DIR}/TeXworks-manual-html-r814.zip
 
47
      EXPECTED_MD5 2894969a6ac4bba31953264e04553717
 
48
      SHOW_PROGRESS
 
49
    )
 
50
  ENDIF ()
 
51
 
 
52
  IF ( NOT EXISTS ${PROJECT_SOURCE_DIR}/TeXworks-manual )
 
53
    EXECUTE_PROCESS(COMMAND unzip ${PROJECT_SOURCE_DIR}/TeXworks-manual-html-r814.zip
 
54
      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
 
55
    )
 
56
  ENDIF ()
 
57
 
 
58
  FILE(INSTALL ${PROJECT_SOURCE_DIR}/TeXworks-manual
 
59
    DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app/Contents/texworks-help/
 
60
  )
 
61
 
 
62
 
 
63
  # Copy all runtime dependencies and rewrite loader paths
 
64
  # ------------------------------------------------------
 
65
 
 
66
  # Bring in `DeployQt4` a CMake module taken from the Charm application:
 
67
  #
 
68
  #   <https://github.com/KDAB/Charm>
 
69
  #
 
70
  # This module offers the `FIXUP_QT4_BUNDLE` function which wraps
 
71
  # `FIXUP_BUNDLE` from CMake's `BundleUtilities` module and extends it with
 
72
  # additional Qt4-specific goodies---such as installing Qt4 plugins.
 
73
  #
 
74
  # `FIXUP_BUNDLE` is a wonderful function that examines an executable, finds
 
75
  # all non-system libraries it depends on, copies them into the `.app` bundle
 
76
  # and then re-writes the necessary loader paths.
 
77
  SET(CMAKE_MODULE_PATH @CMAKE_MODULE_PATH@)
 
78
  INCLUDE(DeployQt4)
 
79
 
 
80
  # Gather all TeXworks Plugin libraries.
 
81
  FILE(GLOB TeXworks_PLUGINS
 
82
    ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app/Contents/PlugIns/*${CMAKE_SHARED_LIBRARY_SUFFIX})
 
83
 
 
84
  # If `BU_CHMOD_BUNDLE_ITEMS` is not set, `install_name_tool` will fail to
 
85
  # re-write some loader paths due to insufficiant permissions.
 
86
  SET(BU_CHMOD_BUNDLE_ITEMS ON)
 
87
 
 
88
  FIXUP_QT4_BUNDLE(${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app "${QT_PLUGINS}" "${TeXworks_PLUGINS}" "${TeXworks_LIB_DIRS}")
 
89
 
 
90
 
 
91
  # Remove unecessary architectures from universal binaries
 
92
  # -------------------------------------------------------
 
93
 
 
94
  # Some libraries copied from the OS X system, such as X11 libraries, may
 
95
  # contain up to 4 different architectures. Here we will iterate over these
 
96
  # libraries and use `lipo` to strip out un-needed architectures.
 
97
 
 
98
  # Another useful function from `BundleUtilities`.
 
99
  GET_BUNDLE_MAIN_EXECUTABLE(${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app APP_MAIN)
 
100
 
 
101
  # We look at the TeXworks binary that was built rather than consulting the
 
102
  # value of the `CMAKE_OSX_ARCHITECTURES` because if the user did not set
 
103
  # `CMAKE_OSX_ARCHITECTURES`, then the variable will be an empty string and the
 
104
  # format of the resulting binary will depend on the versions of OS X and
 
105
  # XCode.
 
106
  MESSAGE(STATUS "Reducing the size of bundled libraries.")
 
107
  MESSAGE(STATUS "Scanning architectures of: ${APP_MAIN}")
 
108
  EXECUTE_PROCESS(
 
109
    # `lipo -info` returns a list of the form:
 
110
    #
 
111
    #     <is universal binary?>: <program name>: <list of architectures>
 
112
    #
 
113
    # Piping this output to `cut -d : -f 3-` allows us to extract just the list
 
114
    # of architectures.
 
115
    COMMAND lipo -info ${APP_MAIN}
 
116
    COMMAND cut -d : -f 3-
 
117
    OUTPUT_VARIABLE APP_ARCHS
 
118
  )
 
119
 
 
120
  # Strip leading and trailing whitespace.
 
121
  STRING(STRIP ${APP_ARCHS} APP_ARCHS)
 
122
  # Convert spaces to semicolons so CMake will interpret the string as a list.
 
123
  STRING(REPLACE " " ";" APP_ARCHS ${APP_ARCHS})
 
124
 
 
125
  MESSAGE(STATUS "Will reduce bundled libraries to: ${APP_ARCHS}")
 
126
 
 
127
  FOREACH(ARCH IN LISTS APP_ARCHS)
 
128
    SET(ARCHS_TO_EXTRACT "${ARCHS_TO_EXTRACT} -extract ${ARCH}")
 
129
  ENDFOREACH ()
 
130
 
 
131
  # __NOTE:__ This will not process any dylibs from Frameworks copied by
 
132
  # `FIXUP_BUNDLE`, hence it may not touch any of the Qt libraries. Something to
 
133
  # fix in the future.
 
134
  FILE(GLOB BUNDLED_DYLIBS
 
135
    ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app/Contents/MacOS/*${CMAKE_SHARED_LIBRARY_SUFFIX})
 
136
 
 
137
  FOREACH(DYLIB IN LISTS BUNDLED_DYLIBS)
 
138
    MESSAGE(STATUS "Processing included library: ${DYLIB}")
 
139
    # `lipo` is very very anal about how arguments get passed to it. So we
 
140
    # execute through bash to side-step the issue.
 
141
    EXECUTE_PROCESS(COMMAND bash -c "lipo ${ARCHS_TO_EXTRACT} ${DYLIB} -output ${DYLIB}")
 
142
  ENDFOREACH ()
 
143
 
 
144
  MESSAGE(STATUS "Finished stripping architectures from bundled libraries.")
 
145
 
 
146
ENDIF ()
 
147