Re: [CMake] Mixed linking

2015-02-21 Thread Ray Donnelly
On Sat, Feb 21, 2015 at 9:59 AM, Stephen Kelly  wrote:
> Ray Donnelly wrote:
>
>>> >
>>> > 1) Am I right when I say CMake, Qt and static linking don’t mix ?
>>>
>>> They should mix fine.
>
> What I meant when I wrote this was 'they should mix fine, but some
> convenience is not available - you need to specify the correct link flags
> yourself'.
>
> That is, it's 'fine' in the same way that other static libraries which don't
> provide any cmake files at all are 'fine' and leave everything to you.
>

Right, thanks Steve. When/if I get time, I might try to make some new
patches for this for Qt5 and CMake that aren't reliant on MSYS2's many
Qt5 patches and test them on OS X and GNU/Linux.

> Thanks,
>
> Steve.
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: 
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more 
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at 
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Mixed linking

2015-02-21 Thread Stephen Kelly
Ray Donnelly wrote:

>> >
>> > 1) Am I right when I say CMake, Qt and static linking don’t mix ?
>>
>> They should mix fine.

What I meant when I wrote this was 'they should mix fine, but some 
convenience is not available - you need to specify the correct link flags 
yourself'. 

That is, it's 'fine' in the same way that other static libraries which don't 
provide any cmake files at all are 'fine' and leave everything to you.

Thanks,

Steve.


-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Mixed linking

2015-02-21 Thread Stephen Kelly
Ghyslain Leclerc wrote:

> 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).

Yes, I think it makes a difference. It also makes a difference whether 
find_library finds the exact same binary which Qt statically links or not. 

The inability to determine which static library (by exact path) is linked by 
the Qt libraries is the reason the Qt5 CMake files don't list the static 
libraries in their INTERFACE_LINK_LIBRARIES. Your find_library calls are not 
a fully generic solution because find_library might find a different binary 
to what Qt is linked to.

> 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.

What I referred to with INTERFACE_SOURCES was just about automatically 
linking in the platform plugin in a static build.  That is provided by Qt, 
so ew know the full path, but we need to generate a file which you compile 
into the executable so that your executable uses a symbol from it. Otherwise 
the linker discards it. So my message was just saying that that part can be 
made simpler.

Thanks,

Steve.


-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Mixed linking

2015-02-10 Thread Ghyslain Leclerc

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



-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/openso

Re: [CMake] Mixed linking

2015-02-06 Thread Norbert Pfeiler
>
> Norbert Pfeiler wrote:
> > Currently you have to define »QT_STATIC«
> You shouldn't need to do this. If you use MSYS2's
> mingw-w64-{i686,x86_64}-qt5-static then that will be defined for you.


I have both *-qt5 (for dev) and *-qt5-static (for deploy) installed and
append the root of qt5-static to CMAKE_PREFIX_PATH for cmake to prefer the
static to the shared version.
QT_STATIC is not defined in this case.

Norbert Pfeiler wrote:
> > For Windows it’s like this:
> >
> > #if defined(Q_OS_WIN) && defined(QT_STATIC)
> > #include 
> > Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
> > #endif
> Again, if you use MSYS2's mingw-w64-{i686,x86_64}-cmake then you
> should not need to do this either, because of


This is also not the case in the configuration above.
I don’t have to explicitly link the platform plugin though (after adding
Q_IMPORT_PLUGIN).

These 2 additions are way less of a hassle than having to rename *.lib to
*.a in all the qt cmake files and explicitly specifying all transitive qt
link deps, which was necessary before.
So thanks for your work.

Looking forward to:

> > They should mix fine.


Best, Norbert.
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Mixed linking

2015-02-06 Thread Stephen Kelly
Norbert Pfeiler wrote:

>>
>> But I just don't know how to include the plugins.  Actually, I always get
>> the error about the platform plugin (cocoa in my case).  Any tips ?
> 
> 
> For Windows it’s like this:
> 
> #if defined(Q_OS_WIN) && defined(QT_STATIC)
> #include 
> Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
> #endif

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,

Steve.


-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Mixed linking

2015-02-06 Thread Norbert Pfeiler
>
> But I just don't know how to include the plugins.  Actually, I always get
> the error about the platform plugin (cocoa in my case).  Any tips ?


For Windows it’s like this:

#if defined(Q_OS_WIN) && defined(QT_STATIC)
#include 
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
#endif

Best, Norbert.
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Mixed linking

2015-02-06 Thread Ghyslain Leclerc
Hello again.  Thanks for the answers.

To Stephen Kelly:

>> 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 ?

>They should mix fine.

Alright, I won't give up just yet.  :-)

>> 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 :

>I recommend starting with a minimal testcase, make sure it runs, and add
>things until it doesn't. Find the change that breaks.

Thanks for the suggestion.  Just did.  Here is the code for CMake:

# Some definitions to setup Qt
set( CMAKE_INCLUDE_CURRENT_DIR ON )
set( CMAKE_AUTOMOC ON )
set( QT_STATIC TRUE )
add_definitions( -DQT_STATIC )
if( "${CMAKE_BUILD_TYPE}" MATCHES Release )
   add_definitions(-DQT_NO_DEBUG_OUTPUT)
endif()


# Find Qt packages
find_package( Qt5Widgets )

# Find Qt dependencies
find_library( COREFOUNDATION_LIBRARY CoreFoundation )
find_library( COCOA_LIBRARY Cocoa )
find_library( CARBON_LIBRARY Carbon )
find_library( OPENGL_LIBRARY OpenGL )


include_directories( ${CMAKE_CURRENT_LIST_DIR} )
add_executable( helwrld main.cpp )
target_link_libraries( helwrld  Qt5::Widgets ${COREFOUNDATION_LIBRARY}
 ${COCOA_LIBRARY}
 ${CARBON_LIBRARY}
 ${OPENGL_LIBRARY}

"/sw/local/qt/lib/libqtharfbuzzng.a"
 z )



And here is the main.cpp file


#include 
#include 

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
return a.exec();
}

Don't know how to make it simpler.  Using the code compiles and links,
but still won't run.  Maybe my Qt static compilation was missing
something.  I will try and look into that.


To Norbert Pfeiler :

> Currently you have to define ?QT_STATIC? and explicitly include your
> required plugins in the code to get it working.

Thanks for the tips.  I looked up and now define QT_STATIC.  But I
just don't know how to include the plugins.  Actually, I always get
the error about the platform plugin (cocoa in my case).  Any tips ?

Thank you to all !
Ghyslain
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake


Re: [CMake] Mixed linking

2015-02-05 Thread Norbert Pfeiler
Hey,

to build a static qt executable for windows you may be interested in using
msys2.
It offers a prepackaged static qt5 with patches for static linking with
cmake (as the official files are a bit broken for mingw).
Currently you have to define »QT_STATIC« and explicitly include your
required plugins in the code to get it working.
In our case we only link statically on windows, on linux and mac we deploy
the dynamic libraries.

Best, Norbert.
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Mixed linking

2015-02-05 Thread Stephen Kelly
Ghyslain Leclerc wrote:

> 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 ?

They should mix fine.

> 
> 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 :

I recommend starting with a minimal testcase, make sure it runs, and add 
things until it doesn't. Find the change that breaks. 

> qt5_use_modules( calculum Widgets Sql )

You probably don't need this line.

I don't have experience on OSX to help.

Thanks,

Steve.


-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake