[CMake] QT4_WRAP_CPP and Implicit Dependencies

Miller, Frank FMiller at sjm.com
Thu Oct 11 00:32:18 EDT 2012


Greetings,

Suppose we have a header file, Dum.h, that is included by another header
file, Main.h, and Main.h needs to be processed with the qt moc tool.
When Dum.h changes, should we rerun moc on Main.h?

QMake says yes. CMake, using QT4_WRAP_CPP, says no.

I am inclined to believe qmake on this one. However, I have yet to think
of a way to break a build by not rerunning moc. Is this a problem?

Please pardon me if you think this question is in the wrong forum. I am
asking here because I know there are a lot of qt users in this community
and qmake is clearly not doing anything wrong.

Here is a simple example:

    === CMakeLists.txt ===
    cmake_minimum_required( VERSION 2.8.0 )
    project( mocdep )
    find_package( Qt4 REQUIRED )
    include( ${QT_USE_FILE} )
    include_directories( ${CMAKE_BINARY_DIR} )
    QT4_WRAP_CPP( mocdep_MOCSOURCES Main.h )
    add_executable( mocdep Main.cpp ${mocdep_MOCSOURCES} Main.h )
    target_link_libraries( mocdep ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} )

    === mocdep.pro ===
    HEADERS = Main.h Dum.h
    SOURCES = Main.cpp

    === Dum.h ===
    #pragma once

    === Main.h ===
    #pragma once
    #include "Dum.h"
    #include <QMainWindow>

    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    };

    === Main.cpp ===
    #include "Main.h"
    #include <QApplication>

    int main( int argc, char * argv[] )
    {
        QApplication app(argc, argv);

        MainWindow mainWindow;
        mainWindow.show();

        return app.exec();
    }

Frank

This communication, including any attachments, may contain information that is proprietary, privileged, confidential or legally exempt from disclosure. If you are not a named addressee, you are hereby notified that you are not authorized to read, print, retain a copy of or disseminate any portion of this communication without the consent of the sender and that doing so may be unlawful. If you have received this communication in error, please immediately notify the sender via return e-mail and delete it from your system.


More information about the CMake mailing list