[LyX/master] CMake install and bundling improvements (esp. OS X)

2014-04-21 Thread Richard Heck
commit 14de3aa49b4fb38093ff12ccaf3200daf0f62c77
Author: Benjamin Piwowarski benja...@bpiwowar.net
Date:   Sun Mar 9 10:21:51 2014 +0100

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

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fce4bed..f68222a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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 

[LyX/master] CMake install and bundling improvements (esp. OS X)

2014-04-21 Thread Richard Heck
commit 14de3aa49b4fb38093ff12ccaf3200daf0f62c77
Author: Benjamin Piwowarski 
Date:   Sun Mar 9 10:21:51 2014 +0100

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

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fce4bed..f68222a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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