[CMake] Mixed linking

Ghyslain Leclerc ghleclerc at gmail.com
Tue Feb 10 23:01:35 EST 2015


Stephen Kelly wrote: 
Ah, right the platform plugin issue. This is likely the reason for not 
running on OSX. 

CMake 3.1 learned a new feature specifically so that this would become 
easier in the future: 

http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/7970 

qmake generates a file like the above for you and compiles it and links it 
into your application for you in the static version. 

With 

http://www.cmake.org/cmake/help/v3.1/prop_tgt/INTERFACE_SOURCES.html 

Qt can do the same, but someone would have to patch Qt to do so. Something 
for the future... :) 



Thanks for all the insight.  I have been looking at this and quite a few posts (mostly from you !) to try and understand.  I think I get most of it.

That being said, I finally got a static executable for my application on my mac. What I did is build my application using qmake, get the linker command and manually find every library using cmake in order to recreate the linker command from qmake (I don’t think it makes a difference, but I’m not sure so I even kept the library order the same).  For my application, this is what did it ended up with (some boiler plate removed).

find_package( Qt5 COMPONENTS Widgets Sql PrintSupport REQUIRED )

find_library( DISKARBITRATION_LIBRARY DiskArbitration )
find_library( IOKIT_LIBRARY IOKit )
find_library( APPLICATIONSERVICES_LIBRARY ApplicationServices )
find_library( CORESERVICES_LIBRARY CoreServices )
find_library( COREFOUNDATION_LIBRARY CoreFoundation )
find_library( FOUNDATION_LIBRARY Foundation )
find_library( COCOA_LIBRARY Cocoa )
find_library( CARBON_LIBRARY Carbon )

find_library( OPENGL_LIBRARY OpenGL )

add_executable( calculum ${SRCS_LIST} ${UIS_LIST} ${HDRS_LIST} )

set( QT_INSTALL_DIR_GL "/sw/local/qt/" )
find_library( QCOCOA qcocoa
    PATHS "${QT_INSTALL_DIR_GL}/plugins/platforms" )

find_library( QDDS qdds
    PATHS "${QT_INSTALL_DIR_GL}/plugins/imageformats" )
find_library( QICNS qicns
    PATHS "${QT_INSTALL_DIR_GL}/plugins/imageformats" )
find_library( QICO qico
    PATHS "${QT_INSTALL_DIR_GL}/plugins/imageformats" )
find_library( QJP2 qjp2
    PATHS "${QT_INSTALL_DIR_GL}/plugins/imageformats" )
find_library( QMNG qmng
    PATHS "${QT_INSTALL_DIR_GL}/plugins/imageformats" )
find_library( QTGA qtga
    PATHS "${QT_INSTALL_DIR_GL}/plugins/imageformats" )
find_library( QTIFF qtiff
    PATHS "${QT_INSTALL_DIR_GL}/plugins/imageformats" )
find_library( QWBMP qwbmp
    PATHS "${QT_INSTALL_DIR_GL}/plugins/imageformats" )
find_library( QWEBP qwebp
    PATHS "${QT_INSTALL_DIR_GL}/plugins/imageformats” )

# Note, GL are my initials.  It was just to ensure no conflicts in names.  Probably not necessary


target_link_libraries( calculum
                       ${DISKARBITRATION_LIBRARY}
                       ${IOKIT_LIBRARY}
                       ${APPLICATIONSERVICES_LIBRARY}
                       ${CORESERVICES_LIBRARY}
                       ${COREFOUNDATION_LIBRARY}
                       ${FOUNDATION_LIBRARY}
                       ${COCOA_LIBRARY}
                       ${CARBON_LIBRARY}
                       Qt5::Sql
                       ${QCOCOA}
                       cups
                       /sw/local/qt/lib/libQt5PlatformSupport.a
                       ${OPENGL_LIBRARY}
                       Qt5::PrintSupport
                       Qt5::Widgets
                       ${QDDS}
                       ${QICNS}
                       ${QICO}
                       ${QJP2}
                       ${QMNG}
                       ${QTGA}
                       ${QTIFF}
                       ${QWBMP}
                       ${QWEBP}
                       Qt5::Gui
                       Qt5::Core
                       z
                       m )

This seems like a lot of work to get what I want…  But if it does the job.  The fun part will be to see what I need on Windows and then put conditionals around that and all.

If I misunderstood something and there is an easier way to get a static executable from using static qt from CMake, please let me know.  I am posting this in case someone searches for information on how to link static Qt using CMake.  The title of my mail said Mixed linking, but it should probably really say static linking Qt5 using CMake, but I don’t know how to change it (I have seen on the list the formerly was …, but not sure if it’s appropriate or how to do it).

Again, thanks for giving a bit of your time.  Really appreciated.

Ghyslain



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150210/5b2916a6/attachment.html>


More information about the CMake mailing list