CMake install and bundling improvements (esp. OS X)

This patch improves the cmake bundling process:
- reworked bundle handling for OS X: only when installing resources are copied, otherwise
only the smallest bundle is built
- on OS X, the utility programs (tex2lyx) are now installed in the right location
- it removes some unneeded BUNDLE DESTINATION
- it provides a basic support for QT plugins inclusion
- it properly builds a disk image on OS X (only the background image is missing)
- it fixes the library paths for all executables (not only LyX)
- Use the COPYING file for cmake install license
This commit is contained in:
Benjamin Piwowarski 2014-03-09 10:21:51 +01:00 committed by Richard Heck
parent c2e67a41ce
commit 14de3aa49b
9 changed files with 216 additions and 88 deletions

View File

@ -38,6 +38,8 @@ file(MAKE_DIRECTORY "${LYX_TESTS_USERDIR}")
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 OLD)
cmake_policy(SET CMP0005 OLD)
# Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION
cmake_policy(SET CMP0006 NEW)
endif()
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
@ -297,41 +299,66 @@ else()
set(LYX_REVISION_VERSION ${LYX_PATCH_VERSION})
endif()
if(LYX_PROGRAM_SUFFIX)
set(PROGRAM_SUFFIX "${LYX_INSTALL_SUFFIX}")
else()
# Set the programs (lyx, tex2lyx, etc.) suffix
# When building an OS X bundle, we will append
# the suffix only to the bundle, not to the programs
set(PROGRAM_SUFFIX "")
if(LYX_PROGRAM_SUFFIX AND NOT (APPLE AND LYX_BUNDLE))
set(PROGRAM_SUFFIX "${LYX_INSTALL_SUFFIX}")
endif()
set(_lyx "${PACKAGE_BASE}${PROGRAM_SUFFIX}")
set(_tex2lyx tex2lyx${PROGRAM_SUFFIX})
add_custom_target(lyx_version ALL
COMMAND ${CMAKE_COMMAND} -DTOP_SRC_DIR=${TOP_SRC_DIR} -DTOP_CMAKE_PATH=${TOP_CMAKE_PATH} -DTOP_BINARY_DIR=${TOP_BINARY_DIR} -DLYX_DATE=${LYX_DATE} -P ${TOP_SCRIPT_PATH}/LyXGetVersion.cmake
)
set_target_properties(lyx_version PROPERTIES FOLDER "applications")
if(APPLE)
set(osx_bundle_program_name ${PACKAGE_BASE}${PROGRAM_SUFFIX})
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/development/MacOSX/Info.plist.in" "${CMAKE_CURRENT_BINARY_DIR}/Info.plist")
endif()
# Default paths for installed utilities (tex2lyx, lyxclient, etc.)
set(LYX_UTILITIES_INSTALL_PATH bin)
if(LYX_BUNDLE)
set(LYX_CPACK ON)
message(STATUS)
message(STATUS "Bundle creation is enabled (experimental):")
message(STATUS " make")
message(STATUS " make install/strip")
message(STATUS " make package")
if(APPLE)
set(MACOSX_BUNDLE TRUE)
# This sets the bundle + executable names
set(_lyx "${PACKAGE_BASE}${LYX_INSTALL_SUFFIX}")
# This sets the Info.plist executable name
set(osx_bundle_program_name ${_lyx})
# Bundle name
set(LYX_BUNDLE_NAME ${_lyx})
# This will contain the list of files that need to be included
# in the bundle and their location within the bundle
set(OSX_BUNDLE_FILES "${TOP_SRC_DIR}/development/MacOSX/LyX.sdef;${TOP_SRC_DIR}/development/MacOSX/LyXapp.icns;${CMAKE_BINARY_DIR}/lyxrc.dist")
set(OSX_BUNDLE_DIRS "Resources;Resources;Resources")
# Process Info.plist and lyxrc.dist
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/development/MacOSX/Info.plist.in" "${CMAKE_CURRENT_BINARY_DIR}/Info.plist")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/development/MacOSX/lyxrc.dist.in" "${CMAKE_CURRENT_BINARY_DIR}/lyxrc.dist")
set(LYX_BUILD_BUNDLE MACOSX_BUNDLE)
set(CPACK_BUNDLE_NAME ${PACKAGE_BASE}${PROGRAM_SUFFIX})
set(LYX_DATA_SUBDIR ${LYX_BUNDLE_NAME}.app/Contents/Resources/ CACHE STRING "Bundle Contents dir" FORCE)
# Variables used by CPack
set(CPACK_BUNDLE_NAME ${LYX_BUNDLE_NAME})
set(CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_BINARY_DIR}/Info.plist")
set(LYX_DATA_SUBDIR ${PACKAGE_BASE}${PROGRAM_SUFFIX}.app/Contents/Resources/ CACHE STRING "Bundle Contents dir" FORCE)
set(MACOSX_BUNDLE_STARTUP_COMMAND ${PACKAGE_BASE}${PROGRAM_SUFFIX}.app)
set(MACOSX_BUNDLE_STARTUP_COMMAND ${LYX_BUNDLE_NAME}.app)
# Set the install paths
set(LYX_UTILITIES_INSTALL_PATH ${LYX_BUNDLE_NAME}.app/Contents/MacOS)
if(NOT LYX_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/LyX CACHE PATH "Mac bundle dir" FORCE)
set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
endif()
# Change the owner so that the install can work
install(CODE "set(BU_CHMOD_BUNDLE_ITEMS 1)")
install(CODE "set(BU_CHMOD_BUNDLE_ITEMS 1)" COMPONENT Runtime)
elseif(UNIX)
message(STATUS "To embed Qt in this bundle don't build with your system Qt:")
message(STATUS " - fix PATH so a other qmake is found by cmake")
@ -390,8 +417,11 @@ set(LYX_LOCALEDIR "locale")
set(LYX_ABS_INSTALLED_LOCALEDIR "${LYX_ABS_INSTALLED_DATADIR}/${LYX_DATA_SUBDIR}${LYX_LOCALEDIR}")
set(LYX_ABS_TOP_SRCDIR "${TOP_SRC_DIR}")
set(LYX_MAN_DIR "/usr/local/man" CACHE STRING
"Install location for man pages.")
if(LYX_BUNDLE AND APPLE)
set(LYX_MAN_DIR "${LYX_DATA_SUBDIR}" CACHE STRING "Install location for man pages.")
else()
set(LYX_MAN_DIR "/usr/local/man/man1" CACHE STRING "Install location for man pages.")
endif()
mark_as_advanced(LYX_MAN_DIR)
if(LYX_INSTALL AND WIN32)
@ -738,8 +768,6 @@ if(QTVERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*")
MATH(EXPR QT4_VERSION "(${CMAKE_MATCH_1}<<16)|(${CMAKE_MATCH_2}<<8)|${CMAKE_MATCH_3}")
endif()
set(_lyx "${PACKAGE_BASE}${PROGRAM_SUFFIX}")
set(_tex2lyx tex2lyx${PROGRAM_SUFFIX})
set (cmd ${CMAKE_CTEST_COMMAND})
if (MSVC)
@ -751,12 +779,6 @@ add_custom_target (lyx_run_tests COMMAND ${cmd})
set_target_properties(lyx_run_tests PROPERTIES FOLDER "tests")
add_subdirectory(src "${TOP_BINARY_DIR}/src")
add_subdirectory(lib/lyx2lyx "${TOP_BINARY_DIR}/lyx2lyx")
add_subdirectory(lib/scripts "${TOP_BINARY_DIR}/scripts")
add_subdirectory(lib/examples "${TOP_BINARY_DIR}/lib/examples")
if(LYX_INSTALL)
if(${LYX_PYTHON_EXECUTABLE} MATCHES "-NOTFOUND")
message(STATUS "Python required to create doc!")
@ -764,11 +786,13 @@ if(LYX_INSTALL)
add_subdirectory(${LYX_CMAKE_DIR}/man "${TOP_BINARY_DIR}/man")
add_subdirectory(${LYX_CMAKE_DIR}/doc "${TOP_BINARY_DIR}/doc")
endif()
if(NOT(LYX_BUNDLE AND APPLE))
include(../Install)
endif()
endif()
add_subdirectory(src "${TOP_BINARY_DIR}/src")
add_subdirectory(lib/lyx2lyx "${TOP_BINARY_DIR}/lyx2lyx")
add_subdirectory(lib/scripts "${TOP_BINARY_DIR}/scripts")
add_subdirectory(lib/examples "${TOP_BINARY_DIR}/lib/examples")
add_subdirectory(sourcedoc "${TOP_BINARY_DIR}/sourcedoc")
add_subdirectory(development/autotests "${TOP_BINARY_DIR}/autotests")
if(LYX_ENABLE_URLTESTS)
@ -813,4 +837,8 @@ if(ENABLE_DIST)
add_custom_target(git-archive DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${DIST_NAME})
endif()
# Last directory to be included so that the fixup code (OS X)
# can be run last
add_subdirectory(development/cmake/post_install)
message(STATUS)

View File

@ -0,0 +1,63 @@
# Copied from Lyx-Mac-binary-release.sh
# TODO: In order to avoid having two versions,
# call this file from Lyx-Mac-binary-release.sh
FILE=$1
LyxName=$2
IMAGEPATH=$3
X_BOUNDS=$4
Y_BOUNDS=$5
# Creates the structure
mkdir -p "${FILE}"
touch "${FILE}/${LyxName}.app"
touch "${FILE}/Applications"
# Copy the background and make sure the file is visible
# For some reason (OS X cache?), we need to remove the previous
# file
rm -f "$FILE/background.png"
cp "$IMAGEPATH" "$FILE/background.png"
xattr -c "$FILE/background.png"
Y_POSITION=$((Y_BOUNDS - 65))
Y_BOUNDS=$((Y_BOUNDS + 20))
LYX_X_POSITION=$((X_BOUNDS / 4))
LYX_Y_POSITION=$Y_POSITION
APP_X_POSITION=$((3 * X_BOUNDS / 4))
APP_Y_POSITION=$Y_POSITION
WITH_DOCUMENTS=$(test -d "${FILE}/Documents" && echo true || echo false)
osascript <<-EOF
tell application "Finder"
set f to POSIX file ("$FILE" as string) as alias
set image to POSIX file ("$IMAGEPATH" as string) as alias
tell folder f
open
tell container window
set toolbar visible to false
set statusbar visible to false
set current view to icon view
delay 1 -- sync
set the bounds to {20, 50, $X_BOUNDS, $Y_BOUNDS}
end tell
delay 1 -- sync
set icon size of the icon view options of container window to 64
set arrangement of the icon view options of container window to not arranged
if ${WITH_DOCUMENTS} then
set position of item "Documents" to {$LYX_X_POSITION,0}
end if
set position of item "${LyxName}.app" to {$LYX_X_POSITION,$LYX_Y_POSITION}
set position of item "Applications" to {$APP_X_POSITION,$APP_Y_POSITION}
set background picture of the icon view options of container window to file "background.png"
set the bounds of the container window to {0, 0, $X_BOUNDS, $Y_BOUNDS}
update without registering applications
delay 5 -- sync
close
end tell
delay 5 -- sync
end tell
EOF
# Hide again the background
chflags hidden "$FILE/background.png"

View File

@ -5,18 +5,6 @@
if(NOT(LYX_BUNDLE) AND APPLE)
message(STATUS "Installing to ${CMAKE_INSTALL_PREFIX}, defined by CMAKE_INSTALL_PREFIX")
endif()
set(OSX_BUNDLE_FILES "")
# Install files into OS X bundle
macro(lyx_install_osx basedir files)
if(LYX_BUNDLE_PROPERTY_MODE STREQUAL "ON")
foreach(file ${files})
set_source_files_properties("${file}" PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/${basedir}")
endforeach()
else()
list(APPEND OSX_BUNDLE_FILES "${files}")
endif()
endmacro(lyx_install_osx)
# the macro scans the directories "_parent_src_dir/_dir/_current_dir" for *._file_type files
# and installs the files in CMAKE_INSTALL_PREFIX/_current_dir
@ -71,23 +59,14 @@ macro(lyx_install _parent_src_dir _gl_dir _file_type)
if(_glob_dir STREQUAL ".")
set(_base_dir .)
endif()
#message(STATUS "install ${LYX_DATA_SUBDIR}${_dir}/${_base_dir}: ${files_list} ")
#message(STATUS "install at ${CMAKE_INSTALL_PREFIX}/${LYX_DATA_SUBDIR}${_dir}/${_base_dir}")
if(APPLE)
lyx_install_osx("${_dir}/${_based_dir}" "${files_list}")
else()
install(FILES ${files_list} DESTINATION ${LYX_DATA_SUBDIR}${_dir}/${_base_dir})
endif(APPLE)
install(FILES ${files_list} DESTINATION "${LYX_DATA_SUBDIR}${_dir}/${_base_dir}")
endif()
if(program_list)
if(_glob_dir STREQUAL ".")
set(_base_dir .)
endif()
if(APPLE)
lyx_install_osx("${_dir}/${_based_dir}" "${program_list}")
else()
install(PROGRAMS ${program_list} DESTINATION ${LYX_DATA_SUBDIR}${_dir}/${_base_dir})
endif(APPLE)
install(FILES ${program_list} DESTINATION "${LYX_DATA_SUBDIR}${_dir}/${_base_dir}")
endif()
endforeach(_current_dir)
endforeach(_glob_dir)
@ -123,14 +102,15 @@ lyx_install(${TOP_SRC_DIR}/lib . * .)
# Install
if(APPLE)
lyx_install(${TOP_SRC_DIR}/development/MacOSX . *.sdef .)
lyx_install(${TOP_SRC_DIR}/development/MacOSX . *.icns .)
lyx_install(${TOP_SRC_DIR}/development/MacOSX . qt.conf .)
endif()
if(LYX_BUNDLE)
install(FILES ${TOP_SRC_DIR}/development/MacOSX/spotlight/Info.plist DESTINATION "${MACOSX_BUNDLE_STARTUP_COMMAND}/Contents/Library/Spotlight/LyX-Metadata.mdimporter/Contents")
install(FILES "${TOP_SRC_DIR}/development/MacOSX/PkgInfo" DESTINATION "${MACOSX_BUNDLE_STARTUP_COMMAND}/Contents")
endif()
install(PROGRAMS ${TOP_SRC_DIR}/lib/scripts/listerrors DESTINATION scripts)
if(UNIX)
install(FILES "${TOP_SRC_DIR}/development/MacOSX/lyxeditor" DESTINATION "${LYX_UTILITIES_INSTALL_PATH}")
install(FILES "${TOP_SRC_DIR}/development/MacOSX/LyX.icns" DESTINATION "${LYX_DATA_SUBDIR}")
set(program_suffix ${PROGRAM_SUFFIX})
elseif(UNIX)
set(program_suffix ${PROGRAM_SUFFIX})
configure_file(${TOP_SRC_DIR}/lib/lyx.desktop.in lyx${PROGRAM_SUFFIX}.desktop)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lyx${PROGRAM_SUFFIX}.desktop DESTINATION applications)

View File

@ -1 +1 @@
GPL
GPL

View File

@ -6,6 +6,8 @@
if(LYX_BUNDLE)
if(APPLE)
set(CPACK_GENERATOR DragNDrop)
set(CPACK_DMG_BACKGROUND_IMAGE "${TOP_CMAKE_PATH}/../MacOSX/dmg-background.png")
set(CPACK_DMG_DS_STORE "${CMAKE_BINARY_DIR}/ds_store/.DS_Store")
elseif(UNIX)
set(CPACK_GENERATOR STGZ)
elseif(WIN32)
@ -32,7 +34,10 @@ FILE(STRINGS "${TOP_CMAKE_PATH}/LyX_summary.txt" CPACK_PACKAGE_DESCRIPTION_SUMMA
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${LYX_INSTALL_SUFFIX}")
if (NOT WIN32)
if (APPLE)
# We don't need absolute paths
set(CPACK_SET_DESTDIR "OFF")
elseif (NOT WIN32)
# needed by rpm
set(CPACK_SET_DESTDIR "ON")
endif()
@ -54,7 +59,7 @@ set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
#
# for the next ones, cpack insists on data with values in some file
set(CPACK_PACKAGE_DESCRIPTION_FILE "${TOP_CMAKE_PATH}/LyX_description.txt")
set(CPACK_RESOURCE_FILE_LICENSE "${TOP_CMAKE_PATH}/LyX_license.txt")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
# Use the revision number saved in ${LYX_PACKAGE_RELEASE}
# as the release in rpm-package-build.

View File

@ -0,0 +1,65 @@
# Finish the construction of the bundle
# by including the necessary QT libraries
set(QTPLUGINS "")
# Find a qt plugin and install it in the plugins directory
macro(install_qt_plugin _qt_plugin_name)
get_target_property(qtlib "${_qt_plugin_name}" LOCATION)
if(EXISTS ${qtlib})
get_filename_component(qtdir ${qtlib} PATH)
get_filename_component(qtdir ${qtdir} NAME)
# Installing QT plugin ${qtlib} into ${qtplugin_dest_dir}/plugins/${qtdir}
install(FILES "${qtlib}" DESTINATION ${qtplugin_dest_dir}/plugins/${qtdir} COMPONENT Runtime)
else()
message(FATAL_ERROR "Could not find QT plugin ${_qt_plugin_name}")
endif()
endmacro()
if(LYX_BUNDLE)
if(NOT APPLE)
set(installed_lyx_path bin/${_lyx}${CMAKE_EXECUTABLE_SUFFIX})
set(qtplugin_dest_dir bin)
set(qt_conf_path bin/qt.conf)
else()
set(installed_lyx_path ${LYX_BUNDLE_NAME}.app)
set(qtplugin_dest_dir "${LYX_BUNDLE_NAME}.app/Contents")
set(qt_conf_path "${LYX_BUNDLE_NAME}.app/Contents/Resources/qt.conf")
endif()
if(Qt5Core_FOUND)
install_qt_plugin("Qt5::QJpegPlugin")
install_qt_plugin("Qt5::QGifPlugin")
install_qt_plugin("Qt5::QICOPlugin")
if(APPLE)
install_qt_plugin("Qt5::QCocoaIntegrationPlugin")
endif()
else()
# With QT4, just copy all the plugins
file(GLOB QT_PLUGIN_DIRECTORIES "${QT_PLUGINS_DIR}/*")
install(DIRECTORY ${QT_PLUGIN_DIRECTORIES} DESTINATION "${qtplugin_dest_dir}/plugins/" COMPONENT Runtime)
endif()
# Install code does the following:
# - Creates the qt.conf file
# - install the platform specific plugins (with Qt5)
# - Fixup the bundle
install(CODE "include(BundleUtilities)
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qt_conf_path}\" \"\")
file(GLOB_RECURSE QTPLUGINS
\"\${CMAKE_INSTALL_PREFIX}/${qtplugin_dest_dir}/plugins/*/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
message(STATUS \"QT plugins [\${CMAKE_INSTALL_PREFIX}/${qtplugin_dest_dir}/plugins/*/*${CMAKE_SHARED_LIBRARY_SUFFIX}]: \${QTPLUGINS}\")
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${installed_lyx_path}\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIRS}\")"
COMPONENT Runtime
)
if (APPLE AND LYX_DMG)
# Setup the disk image layout
install(CODE "
message(STATUS \"Creating the folder view options (.DS_Store)\")
execute_process(COMMAND /bin/ln -sf /Applications \"\${CMAKE_INSTALL_PREFIX}\")
execute_process(COMMAND /bin/bash \"${CMAKE_CURRENT_SOURCE_DIR}/../../MacOSX/set_bundle_display_options.sh\"
\"${CMAKE_BINARY_DIR}/ds_store\" \"${_lyx}\" \"${TOP_CMAKE_PATH}/../MacOSX/dmg-background.png\" 560 364)
")
endif()
endif()

View File

@ -107,10 +107,6 @@ lyx_find_info_files(LyXCMakeFiles ${TOP_MODULE_PATH}/*)
lyx_find_info_files(LyXCMakeFiles ${TOP_SCRIPT_PATH}/*)
lyx_find_info_files(LyXUiFiles ${TOP_SRC_DIR}/lib/ui/*)
if (APPLE AND LYX_BUNDLE)
include(../Install)
endif()
add_executable(${_lyx}
${WIN32_CONSOLE}
${LYX_BUILD_BUNDLE}
@ -170,22 +166,26 @@ endif()
project_source_group("${GROUP_CODE}" lyx_sources lyx_headers)
install(TARGETS ${_lyx}
RUNTIME DESTINATION bin
BUNDLE DESTINATION .)
install(TARGETS ${_lyx}
BUNDLE DESTINATION . COMPONENT Runtime
RUNTIME DESTINATION bin COMPONENT Runtime)
if(LYX_BUNDLE)
if(NOT APPLE)
set(installed_lyx ${CMAKE_INSTALL_PREFIX}/bin/${_lyx}${CMAKE_EXECUTABLE_SUFFIX})
else()
if(APPLE)
# Now that lyx executable is defined, we can the files that should be included
# directly in the bundle. Note that resources are not copied with this mechanism:
# only the files necessary to run the executable are processed here (LyX.sdef, LyX.icns, etc.)
list(LENGTH OSX_BUNDLE_FILES OSX_BUNDLE_LAST_INDEX)
math(EXPR OSX_BUNDLE_LAST_INDEX "${OSX_BUNDLE_LAST_INDEX} - 1")
foreach(_i RANGE ${OSX_BUNDLE_LAST_INDEX})
list(GET OSX_BUNDLE_FILES ${_i} _file)
list(GET OSX_BUNDLE_DIRS ${_i} _directory)
# Sets the location of the file into the OS X bundle
set_source_files_properties("${_file}" PROPERTIES MACOSX_PACKAGE_LOCATION "${_directory}")
endforeach()
set_target_properties(${_lyx} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_BINARY_DIR}/../Info.plist")
set(installed_lyx ${CMAKE_INSTALL_PREFIX}/${_lyx}.app)
set(LYX_BUNDLE_PROPERTY_MODE "ON")
include("../Install")
endif()
install(CODE "include(BundleUtilities)
fixup_bundle(\"${installed_lyx}\" \"\" \"\") " COMPONENT RUNTIME)
endif()
add_subdirectory(tests)

View File

@ -40,12 +40,5 @@ if(APPLE)
target_link_libraries(${_lyxclient} "-framework AppKit")
endif()
if(LYX_BUNDLE)
install(TARGETS ${_lyxclient}
RUNTIME DESTINATION bin
BUNDLE DESTINATION .)
else()
install(TARGETS ${_lyxclient} DESTINATION bin)
endif()
install(TARGETS ${_lyxclient} DESTINATION ${LYX_UTILITIES_INSTALL_PATH})

View File

@ -65,11 +65,5 @@ project_source_group("${GROUP_CODE}" tex2lyx_sources tex2lyx_headers)
add_subdirectory(test)
if(LYX_BUNDLE)
install(TARGETS ${_tex2lyx}
RUNTIME DESTINATION bin
BUNDLE DESTINATION .)
else()
install(TARGETS ${_tex2lyx} DESTINATION bin)
endif()
install(TARGETS ${_tex2lyx} DESTINATION ${LYX_UTILITIES_INSTALL_PATH})