Re: [Interest] CMake AUTOMOC & Windows linking

2020-05-15 Thread Andy
OK. I don't know why my cmake code to show the SOURCES wasn't showing them,
but when I looked in the ninja json files, A's headers were in the
"sources" section.

The problem turned out to be this:

target_sources( libA
PUBLIC
...

It needs to be:

target_sources( libA
PRIVATE
...

The PRIVATE vs. PUBLIC on target_sources() didn't make sense to me before,
but with this concrete example I think I understand it better. :-)

Thanks for pointing me in the right direction Thiago!

---
Andy Maloney  //  https://asmaloney.com
twitter ~ @asmaloney 



On Fri, May 15, 2020 at 2:15 PM Matthew Woehlke 
wrote:

> On 15/05/2020 11.17, Andy wrote:
> > I'm running into a link problem on Windows. I only have Windows on CI, so
> > debugging this is... challenging.
> >
> > - cmake 3.10+
> >
> > - AUTOMOC is ON for the project in the top level cmake file
> >
> > - Dynamic Library "A":
> >class LIB_IMPORT_EXPORT Foo
> >{
> >Q_OBJECT
> >...
> >
> > where LIB_IMPORT_EXPORT uses Q_DECL_EXPORT/Q_DECL_IMPORT properly
> > depending on who's building.
>
> This isn't necessarily your problem, but if you're using CMake, I would
> recommend using generate_export_header to define your ABI decoration
> symbols rather than rolling your own using Q_DECL_EXPORT/Q_DECL_IMPORT.
>
> --
> Matthew
>
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] CMake AUTOMOC & Windows linking

2020-05-15 Thread Matthew Woehlke

On 15/05/2020 11.17, Andy wrote:

I'm running into a link problem on Windows. I only have Windows on CI, so
debugging this is... challenging.

- cmake 3.10+

- AUTOMOC is ON for the project in the top level cmake file

- Dynamic Library "A":
   class LIB_IMPORT_EXPORT Foo
   {
   Q_OBJECT
   ...

where LIB_IMPORT_EXPORT uses Q_DECL_EXPORT/Q_DECL_IMPORT properly
depending on who's building.


This isn't necessarily your problem, but if you're using CMake, I would 
recommend using generate_export_header to define your ABI decoration 
symbols rather than rolling your own using Q_DECL_EXPORT/Q_DECL_IMPORT.


--
Matthew
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] CMake AUTOMOC & Windows linking

2020-05-15 Thread Andy
Thanks Thiago. I used the following to confirm that A's headers are not in
B's sources:

get_target_property( files ${plugin_target} SOURCES )
list( FILTER files INCLUDE REGEX ".*\.h" )
message( "Headers ${plugin_target}" )
foreach( filename ${files} )
   message( "  - ${filename}" )
endforeach()

This produces a list of B's headers - nothing related to A.

According to the AUTOMOC docs, that's what it should be using to moc,
correct?

---
Andy Maloney  //  https://asmaloney.com
twitter ~ @asmaloney 



On Fri, May 15, 2020 at 1:24 PM Thiago Macieira 
wrote:

> On sexta-feira, 15 de maio de 2020 08:17:49 PDT Andy wrote:
> > 1) This setup was working before I added a class with Q_OBJECT & signals
> to
> > "A"
> > 2) It looks like I'm getting Foo's static meta object compiled into both
> > "A" and "B". Is this what should be happening?
> >
> > I feel like I'm missing something obvious...
>
> Make sure A's headers are not listed in B's header list.
>
> --
> Thiago Macieira - thiago.macieira (AT) intel.com
>   Software Architect - Intel System Software Products
>
>
>
>
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] CMake AUTOMOC & Windows linking

2020-05-15 Thread Thiago Macieira
On sexta-feira, 15 de maio de 2020 08:17:49 PDT Andy wrote:
> 1) This setup was working before I added a class with Q_OBJECT & signals to
> "A"
> 2) It looks like I'm getting Foo's static meta object compiled into both
> "A" and "B". Is this what should be happening?
> 
> I feel like I'm missing something obvious...

Make sure A's headers are not listed in B's header list.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel System Software Products



___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


[Interest] CMake AUTOMOC & Windows linking

2020-05-15 Thread Andy
I'm running into a link problem on Windows. I only have Windows on CI, so
debugging this is... challenging.

- cmake 3.10+

- AUTOMOC is ON for the project in the top level cmake file

- Dynamic Library "A":
  class LIB_IMPORT_EXPORT Foo
  {
  Q_OBJECT
  ...

   where LIB_IMPORT_EXPORT uses Q_DECL_EXPORT/Q_DECL_IMPORT properly
depending on who's building.

- Dynamic Library (Plugin) "B":
  Uses target_link_libraries( B "A" ) to include "A".

When compiling with MSVC (on CI), I have a link problem:

PLUGIN_B_autogen\4RG5PT7PRG/moc_Foo.cpp(75): warning C4273:
'Foo::qt_static_metacall': inconsistent dll linkage
LibraryA\include\Foo.h(30): note: see previous definition of
'qt_static_metacall'
PLUGIN_B_autogen\4RG5PT7PRG/moc_Foo.cpp(111): error C2491:
'Foo::staticMetaObject': definition of dllimport static data member not
allowed

1) This setup was working before I added a class with Q_OBJECT & signals to
"A"
2) It looks like I'm getting Foo's static meta object compiled into both
"A" and "B". Is this what should be happening?

I feel like I'm missing something obvious...

---
Andy Maloney  //  https://asmaloney.com
twitter ~ @asmaloney 
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest