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@)
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/.* )
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
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}
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
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
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}
58
FILE(INSTALL ${PROJECT_SOURCE_DIR}/TeXworks-manual
59
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app/Contents/texworks-help/
63
# Copy all runtime dependencies and rewrite loader paths
64
# ------------------------------------------------------
66
# Bring in `DeployQt4` a CMake module taken from the Charm application:
68
# <https://github.com/KDAB/Charm>
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.
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@)
80
# Gather all TeXworks Plugin libraries.
81
FILE(GLOB TeXworks_PLUGINS
82
${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app/Contents/PlugIns/*${CMAKE_SHARED_LIBRARY_SUFFIX})
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)
88
FIXUP_QT4_BUNDLE(${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app "${QT_PLUGINS}" "${TeXworks_PLUGINS}" "${TeXworks_LIB_DIRS}")
91
# Remove unecessary architectures from universal binaries
92
# -------------------------------------------------------
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.
98
# Another useful function from `BundleUtilities`.
99
GET_BUNDLE_MAIN_EXECUTABLE(${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app APP_MAIN)
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
106
MESSAGE(STATUS "Reducing the size of bundled libraries.")
107
MESSAGE(STATUS "Scanning architectures of: ${APP_MAIN}")
109
# `lipo -info` returns a list of the form:
111
# <is universal binary?>: <program name>: <list of architectures>
113
# Piping this output to `cut -d : -f 3-` allows us to extract just the list
115
COMMAND lipo -info ${APP_MAIN}
116
COMMAND cut -d : -f 3-
117
OUTPUT_VARIABLE APP_ARCHS
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})
125
MESSAGE(STATUS "Will reduce bundled libraries to: ${APP_ARCHS}")
127
FOREACH(ARCH IN LISTS APP_ARCHS)
128
SET(ARCHS_TO_EXTRACT "${ARCHS_TO_EXTRACT} -extract ${ARCH}")
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
134
FILE(GLOB BUNDLED_DYLIBS
135
${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app/Contents/MacOS/*${CMAKE_SHARED_LIBRARY_SUFFIX})
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}")
144
MESSAGE(STATUS "Finished stripping architectures from bundled libraries.")