gyp for a cross-platform project using Qt

1,137 views
Skip to first unread message

Claudio Junior

unread,
May 22, 2012, 10:23:17 PM5/22/12
to gyp-de...@googlegroups.com
Hi, I am working on this project that use Qt for the GUI and a lot of chromium's code with gyp files generating projects for MSVC 10. Now, we want to begin porting this project for OS X using Xcode. All of our projects depending on Qt are being handled manually.

Does someone believe it to be a feasible idea to use gyp for generating Qt dependencies on MSVC and in XCode with their native project types?

Thank you,

Claudio M. Souza Junior.

Evan Martin

unread,
May 23, 2012, 1:46:20 PM5/23/12
to Claudio Junior, gyp-de...@googlegroups.com
What do you mean by "generating qt dependencies"? Can you be more specific?

Ryan Sleevi

unread,
May 23, 2012, 2:03:12 PM5/23/12
to Evan Martin, Claudio Junior, gyp-de...@googlegroups.com
QT has several preprocessing tools to aid in compiling code with QT's special macros. These include 'moc' (the meta-object compiler) and 'uic' (the UI compiler).

'moc' pre-processes header files (foo.h) and generates target files of the form 'moc_foo.cpp'. 'uic' parses .ui files (bar.ui) and generates target files of the form 'ui_bar.h' and 'ui_bar.cpp'

These auto-generating tools are generally passed the same configuration options (DEFINES, etc) as the compiler toolchain, roughly similar to how WebKit generates JSC/V8 bindings in the Chromium tree.

Conceptually, you could accomplish this with 'rules', and perhaps 'actions' with 'process_outputs_as_sources'.

I'm surprised you would prefer GYP as the backend tool, since QT promotes their qmake meta-buildtool quite heavily. As I recall, qmake is able to generate XCode and MSVS projects (in addition to makefiles of both GNU make and nmake variety).

That said, it should be possible to add 'rules' to moc some/all headers and files, and then add their sources to the target. Likewise, rules, for .ui files should be fairly trivial.

Claudio Junior

unread,
May 23, 2012, 3:22:27 PM5/23/12
to gyp-de...@googlegroups.com, Evan Martin, Claudio Junior, rsl...@chromium.org
When I say about qt dependencies I am talking about all the things required to link Qt libraries on my project with a natural feel.

I do not want to use qmake because I am using some projects like libjingle from google. Those project integrate nicely with my IDE, but i feel that using qmake for this would be cumbersome.

Since we have to compile this project on Windows and Mac, it seems more appropriate to use gyp. So I would like to know how to integrate qmake generated makefiles with the xcodeproj generated by gyp.

- Claudio

Ryan Sleevi

unread,
May 23, 2012, 3:45:28 PM5/23/12
to Claudio Junior, gyp-de...@googlegroups.com, Evan Martin
GYP doesn't have a great story about integrating with other meta-build systems, largely because it's intended to be a meta-build system itself.

As far as linking QT libraries, can you not create a 'qt' target that specifies all the linkable requirements? For example, on Linux, when linking against system libraries/third-party libraries, Chromium has GYP stub out to pkg-config to describe the necessary link requirements ( see http://src.chromium.org/viewvc/chrome/trunk/src/build/linux/system.gyp?view=markup ).

For QT, you could do such an approach for Linux. For Mac/Win builds, you could do something like
{
  'target_name': 'qt',
  'type': 'none',
  'variables': {
    'qt_dir': 'some_path_to_qt_libraries',
    'conditions': [
      ['OS=="win" and _configuration == "Debug", {
        'qt_lib_suffix': 'd4',
      }, {
        'qt_lib_suffix': '4',
      }],
    ],
  },
  'conditions': [
    ['OS=="win" or OS=="mac"', {
      'link_settings': {
        'libraries': [
          'qtmain<(qt_lib_suffix)', 'qtcore4<(qt_lib_suffix)', 'qtgui4<(qt_lib_suffix)'
        ],
        'library_dirs': [
          '<(qt_dir)',
        ],
    }],
    ['OS=="linux"', {
      ['_toolset=="target"', {
        'direct_dependent_settings': {
          'cflags': [ '<!@(pkg-config --cflags qt4)', ],
        },
       'link_settings': {
         'ldflags': [
           '<(@(pkg-config --libs-only-L --libs-only-other qt4)',
         ],
         'libraries': [
           '<@(pkg-config --libs-only-l qt)',
         ],
      }, 
    }],
    ['OS=="mac"', {
      'target_conditions': [
        ['_configuration=="Debug", {
           'mac_framework_dirs': [
             '<(qt_dir)/Debug',
           ],
        }, {
          'mac_framework_dirs': [
            '<(qt_dir)/Release',
          ],
        }],
      ],
    }],
  }
}

This is all going from memory - it's been half a year since I last touched QT stuff. I seem to recall the DLL names on Windows being either qtmain4.dll / qtmaind4.dll (hence qt_lib_suffix), whereas on Mac, it was qtmain.dylib but differentiated by the Framework directory (hence the 'mac_framework_dirs' condition). Linux it was typically always built release, but your distro would ship debug symbols (hence the pkg-config calls).

This probably will not work as written, and I'm not looking to necessarily support it, since like I said, I haven't touched QT in a while, but I think that'll cover the major touchpoints for linking, in addition to the comments about 'rules' and 'actions' for uic/moc.

http://code.google.com/p/gyp/wiki/InputFormatReference is the go-to reference for what you can do, and should probably be the first point for any questions. Also, you may find it helpful to read Chromium's GYP files (such as the one I mentioned), since I think you'll find quite a bit cross-platform flexibility in them that isn't always well-expressed in other meta-build tools.

Cheers

Claudio Junior

unread,
May 23, 2012, 8:55:57 PM5/23/12
to gyp-de...@googlegroups.com, Claudio Junior, Evan Martin, rsl...@chromium.org
Hi Ryan.
I am very thankful. I know I will have to study how to implement it in detail, but you are a real contributor to a group of questions. This is just one more score why gyp is so terrific.

I am really looking forward for using gyp on my projects. QMake is petty lame on windows because it does not use the default building system for building the project.

Thank you very much. I will try to make it work,

- Claudio.
Reply all
Reply to author
Forward
0 new messages