[CMake] How to get Qt shared libraries to install with cmake 2.8.0

Mike Jackson mike.jackson at bluequartz.net
Wed Feb 3 08:06:34 EST 2010


This is what I use. Seems a bit "kludgey" but does seem to work. This
code will copy the Qt dlls into BOTH the Debug and Release build
directories (so debugging works) and create installation rules to copy
the proper dlls into the install location.

# Copy the needed Qt libraries into the Build directory. Also add installation
# and CPack code to support installer generation.
# this is a complete hack for Visual Studio to copy the Qt libraries.
if ( NOT Q_WS_MAC)
    if (DEFINED QT_QMAKE_EXECUTABLE)
        SET (QTLIBLIST QtCore QtGui)

        IF (MSVC)
            set(TYPE "d")
            FOREACH(qtlib ${QTLIBLIST})
              IF (WIN32)
                GET_FILENAME_COMPONENT(QT_DLL_PATH_tmp
${QT_QMAKE_EXECUTABLE} PATH)
                file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug)
                file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release)
                file(MAKE_DIRECTORY
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/MinSizeRel)
                file(MAKE_DIRECTORY
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/RelWithDebInfo)
                INSTALL(FILES ${QT_DLL_PATH_tmp}/${qtlib}${type}d4.dll
                    DESTINATION ./
                    CONFIGURATIONS Debug
                    COMPONENT Applications)
                INSTALL(FILES ${QT_DLL_PATH_tmp}/${qtlib}4.dll
                    DESTINATION ./
                    CONFIGURATIONS Release
                    COMPONENT Applications)
                add_custom_target(ZZ_${qtlib}-Debug-Copy ALL
                            COMMAND ${CMAKE_COMMAND} -E
copy_if_different ${QT_DLL_PATH_tmp}/${qtlib}${TYPE}4.dll
                            ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug/
                            COMMENT "Copying ${qtlib}${TYPE}4.dll to
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug/")
                add_custom_target(ZZ_${qtlib}-Release-Copy ALL
                            COMMAND ${CMAKE_COMMAND} -E
copy_if_different ${QT_DLL_PATH_tmp}/${qtlib}4.dll
                            ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/
                            COMMENT "Copying ${qtlib}4.dll to
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/")
              ENDIF (WIN32)
            ENDFOREACH(qtlib)

        endif()
    endif(DEFINED QT_QMAKE_EXECUTABLE)
endif()
_________________________________________________________
Mike Jackson                  mike.jackson at bluequartz.net
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio



On Wed, Feb 3, 2010 at 4:21 AM,  <Mika.Rajala at patria.fi> wrote:
>
> Hi
>
> I'd like to install the necessary .dll files of Qt to my install directory.
>
> So that when someone installs my program from a package, he gets the
> complete set and doesn't need to install Qt seperately.
>
> Actually my program is multiple programs and i'd rather not link them
> statically to Qt libraries.
>
> FindQt4.cmake doesn't seem to provide any way to get the shared libraries.
>
> Do i need to hack my way through QT_LIBRARY_DIR ?
>
> I fell that i'm missing something here, since such a simple and what i
> think a common task should not include such hacking, right?
>
> Maybe this is different on some linux platform, but on windows i'd rather
> not bother ppl with having to install libraries to make my software work.
>
> I want to make it easy for them.
>
> -mika
>
> _______________________________________________
> 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