Moc issue with osX/iOs application



  • Hi,

    I try use qmake to build a project for osX and iOs.
    I have one class using Q_OBEJCT with specific implementation for osX and iOs.
    Every files of the project are set in SOURCES and HEADERS.
    I protect platforms depend sources / headers files with :

    #ifdef __APPLE__
    # include <TargetConditionals.h>
    # if TARGET_OS_SIMULATOR || TARGET_OS_IPHONE
    

    or

    #ifdef __APPLE__
    # include <TargetConditionals.h>
    # if TARGET_OS_OSX
    

    In qmake, I added :

    ios {
      QMAKE_MOC_OPTIONS += -DTARGET_OS_IPHONE=1
    }
    osx {
      QMAKE_MOC_OPTIONS += -DTARGET_OS_OSX=1
    }
    

    To generate the Xcode project for iOs i use :

    Qt5.9.1/5.9.1/ios/bin/qmake myProject.pro
    

    But all class depending of #if TARGET_OS_SIMULATOR || TARGET_OS_IPHONE got the warning message :

    Note: No relevant classes found. No output generated.
    

    When I do it by hand it's work :

    Qt5.9.1/5.9.1/ios/bin/qmake -DTARGET_OS_IPHONE=1 myclass.hxx
    

    Even worst qmake / moc build me every class having #if TARGET_OS_OSX

    Is there a way to tell qmake i want a iOs build, so please qmake use the iOs macro for moc expanding ?

    Here the smallest project i can do with the issue i meet, project issue sample

    In advance thanks for any tips that may help me fix my issue,
    NAnder


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Why not use Qt's available platform defines ? i.e. Q_OS_MACOS and Q_OS_IOS



  • HI SGaist,

    Thx for the welcome.

    I tried them too, but they have same issue, moc do all macro expansion as it was an osX build when qmake write the iOs project.

    I'm unable to find what i do bad, seems moc not offer verbose mode.

    From qmake -d, and by testing moc with command line, it seems issue starting when qmake start add to the moc command line :

    -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include
    

  • Lifetime Qt Champion

    Out of curiosity why are you including TargetConditionals.h ?



  • I include TargetConditionals.h because it is the one that define the macro TARGET_OS_XXXXX


  • Lifetime Qt Champion

    Well, you don't need them since Qt already provides defines for the platform it supports so you only have to use

    #if defined(Q_OS_MACOS)
    #elif defined(Q_OS_IOS)
    #endif
    


  • I have tried, but I have the same issue with moc in qmake if I use Q_OS_MACOS and Q_OS_IOS : moc only use the code where Q_OS_MACOS is define whatever I ask it to build, an iOs project or an OsX project.

    All my class depending of #if defined(Q_OS_IOS) got the warning message :

    Note: No relevant classes found. No output generated.
    

    Is it the normal qmake/moc behaviour or I do something bad ?


  • Lifetime Qt Champion

    Can you post the code that triggers that ?



  • Hi, sorry for the late answer. I got some issues.
    Here is smallest set of code to sample that show the problem:
    project.pro

    QT       += core gui
    
    TARGET = Bugs
    TEMPLATE = app
    
    SOURCES += main.cxx
    HEADERS += test_ios.hxx test_osx.hxx
    

    main.cxx

    #include <QApplication>
    #include "test_ios.hxx"
    #include "test_osx.hxx"
    
    Tests::Tests() {}
    Tests::~Tests() {}
    //#include <TargetConditionals.h>
    #ifdef Q_OS_IOS
    //#if TARGET_OS_SIMULATOR || TARGET_OS_IPHONE
    void Tests::Hello() {}
    #endif
    
    int main(int argc, char * argv[])
    {
      Tests bug;
      return 0;
    }
    

    test_ios.hxx

    #include <QApplication>
    #ifdef __APPLE__
    //# include <TargetConditionals.h>
    //# if TARGET_OS_SIMULATOR || TARGET_OS_IPHONE
    #  ifdef Q_OS_IOS
    
    #  include <QObject>
    
    class Tests : public QObject
    {
      Q_OBJECT
    
    public:
      explicit Tests();
      ~Tests();
    
      void Hello();
    };
    
    # endif
    #endif
    

    test_osx.hxx

    #include <QApplication>
    #ifdef __APPLE__
    # include <TargetConditionals.h>
    //# if TARGET_OS_OSX
    #ifdef Q_OS_MACOS
    
    #  include <QObject>
    
    class Tests : public QObject
    {
      Q_OBJECT
    
    public:
      explicit Tests();
      ~Tests();
    };
    
    # endif
    #endif
    

    I create the Xcode project with :

    Qt5.9.1/5.9.1/ios/bin/qmake ../project.pro
    

    Best regards


  • Qt Champions 2016

    You're running moc on an empty header (either one of the two is, or both are, empty). So moc complains about not having any class to parse.



  • Hi, thx for your answer.
    Yes it should complain about one empty header, that would not be an issue.
    But it complain about the wrong one, when i try compile for iOs, why it say :

    Note: No relevant classes found. No output generated.
    

    about test_ios.hxx


  • Qt Champions 2016

    My guess would be that __APPLE__ isn't defined.


  • Lifetime Qt Champion

    Rather than having empty headers, just don't try to build that class if it doesn't make sense on a given platform.

    Use scopes in your .pro file to only compile what is needed.



  • Hi, thx for the answer.

    __ APPLE__ is defined otherwise test_osx.hxx would generate an empty moc file too, which is not the case.

    Yes using scope in .pro file is the way to avoid useless warning, but I not used it here because I wanted to show that moc only generate a moc file from test_osx.hxx whatever I ask qmake to generate a project for OsX or iOs.

    My question is it the normal moc behaviour to expand only OSX macro when I ask qmake to generate a project for iOs ? If not, why it do it with my sample ?

    Best regards,


  • Lifetime Qt Champion

    For me it generates an empty moc file also for iOS when building for macOS and that's expected. Since you are passing both files to the HEADERS variable moc will be run on both generating an empty file for the other OS since the macro is correctly handled.

    To have a truly cross-platform code base, use scopes in your .pro file and only include what's relevant to the platform in your source code otherwise it will become quiet quickly a nightmare to maintain.



  • Hi,

    Thank you for the answers.

    It took me sometime for write back, because i was training my english to be able to answer here. My question is very clear in my head, but it seems my words are bad.

    Yes it's generate an empty moc class warning when i compile for mac osX. This is not an issue, first it just a warning, the compilation still go on, and like you said fix the warning is very easy.

    My question was, why it not work when i try compile for iOS. When i try, I got a warning about test_ios.hxx generating an empty file. And that is a critical error because the compiler will not be able to find the iOS code. Moc seems not expand IOS macro, but always OSX macro whenever it's an OSx or IOs build.

    Best regards,


  • Lifetime Qt Champion

    Can you check whether it's still the case with more recent version of Qt ?



  • Thank a lot for the answer.
    I'll try as soon I can.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.