Results 1 to 10 of 10

Thread: qmake: Custom code generation that produces both header and cpp files...

  1. #1
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default qmake: Custom code generation that produces both header and cpp files...

    I want to include a custom code generation step in my project that produces both header and cpp files from an input file.

    So far I only found examples that generate one type of file.

    I experimented quite a bit, but just could not get it to work. Is this even possible in qmake, or should I start looking at other build tools (ie cmake)?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: qmake: Custom code generation that produces both header and cpp files...

    Assuming the generated header is #included in the generated cpp file, and the header does not need to be run through MOC, it should be sufficient to to run the generator and add the resulting cpp file to SOURCES.

  3. #3
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: qmake: Custom code generation that produces both header and cpp files...

    But then the files will not be regenerated when the input file is modified...

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: qmake: Custom code generation that produces both header and cpp files...

    How have you defined your extra processing in your PRO file?

    This works for me:
    Qt Code:
    1. fakecompiler.name = Test Compiler
    2. fakecompiler.input = FAKEINPUTS
    3. fakecompiler.commands = fakeit.sh ${QMAKE_FILE_IN}
    4. fakecompiler.output = ${QMAKE_FILE_IN}.cpp
    5. fakecompiler.variable_out = SOURCES
    6. fakecompiler.clean = ${QMAKE_FILE_IN}.cpp ${QMAKE_FILE_IN}.h
    7.  
    8. QMAKE_EXTRA_COMPILERS += fakecompiler
    9.  
    10. TEMPLATE = app
    11.  
    12. SOURCES += main.cpp
    13. FAKEINPUTS += something.fake
    To copy to clipboard, switch view to plain text mode 
    (fakeit.sh generates a do nothing FILE.cpp and FILE.h from the given file name)

    First run:
    Qt Code:
    1. chrisw@newton /tmp/test $ ls
    2. fakeit.sh main.cpp something.fake test.pro
    3. chrisw@newton /tmp/test $ qmake
    4. chrisw@newton /tmp/test $ make
    5. g++ -c -pipe -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -o main.o main.cpp
    6. make: Circular something.fake <- something.fake.o dependency dropped.
    7. fakeit.sh something.fake
    8. g++ -c -pipe -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -o something.fake.o something.fake.cpp
    9. g++ -Wl,-O1 -Wl,-rpath,/usr/lib64/qt4 -o test main.o something.fake.o -L/usr/lib64/qt4 -lQtGui -L/usr/lib64 -L/usr/lib64/qt4 -L/usr/X11R6/lib -lQtCore -lgthread-2.0 -lrt -lglib-2.0 -lpthread
    To copy to clipboard, switch view to plain text mode 

    Second run:
    Qt Code:
    1. chrisw@newton /tmp/test $ make
    2. make: Circular something.fake <- something.fake.o dependency dropped.
    3. make: Nothing to be done for `first'.
    To copy to clipboard, switch view to plain text mode 

    Third run:
    Qt Code:
    1. chrisw@newton /tmp/test $ touch something.fake
    2. chrisw@newton /tmp/test $ make
    3. make: Circular something.fake <- something.fake.o dependency dropped.
    4. fakeit.sh something.fake
    5. g++ -c -pipe -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -o something.fake.o something.fake.cpp
    6. g++ -Wl,-O1 -Wl,-rpath,/usr/lib64/qt4 -o test main.o something.fake.o -L/usr/lib64/qt4 -lQtGui -L/usr/lib64 -L/usr/lib64/qt4 -L/usr/X11R6/lib -lQtCore -lgthread-2.0 -lrt -lglib-2.0 -lpthread
    To copy to clipboard, switch view to plain text mode 

    I haven't tracked down the circular reference, but it doesn't seem harmful.

  5. #5
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: qmake: Custom code generation that produces both header and cpp files...

    That does not work if you try to include something.fake.h

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: qmake: Custom code generation that produces both header and cpp files...

    What do you mean?

  7. #7
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: qmake: Custom code generation that produces both header and cpp files...

    something.fake.h is not generated as a dependency of main.cpp (because qmake does not know anything about something.fake.h).
    For me the files are generated *after* it tries to compile main.cpp.

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: qmake: Custom code generation that produces both header and cpp files...

    Yes, I can see that here. So the problem is not that the outputs are not rebuilt when the inputs change, but that the outputs of the custom compiler are a not generated early enough. I don't have time to tinker with it right now. Perhaps someone else will chime in.

  9. The following user says thank you to ChrisW67 for this useful post:

    chenz (28th February 2012)

  10. #9
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: qmake: Custom code generation that produces both header and cpp files...

    Thanks for trying anyway

  11. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: qmake: Custom code generation that produces both header and cpp files...

    Qt Code:
    1. fake_cpp.name = Compiler to CPP
    2. fake_cpp.input = FAKEINPUTS
    3. fake_cpp.commands = fakeit.sh ${QMAKE_FILE_IN}
    4. fake_cpp.output = ${QMAKE_FILE_IN_BASE}.cpp
    5. fake_cpp.variable_out = SOURCES
    6. fake_cpp.clean = ${QMAKE_FILE_IN_BASE}.cpp
    7.  
    8. fake_h.name = Compiler to H
    9. fake_h.input = FAKEINPUTS
    10. fake_h.commands = @echo Fake making the header for ${QMAKE_FILE_IN}
    11. fake_h.depends = ${QMAKE_FILE_IN_BASE}.cpp
    12. fake_h.output = ${QMAKE_FILE_IN_BASE}.h
    13. fake_h.clean = ${QMAKE_FILE_IN_BASE}.h
    14.  
    15. QMAKE_EXTRA_COMPILERS += fake_cpp
    16. QMAKE_EXTRA_COMPILERS += fake_h
    17.  
    18.  
    19. TEMPLATE = app
    20.  
    21. SOURCES += main.cpp
    22. FAKEINPUTS += something.fake
    To copy to clipboard, switch view to plain text mode 

    Seems to work when main.cpp references "something.h". Line 11 causes a request for "something.h" to build the dependency "something.cpp", which has a side-effect of creating our header also. The command at line 10 must exist but does nothing (use @true on UNIX).

    I changed the generated file names a bit to remove the circular dependency problem.

Similar Threads

  1. Q_PROPERTY Code Generation
    By lexfridman in forum Qt Programming
    Replies: 4
    Last Post: 16th January 2014, 09:37
  2. Replies: 10
    Last Post: 6th April 2011, 10:05
  3. Replies: 4
    Last Post: 7th April 2010, 23:09
  4. Why does qmake/moc only process header files?
    By doberkofler in forum Qt Programming
    Replies: 6
    Last Post: 3rd March 2010, 08:32
  5. Designer produces invalid code?
    By Tiansen in forum Qt Programming
    Replies: 7
    Last Post: 4th March 2008, 11:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.