Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to add entries to moc_predefs.h?

How to add entries to moc_predefs.h?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dan Princ
    wrote on last edited by Dan Princ
    #1

    Moc generates file moc_predefs.h, that contains some defines, that are included to every file that moc parses. Is there a way to add defines to this file?

    I'd like to define some include guards in this file to prevent moc from parsing some headers. I could define these guards directly as moc's parameter, but that would unnecessarily bloat the makefile, it would be much nicer to have it directly in the predefs file.

    Thanks for any hints.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Would it be simpler to use #ifdef Q_MOC_RUN in your code ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Would it be simpler to use #ifdef Q_MOC_RUN in your code ?

        D Offline
        D Offline
        Dan Princ
        wrote on last edited by
        #3

        @SGaist Hi, that is a possibility, but I'm trying to prevent moc from parsing 3rd party headers like boost... That would mean using #ifdef Q_MOC_RUN around every such include, which isn't exactly convenient.

        But I've just found out, that there's a command line parameter for moc @<file>, which enables to read additional command options from a file. It seems I can create a file full of -DINCLUDE_GUARD and pass it to moc in my pro file with QMAKE_MOC += @moc_ignored_file_guards.txt.

        I haven't yet tested it, but if it works, it would be as convenient as it gets for my case :)

        1 Reply Last reply
        1
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What is your problem with boost ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          D 1 Reply Last reply
          0
          • SGaistS SGaist

            What is your problem with boost ?

            D Offline
            D Offline
            Dan Princ
            wrote on last edited by Dan Princ
            #5

            @SGaist said in How to add entries to moc_predefs.h?:

            What is your problem with boost ?

            Moc is slow to parse it. I can speed up moc 2x-3x simply by not parsing boost headers. In some cases I tested, it seems I can speed up moc 10x if I prevent it to parse all 3rd party includes. This means a total save of several minutes of build time in my case.

            Btw. the solution I posted in my previous post seems to work, which basically solves my issue.

            1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Good to know, thanks for the feedback !

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved