[CMake] [CMAKE] fixup_bundle problem with qt plugins

Michael Jackson mike.jackson at bluequartz.net
Wed Apr 28 09:33:22 EDT 2010


This is what I use. Note that this gets "configured" by cmake first.  
Pay Attention to the notes in the file as the use case is _very_  
specific.

#----------------- Start ----------------------------------
message (STATUS "#------------ Starting OS X Bundle Fixup  
--------------------------")
cmake_minimum_required(VERSION 2.6)

#-- Need this for link line stuff?
if(COMMAND cmake_policy)
   cmake_policy(SET CMP0009 NEW)
endif(COMMAND cmake_policy)


if (${CMAKE_VERSION} VERSION_GREATER 2.6.2)
if(COMMAND cmake_policy)
   cmake_policy(SET CMP0011 NEW)
endif(COMMAND cmake_policy)
endif()

# gp_item_default_embedded_path item default_embedded_path_var
#
# Return the path that others should refer to the item by when the item
# is embedded inside a bundle.
#
# Override on a per-project basis by providing a project-specific
# gp_item_default_embedded_path_override function.
#
function(gp_item_default_embedded_path_override item  
default_embedded_path_var)
   #
   # The assumption here is that all executables in the bundle will be
   # in same-level-directories inside the bundle. The parent directory
   # of an executable inside the bundle should be MacOS or a sibling of
   # MacOS and all embedded paths returned from here will begin with
   # "@executable_path/../" and will work from all executables in all
   # such same-level-directories inside the bundle.
   #

   # By default, embed things right next to the main bundle executable:
   #
   set(path "@executable_path/../../Contents/MacOS")

   set(overridden 0)
   # For Qt Based Plugins for the image formats, the plugins MUST  
reside in
   # the "PlugIns/imageformats" directory. Since THIS particular  
project ONLY has
   # the Qt Frameworks AND the plugins the below regex will suffice to  
separate
   # them from each other. On other projects we could use better logic  
to
   # put things where they go. Maybe using some "configured" CMake  
List of libraries
   # then looking through each list for the currect library being  
fixed up.
   # Embed .dylibs right next to the main bundle executable:
   #
   if(item MATCHES "\\.dylib$")
     set(path "@executable_path/../PlugIns/imageformats")
     set(overridden 1)
   endif(item MATCHES "\\.dylib$")

   # Embed .so right next to the main bundle executable:
   #
   if(item MATCHES "\\.so$")
     set(path "@executable_path/../Plugins/imageformats")
     set(overridden 1)
   endif(item MATCHES "\\.so$")

   # Embed frameworks in the embedded "Frameworks" directory (sibling  
of MacOS):
   #
   if(NOT overridden)
     if(item MATCHES "[^/]+\\.framework/")
       set(path "@executable_path/../Frameworks")
       set(overridden 1)
     endif(item MATCHES "[^/]+\\.framework/")
   endif(NOT overridden)

   set(${default_embedded_path_var} "${path}" PARENT_SCOPE)
endfunction(gp_item_default_embedded_path_override)


#-- Be sure all the internal directories are created first before  
calling the 'fixup_bundle'
#file(MAKE_DIRECTORY "@CMAKE_INSTALL_PREFIX@/@target at .app/Contents/ 
Libraries")
file(MAKE_DIRECTORY "@CMAKE_INSTALL_PREFIX@/@target at .app/Contents/ 
Plugins")
file(MAKE_DIRECTORY "@CMAKE_INSTALL_PREFIX@/@target at .app/Contents/ 
Frameworks")
#file(MAKE_DIRECTORY "@CMAKE_INSTALL_PREFIX@/@target at .app/Contents/ 
Support")

#--------------------------------------------------------------------------------
# install a qt.conf file
# this inserts some cmake code into the install script to write the file
file(WRITE "@CMAKE_INSTALL_PREFIX@/@target at .app/Contents/Resources/ 
qt.conf" "")

#-- Check for Qt4 stuff
if ("@QT_MAC_USE_COCOA@" STREQUAL "1")
   message(STATUS "Copying qt_menu.nib into @target at .app/Contents/ 
Resources")
   file(MAKE_DIRECTORY "@CMAKE_INSTALL_PREFIX@/@target at .app/Contents/ 
Resources/qt_menu.nib")
   execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory  
"@QT_LIBRARY_DIR@/QtGui.framework/Resources/qt_menu.nib"  
"@CMAKE_INSTALL_PREFIX@/@target at .app/Contents/Resources/qt_menu.nib")
endif()

set (QTPLUGINS "@QTPLUGINS@")

# -- Run the BundleUtilities cmake code
include(BundleUtilities)
fixup_bundle("@CMAKE_INSTALL_PREFIX@/@target at .app" "${QTPLUGINS}"  
"@QT_PLUGINS_DIR@/imageformats")

message (STATUS "#------------ End OS X Bundle Fixup  
--------------------------")
#----------------- END ----------------------------------
___________________________________________________________
Mike Jackson                      www.bluequartz.net
Principal Software Engineer       mike.jackson at bluequartz.net
BlueQuartz Software               Dayton, Ohio


On Apr 28, 2010, at 6:29 AM, Martin Guillon wrote:

> Hi,
>
> I am having problems using fixup_bundle with qt plugins
>
> I use that code
> install(CODE "
>       # glob for previously installed qt plugins to include in  
> fixup_bundle
>        file(GLOB_RECURSE QTPLUGINS
>      \"${${TARGET_NAME}_OUTPUTPLUGINSDIR}/*$ 
> {CMAKE_SHARED_LIBRARY_SUFFIX}\")
>        include(BundleUtilities)
>        fixup_bundle(\"${APPS}\" \"\${QTPLUGINS}\" \"${DIRS}\")"
>        )
> where \"${${TARGET_NAME}_OUTPUTPLUGINSDIR} points to myapp.app/ 
> Contents/Plugins
>
> so inside it I have that  myapp.app/Contents/Plugins/imageformats/ …
>
> The fixup_bundle scripts corrects those files correctly but my big  
> problem is that it copies the corrected files in that  myapp.app/ 
> Contents/MacOS
>
> My first question is why???
>
> And the most important question is can I make it so that It corrects  
> the dylibs but does not move them?
> The problem with copying files is that now  imageformats dylibs are  
> directly in MacOS and so no way to make qt load them at startup.
>
> Thanks
>
> Martin
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list