[CMake] Mac OS Quick Look plugin support

Michael Wild themiwi at gmail.com
Thu Oct 21 08:30:54 EDT 2010


On 21. Oct, 2010, at 10:35 , Tom Vercauteren wrote:

> Hi All,
> 
> I am rather new to Mac OS X and am trying to port a custom file
> preview plugin I had for KDE 4.
> 
> Using CMake and KDE 4, building and installing such a plugin was
> fairly simple, thanks to
>  kio/thumbcreator.h in KDE
> and the
>  kde4_add_plugin function from KDE4Macros.cmake
>  http://websvn.kde.org/trunk/KDE/kdelibs/cmake/modules/KDE4Macros.cmake?view=markup
> 
> Now for Mac OS X, I guess the easiest would be to write a custom Quick
> Look plugin as is done for example at
>  http://groups.google.com/group/dtitk/web/What+does+it+do%3F
> or
>  http://root.cern.ch/viewvc/trunk/misc/rootql/
> 
> All the resources I found so far on the subject rely on using XCode
> which I have no experience with. Also, I'd rather have that my entire
> project could be build using cmake only.
> 
> Is anybody here familiar with building Quick Look plugins from CMake?
> 
> If not, would someone recommend a particular course of action to try
> and call XCode from CMake for this particular matter? Would using
> ExternalProject_Add be the way to go?
>  http://www.kitware.com/products/html/BuildingExternalProjectsWithCMake2.8.html
> 
> Thanks,
> Tom

Creating so-called plugin-bundles is a bit tricky on Mac OS X, see http://public.kitware.com/Bug/view.php?id=11295. For now, I suggest you "hack" it to generate the appropriate bundle by doing something like this:

if(APPLE)
  # HACK make sure that you do this only in a leaf-directory only containing
  # this target, otherwise other libraries will end up with bogus linker flags!
  set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-bundle -headerpad_max_install_names")
  add_library(my_qlgen SHARED src1.cpp src2.cpp)
  set_target_properties(my_qlgen PROPERTIES
    FRAMEWORK TRUE
    MACOSX_FRAMEWORK_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist"
    SUFFIX .qlgenerator)
endif()

The Info.plist file might look like this (for more flexibility you might want to configure_file it):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>CFBundleDevelopmentRegion</key>
        <string>English</string>
        <key>CFBundleDocumentTypes</key>
        <array>
                <!-- List of document types this plugin handles -->
                <dict>
                        <key>CFBundleTypeName</key>
                        <string>My Super Duper Document</string>
                        <key>CFBundleTypeRole</key>
                        <string>QLGenerator</string>
                        <key>LSItemContentTypes</key>
                        <array>
                                <string>org.nowhere.SuperCool.supercool</string>
                        </array>
                </dict>
         </array>
        <key>CFBundleExecutable</key>
        <string>my_qlgen</string>
        <key>CFBundleGetInfoString</key>
        <string>1.0, Copyright 2010 Ty Coon.</string>
        <key>CFBundleIdentifier</key>
        <string>org.nowhere.my_ql_generator</string>
        <key>CFBundleInfoDictionaryVersion</key>
        <string>6.0</string>
        <key>CFBundleName</key>
        <string>My Super Duper QuickLook Generator</string>
        <key>CFBundleShortVersionString</key>
        <string>1.0</string>
        <key>CFBundleVersion</key>
        <string>1</string>
        <key>CFPlugInDynamicRegisterFunction</key>
        <string></string>
        <key>CFPlugInDynamicRegistration</key>
        <string>NO</string>
        <key>CFPlugInFactories</key>
        <dict>  <!-- The UUID identifying your plugin -->
                <key>CC9EF7CC-1F35-4DD3-9AC1-7ECB3515EAF5</key>
                <!-- The factory function, it must return above UUID! -->
                <string>QuickLookGeneratorPluginFactory</string>
        </dict>
        <key>CFPlugInTypes</key>
        <dict>  <!-- Don't change this, it's the UUID identifying QuickLook plugins -->
                <key>5E2D9680-5022-40FA-B806-43349622E5B9</key>
                <array> <!-- The plugin UUID from above -->
                        <string>CC9EF7CC-1F35-4DD3-9AC1-7ECB3515EAF5</string>
                </array>
        </dict>
        <key>CFPlugInUnloadFunction</key>
        <string></string>
        <key>NSHumanReadableCopyright</key>
        <string>© 2010 Ty Coon</string>
        <key>QLNeedsToBeRunInMainThread</key>
        <true/>
        <key>QLPreviewHeight</key>
        <real>600</real>
        <key>QLPreviewWidth</key>
        <real>800</real>
        <key>QLSupportsConcurrentRequests</key>
        <false/>
        <key>QLThumbnailMinimumSize</key>
        <integer>16</integer>
        <array>
                <!-- Register the document types -->
                <dict>
                        <key>UTTypeConformsTo</key>
                        <array>
                                <!-- List of UTIs your file type conforms to -->
                                <string>public.text</string>
                        </array>
                        <key>UTTypeDescription</key>
                        <string>My Super Cool Document Type</string>
                        <key>UTTypeIdentifier</key>
                        <string>org.nowhere.SuperCool.supercool</string>
                        <key>UTTypeTagSpecification</key>
                        <dict>
                                <key>public.filename-extension</key>
                                <array>
                                        <string>supercool</string>
                                </array>
                        </dict>
                </dict>
        </array>
</dict>
</plist>


Also, make sure to read this: http://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/Quicklook_Programming_Guide/Introduction/Introduction.html

HTH

Michael

DISCLAIMER: I never tried to do this myself...

--
There is always a well-known solution to every human problem -- neat, plausible, and wrong.
H. L. Mencken

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
URL: <http://www.cmake.org/pipermail/cmake/attachments/20101021/3f6e8f98/attachment-0001.pgp>


More information about the CMake mailing list