From b5ce5d2d67b7c0fbb4c9ee780077ad4f0efee35c Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Mon, 17 Nov 2014 14:16:19 +0100 Subject: [PATCH] CMake: refactoring in CPack/Apple --- CMakeLists.txt | 2 +- Core/CMakeLists.txt | 50 +++++++++++++------ GUI/coregui/CMakeLists.txt | 2 +- GUI/main/CMakeLists.txt | 33 +++++++----- cmake/CMakeLists.txt | 2 +- ...undle.cmake.in => FixAppleBundle.cmake.in} | 43 +++++++++++++--- cmake/modules/bundle.cmake.in | 21 -------- 7 files changed, 93 insertions(+), 60 deletions(-) rename cmake/modules/{FixBundle.cmake.in => FixAppleBundle.cmake.in} (81%) delete mode 100644 cmake/modules/bundle.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 7704c813d58..e10b3f3991f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ option(BORNAGAIN_APP "Build test application" OFF) option(BORNAGAIN_GUI "Build a graphical user interface" OFF) option(BORNAGAIN_MAN "Build a user manual" OFF) option(BUILD_DEBIAN "Build a debian package" OFF) -option(CREATE_BUNDLE "Create a Mac OS X bundle" OFF) +option(BORNAGAIN_APPLE_BUNDLE "Create a Mac OS X bundle" OFF) option(ROOT_SUPPORT "Build with dependencies from ROOT" ON) option(BORNAGAIN_OPENMPI "Build with OpenMPI support" OFF) option(BORNAGAIN_RELEASE "Special option for making release" OFF) diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index c8164c7b373..37fdc3743a3 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -149,22 +149,40 @@ else() DESTINATION ${destination_libexec}) # creating bin directory for links - install(CODE " - FILE(MAKE_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/${destination_bin}\") - " COMPONENT Runtime) - - # making links - install(CODE " - execute_process(COMMAND \${CMAKE_COMMAND} -E create_symlink - \"../libexec/${destination_suffix}/frombin_setup_paths.sh\" \"thisbornagain.sh\" - WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/${destination_bin}\") - " COMPONENT Runtime) - - install(CODE " - execute_process(COMMAND \${CMAKE_COMMAND} -E create_symlink - \"../libexec/${destination_suffix}/frombin_setup_paths.csh\" \"thisbornagain.csh\" - WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/${destination_bin}\") - " COMPONENT Runtime) +# install(CODE " +# FILE(MAKE_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/${destination_bin}\") +# " COMPONENT Runtime) + +# # making links +# install(CODE " +# execute_process(COMMAND \${CMAKE_COMMAND} -E create_symlink +# \"../libexec/${destination_suffix}/frombin_setup_paths.sh\" \"thisbornagain.sh\" +# WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/${destination_bin}\") +# " COMPONENT Runtime) + +# install(CODE " +# execute_process(COMMAND \${CMAKE_COMMAND} -E create_symlink +# \"../libexec/${destination_suffix}/frombin_setup_paths.csh\" \"thisbornagain.csh\" +# WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/${destination_bin}\") +# " COMPONENT Runtime) + +# install(CODE " +# FILE(MAKE_DIRECTORY \"${destination_bin}\") +# " COMPONENT Runtime) + +# # making links +# install(CODE " +# execute_process(COMMAND \${CMAKE_COMMAND} -E create_symlink +# \"../libexec/${destination_suffix}/frombin_setup_paths.sh\" \"thisbornagain.sh\" +# WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/${destination_bin}\") +# " COMPONENT Runtime) + +# install(CODE " +# execute_process(COMMAND \${CMAKE_COMMAND} -E create_symlink +# \"../libexec/${destination_suffix}/frombin_setup_paths.csh\" \"thisbornagain.csh\" +# WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/${destination_bin}\") +# " COMPONENT Runtime) + endif() diff --git a/GUI/coregui/CMakeLists.txt b/GUI/coregui/CMakeLists.txt index 8f0edabe587..f28f80711e2 100644 --- a/GUI/coregui/CMakeLists.txt +++ b/GUI/coregui/CMakeLists.txt @@ -129,7 +129,7 @@ target_link_libraries(${library_name} ${ManhattanStyle_LIBRARY} ${qcustomplot_LIBRARY} ${qtpropertybrowser_LIBRARY} - ${PYTHON_LIBRARY} + ${PYTHON_LIBRARIES} ${Boost_LIBRARIES} ${BornAgainCore_LIBRARY} ${BornAgainFit_LIBRARY} diff --git a/GUI/main/CMakeLists.txt b/GUI/main/CMakeLists.txt index 55adc4d6cc3..5e07eec9cb2 100644 --- a/GUI/main/CMakeLists.txt +++ b/GUI/main/CMakeLists.txt @@ -59,7 +59,7 @@ target_link_libraries(${executable_name} ${ManhattanStyle_LIBRARY} ${qcustomplot_LIBRARY} ${qtpropertybrowser_LIBRARY} - ${PYTHON_LIBRARY} + ${PYTHON_LIBRARIES} ${Boost_LIBRARIES} ${BornAgainCore_LIBRARY} ${BornAgainFit_LIBRARY} @@ -94,21 +94,17 @@ elseif(APPLE) MACOSX_BUNDLE_INFO_PLIST ${destination_runtime_configs}/Info.plist ) -#install ( FILES ${CMAKE_SOURCE_DIR}/GUI/main/BornAgain.icns -# DESTINATION ${INBUNDLE}/Contents/Resources/ -#) - -##set ( CPACK_DMG_BACKGROUND_IMAGE ${CMAKE_SOURCE_DIR}/Images/osx-bundle-background.png ) -##set ( CPACK_DMG_DS_STORE ${CMAKE_SOURCE_DIR}/Installers/MacInstaller/osx_DS_Store) -#set ( MACOSX_BUNDLE_ICON_FILE BornAgain.icns ) -#SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/GUI/main/BornAgain.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources) - + set(link_flags "-Wl,-rpath,@loader_path/../") + set_target_properties(${executable_name} + PROPERTIES + LINK_FLAGS ${link_flags} + ) endif() # --- installation --------- #install (TARGETS ${executable_name} DESTINATION ${destination_gui} COMPONENT Applications) -install (TARGETS ${executable_name} BUNDLE DESTINATION . RUNTIME DESTINATION ${destination_gui} COMPONENT Applications) +install (TARGETS ${executable_name} BUNDLE DESTINATION . COMPONENT Applications) # install (TARGETS ${executable_name} # BUNDLE DESTINATION . COMPONENT Applications @@ -119,13 +115,26 @@ set(image_files ${CMAKE_SOURCE_DIR}/GUI/main/BornAgain.ico ${CMAKE_SOURCE_DIR}/G install (FILES ${image_files} DESTINATION ${destination_images} COMPONENT Applications) +# --- system dependent installation --------- if(WIN32) -elseif(APPLE) +elseif(APPLE AND BORNAGAIN_APPLE_BUNDLE) install( FILES ${CMAKE_SOURCE_DIR}/GUI/main/BornAgain.icns DESTINATION ${destination_bundle}/Contents/Resources/ ) + set(plugin_dest_dir ${destination_bundle}/Contents/PlugIns) + install(DIRECTORY "$ENV{QTDIR}/plugins/platforms" DESTINATION ${plugin_dest_dir} COMPONENT Runtime) + + set(fixup_path @rpath) + configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/FixAppleBundle.cmake.in ${destination_runtime_configs}/FixAppleBundle.cmake @ONLY) + install(SCRIPT ${destination_runtime_configs}/FixAppleBundle.cmake COMPONENT Runtime) + +# get_filename_component(PYTHON_REAL_LIBRARY "${PYTHON_LIBRARY}" REALPATH) +# add_library(Python SHARED IMPORTED) +# set_property(TARGET Python PROPERTY IMPORTED_LOCATION ${PYTHON_LIBRARY}) +# message("XXXXXX PYTHON_LIBRARY:${PYTHON_LIBRARY} PYTHON_REAL_LIBRARY:${PYTHON_REAL_LIBRARY} PYTHON_LIBRARIES:${PYTHON_LIBRARIES}") + endif() diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 6b74f93a9e1..df9b9904522 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -1,6 +1,6 @@ # this script is a trick to print the message at the end of installation -if(NOT WIN32 AND NOT CREATE_BUNDLE) +if(NOT WIN32 AND NOT BORNAGAIN_APPLE_BUNDLE) set(after_install_text " Installation done. Please read below. ------------------------------------------------------------------------------- diff --git a/cmake/modules/FixBundle.cmake.in b/cmake/modules/FixAppleBundle.cmake.in similarity index 81% rename from cmake/modules/FixBundle.cmake.in rename to cmake/modules/FixAppleBundle.cmake.in index 5fc3195bf25..562fa112542 100644 --- a/cmake/modules/FixBundle.cmake.in +++ b/cmake/modules/FixAppleBundle.cmake.in @@ -1,5 +1,8 @@ -set ( bundle ${CMAKE_INSTALL_PREFIX}/BornAgain.app ) +set(bundle ${CMAKE_INSTALL_PREFIX}/BornAgain.app ) +set(bornagain_libs ${CMAKE_INSTALL_PREFIX}/@destination_lib@) +set(thirdparty_libs ${CMAKE_INSTALL_PREFIX}/@destination_lib@) + #set(GP_RPATH_DIR ${bundle}/Contents) set(BU_CHMOD_BUNDLE_ITEMS True) @@ -28,17 +31,13 @@ function(gp_resolved_file_type_override resolved_file type_var) set(${type_var} embedded PARENT_SCOPE) elseif(item MATCHES "PlugIns/platforms") - message("XXX resolving file as _embedded : ${file}") + message("XXX3 resolving file as _embedded : ${file}") set(${type_var} embedded PARENT_SCOPE) - elseif(file MATCHES "Python.framework/Resources") - message("XXX resolving file as _embedded : ${file}") + elseif(file MATCHES "Python.framework") + message("XXX resolving file as system : ${file}") set(${type_var} system PARENT_SCOPE) - elseif(file MATCHES "Python.framework/Versions") - message("XXX resolving file as _embedded : ${file}") - set(${type_var} embedded PARENT_SCOPE) - elseif(file MATCHES "/opt") message("XXX resolving file as _embedded : ${file}") set(${type_var} embedded PARENT_SCOPE) @@ -163,6 +162,7 @@ message("QQQQ QTPLUGINS ${QTPLUGINS} dirs ${dirs}") fixup_bundle ( "${bundle}" "${other_libs}" "${dirs}" ) # This will fix up the dependencies for the hard dependencies: MantidKernel etc + #################################################### # Functions to change the dependency references #################################################### @@ -174,3 +174,30 @@ function( change_bundle_dep old_dep new_dep sharedlib ) execute_process(COMMAND install_name_tool -change ${old_dep} ${new_dep} ${sharedlib}) endfunction() + +function(fix_python_framework items_to_fix) + foreach(item ${items_to_fix}) + message("XXXXXXXX -> fixing item ${item}") + get_prerequisites(${item} prereqs 0 0 "" "") + foreach(pr ${prereqs}) + if(pr MATCHES "Python.framework") + message("XXXXXXXX ${pr}") + change_bundle_dep( ${pr} "@rpath/lib/ThirdParty/libpython2.7.dylib" ${item}) + endif() + endforeach() + endforeach() +endfunction() + + +set(items_to_fix "${bundle}/Contents/MacOs/BornAgain") +file (GLOB items ${bornagain_libs}/*.so) +list(APPEND items_to_fix ${items}) +file (GLOB items ${bundle}/Contents/lib/ThirdParty/*.dylib) +list(APPEND items_to_fix ${items}) + +message("AAA ${items_to_fix}") + +fix_python_framework("${items_to_fix}") + +message("Copying library @PYTHON_LIBRARIES@") +execute_process(COMMAND ${CMAKE_COMMAND} -E copy "@PYTHON_LIBRARIES@" "${bundle}/Contents/lib/ThirdParty/libpython2.7.dylib") diff --git a/cmake/modules/bundle.cmake.in b/cmake/modules/bundle.cmake.in deleted file mode 100644 index 96d72efd312..00000000000 --- a/cmake/modules/bundle.cmake.in +++ /dev/null @@ -1,21 +0,0 @@ - - - - -message(STATUS "aaaa @INBUNDLE@") - -set(BU_CHMOD_BUNDLE_ITEMS True) -set(BU_COPY_FULL_FRAMEWORK_CONTENTS False) - -set(plugin_dest_dir @INBUNDLE@/Contents/PlugIns) -set(qtconf_dest_dir @INBUNDLE@/Contents/Resources) -set(APPS @CMAKE_INSTALL_PREFIX@/@INBUNDLE@) - - -file(GLOB_RECURSE QTPLUGINS "@CMAKE_INSTALL_PREFIX@/${plugin_dest_dir}/*@CMAKE_SHARED_LIBRARY_SUFFIX@") -message("AAAAA QTPLUGINS ${QTPLUGINS}") -message("AAAAA QTPLUGINS ${QTPLUGINS}") - -include(BundleUtilities) -fixup_bundle(${APPS} "${QTPLUGINS}" "@DIRS@") - -- GitLab