[CMake] Mixed linking

Ghyslain Leclerc ghleclerc at gmail.com
Thu Feb 5 15:02:05 EST 2015


Hello,

My apologies for the long post, but I think context helps a little.

We have a set of applications (4 at the moment) which compile against ITK, VTK, DCMTK and Boost.  All of those things are compiled statically.  So is the application.  We are developing on Windows, OS X and Linux boxes, but deploying almost only on Windows, so the cross-platform quality of the libraries is important to us and CMake makes it relatively easy to target all those platform.

Without going into static vs dynamic territory, I’ll say that our choice is based on ease of deployment to the hospital network where IT has lots of control, but we do not.  So far, because of our choice of static linking, deployment is basically renaming the old .exe to keep an archive of all software that has been run clinical, and then put the new executable in place.

We’ve come to the stage where a GUI is something that would be practical.  We have decided to go with Qt.  We would like, if possible, to keep using static linking as a strategy, but as far as I can tell, trying to figure out how to use the new Qt5 macros, static linking of Qt is not exactly supported by CMake.

Here are a few questions for the list (hoping someone more knowledgable than me will read this and help):

1) Am I right when I say CMake, Qt and static linking don’t mix ?

I have tried on OS X.   I have compiled a static version of Qt, making sure I explicitly enable every plugin I need.  Then, I have used the following CMake code :
    find_package( Qt5Widgets )
    find_package( Qt5Sql )

    find_library( COREFOUNDATION_LIBRARY CoreFoundation )
    find_library( COCOA_LIBRARY Cocoa )
    find_library( CARBON_LIBRARY Carbon )
    find_library( WEBKIT_LIBRARY WebKit )
    find_library( IOKIT_LIBRARY IOKit )
    find_library( OPENGL_LIBRARY OpenGL )

    set( CMAKE_INCLUDE_CURRENT_DIR ON )
    set( CMAKE_AUTOMOC ON )

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

    target_link_libraries( calculum ${COREFOUNDATION_LIBRARY} ${COCOA_LIBRARY}
                                    ${OPENGL_LIBRARY} ${CARBON_LIBRARY}
                                    Qt5::Widgets Qt5::Sql "/sw/local/qt/plugins/platforms/libqcocoa.a" 
                                    "/sw/local/qt/lib/libqtharfbuzzng.a" z )

    qt5_use_modules( calculum Widgets Sql )
Even so, the executable won’t run.  I have then tried using the BundleUtilities, but that still won’t work (although I am still figuring things out, so it might be misunderstanding on my part that’s the culprit)


2) If so, we will have to switch to dynamic linking for our GUI applications.  In that case, is there a way to keep statically linking our other libraries (ITK, VTK, etc.) into our application and only dynamically link the Qt stuff ?  If we can’t, it means we’ll have to create dynamic libraries of all our external libraries and link to them.  Deployment will be much harder for us, given that we have zero experience with that.

Can you point me towards some tutorials (or documentation, but sometimes, documentation only gets you so far without examples…) ?

Thanks
Ghyslain





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150205/4e582d83/attachment.html>


More information about the CMake mailing list