mingw-cross-env-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Mingw-cross-env-list] Qt with Cmake


From: Daniel Stonier
Subject: Re: [Mingw-cross-env-list] Qt with Cmake
Date: Tue, 23 Nov 2010 10:59:47 +0900

On 23 November 2010 04:10, Mark Brand <address@hidden> wrote:
>
> On 11/22/2010 12:46 PM, Daniel Stonier wrote:
>>
>> I'm trying to link in the static libs from qt using the usual cmake
>> interface with the FindQt4.cmake module.
>>
>> It doesn't seem to realise itself that it is linking static libs. Nor
>> are the dependencies linking in all the
>> lower libraries (jpeg, mng etc). Has anyone here tried cmake with
>> mingw cross' qt?
>>
>> Cheers,
>> Daniel.
>
> Hi Daniel,
>
> My understanding is that qmake is able to include the static dependencies
> when generating makefiles because it because it reads them out of the .prl
> files in the 'lib' directory. The .prl files themselves are assembled during
> the building of Qt.
>
> Not being very familiar with cmake, I don't know what mechanisms cmake
> supports to identify static dependencies. I did come across this reference
> that seems to be about getting cmake to look at the .prl files:
>
> http://www.cmake.org/pipermail/cmake/2006-August/010547.html
>
> Please let us know what solution you settle on.
>
> Mark

Ok, thanks Mark - I'd already concluded I needed to attack the void
left by cmake in not looking up prl files last night, but that link
saved me some work.

The only odd thing that could probably be nicer on the mingw_cross
side, is /opt/mingw/usr/i686-pc-mingw32/mkspecs/qconfig.pri. Cmake is
looking for the keyword "static" in the CONFIG variable to decide
whether to link dynamically or statically. I'm not sure if this
*should* be there or not - there is nothing about that keyword on
http://doc.trolltech.com/4.7/qmake-variable-reference.html#config, so
this might be a dodgy check in the FindQt4.cmake module.

Ive pasted my macros that wrap the FindQt4.cmake call below for anyone
else who runs into the same problem.

##############################################################
# Qt4
##############################################################
#
# On mingw_cross, system lib deps are in prl files which FindQt4 does
not check,
# this can lead to some shortages in the link dependencies especially when
# statically building. So...if there is prl files to tell us about
this, use them.
#
macro(qt_link_flags_from_prl component)
    string(TOUPPER ${component} COMPONENT_UPPER)
        set(FILE_PRL "NOTFOUND")
        find_file(FILE_PRL ${component}.prl ${QT_LIBRARY_DIR})
        if( FILE_PRL )
                file(READ ${FILE_PRL} PRL_CONTENTS) # Read .prl file
                string(REGEX MATCH "QMAKE_PRL_LIBS.+" PRL_LINE ${PRL_CONTENTS}) 
#
Extract the line with linking flags
                string(REGEX REPLACE "-l" "" PRL_LINE ${PRL_LINE}) # Remove 
link flag symbols
                string(REGEX REPLACE "QMAKE_PRL_LIBS" "" PRL_LINE ${PRL_LINE}) #
Remove non links
                string(REGEX REPLACE "=" "" PRL_LINE ${PRL_LINE}) # Remove non 
links
                string(REGEX MATCHALL "[^ \t\n]+" PRL_LINK_FLAGS ${PRL_LINE}) #
Split the line by whitespaces
                # Don't double up in QT_LIBRARIES
                if(PRL_LINK_FLAGS)
                list(REMOVE_ITEM QT_LIBRARIES ${PRL_LINK_FLAGS})
                list(APPEND QT_LIBRARIES ${PRL_LINK_FLAGS})
                if(QT_${COMPONENT_UPPER}_LIB_DEPENDENCIES)
                        list(REMOVE_ITEM QT_${COMPONENT_UPPER}_LIB_DEPENDENCIES
${PRL_LINK_FLAGS})
                endif()
                list(APPEND QT_${COMPONENT_UPPER}_LIB_DEPENDENCIES 
${PRL_LINK_FLAGS})
        endif()
        endif( FILE_PRL )
endmacro()
#
# Is a wrapper around FindQt4.cmake.
#
# Mostly this is needed to satisfy a static mingw cross compile of qt,
(mingw_cross)
# as the cmake FindQt4 handles this poorly. Call with the components
you want to
# compile for, e.g.
#
#     eros_prepare_qt4(QtGui QtCore)
#
# What this macro does:
#
# - calls the underlying FindQt4.cmake module.
# - if compiling statically
#   - turns off -DQT_DLL if it's accidentally left on.
#   - checks to see if there are .prl's which can fill out the lib dependencies.
macro(eros_prepare_qt4)
    if ( ARGC GREATER 0 )
        find_package(Qt4 COMPONENTS ${ARGV})
    else()
        find_package(Qt4)
    endif()

    # This is needed on my ubuntu (cmake 2.8.0), but not on gentoo (cmake 2.8.1)
    # Probably later this can be dropped as it is done in 2.8.1+
    if(QT_IS_STATIC)
        list(REMOVE_ITEM QT_DEFINITIONS -DQT_DLL)
    endif()

    include(${QT_USE_FILE})
    include_directories(${CMAKE_CURRENT_BINARY_DIR}) # Needed to pick
up ui files in build dir

    if(QT_IS_STATIC)
        if(QT_USE_QAXCONTAINER)
            qt_link_flags_from_prl(QAxContainer)
        endif()
        if(QT_USE_QAXSERVER)
            qt_link_flags_from_prl(QAxServer)
        endif()
        if(QT_USE_QT3SUPPORT)
            qt_link_flags_from_prl(Qt3Support)
        endif()
        if(QT_USE_QTCORE)
            qt_link_flags_from_prl(QtCore)
        endif()
        if(QT_USE_QTGUI)
            qt_link_flags_from_prl(QtGui)
        endif()
        if(QT_USE_QTMAIN)
            qt_link_flags_from_prl(qtmain)
        endif()
        if(QT_USE_QTMULTIMEDIA)
            qt_link_flags_from_prl(QtMultimedia)
        endif()
        if(QT_USE_QTNETWORK)
            qt_link_flags_from_prl(QtNetwork)
        endif()
        if(QT_USE_QTOPENGL)
            qt_link_flags_from_prl(QtOpenGL)
        endif()
        if(QT_USE_QTSCRIPT)
            qt_link_flags_from_prl(QtScript)
        endif()
        if(QT_USE_QTSCRIPTTOOLS)
            qt_link_flags_from_prl(QtScriptTools)
        endif()
        if(QT_USE_QTSQL)
            qt_link_flags_from_prl(QtSql)
        endif()
        if(QT_USE_QTSVG)
            qt_link_flags_from_prl(QtSvg)
        endif()
        if(QT_USE_QTTEST)
            qt_link_flags_from_prl(QtTest)
        endif()
        if(QT_USE_QTWEBKIT)
            qt_link_flags_from_prl(QtWebKit)
        endif()
        if(QT_USE_QTXMLPATTERNS)
            qt_link_flags_from_prl(QtXmlPatterns)
        endif()
        if(QT_USE_QTXML)
            qt_link_flags_from_prl(QtXml)
        endif()
    endif()
endmacro()




-- 
Phone : +82-10-5400-3296 (010-5400-3296)
Home: http://snorriheim.dnsdojo.com/
Yujin Robot: http://www.yujinrobot.com/
Embedded Ros : http://www.ros.org/wiki/eros
Embedded Control Libraries: http://snorriheim.dnsdojo.com/redmine/wiki/ecl



reply via email to

[Prev in Thread] Current Thread [Next in Thread]