Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Precompiled header support in MOC
Forum Updated to NodeBB v4.3 + New Features

Precompiled header support in MOC

Scheduled Pinned Locked Moved Qt Creator and other tools
15 Posts 8 Posters 15.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.
  • J Offline
    J Offline
    jds21
    wrote on last edited by
    #1

    This is more of a feature request, but I'm not sure where to post it. I have been using Qt for a while, but for large projects it would be really useful to have the option to force the moc to add a specific #include before the automatic one, primarily to support the use of precompiled headers (often, but not always stdafx.h) with MSVC. This can greatly improve compile times.

    Something like the option "-b<file>" which adds #include <file> before the regular include would be most useful. I've seen patches for moc on the web which almost do this, but it would be better if it was supported in the core version.

    Does anyone know if this kind of feature is coming?
    Thanks, John

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      You could search/make a suggestion on the "bug tracker":https://bugreports.qt.nokia.com/secure/Dashboard.jspa.

      If you just post it here the chances to get it in the sources are negligible.

      If you add it to the bug tracker, please add a link to that webpage here and in the description add a link to this post. Using the link other devnet visitors can vote for your suggestion if they like it.

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        I don't know. But you might post this message on Qt5's mailing list http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback . You can either gather a team with which to implement it, or nudge others to do it for you and the rest of us :)

        (Z(:^

        1 Reply Last reply
        0
        • L Offline
          L Offline
          loladiro
          wrote on last edited by
          #4

          AFAIK, this is already implemented using:
          @
          -f[<file>] force #include, optional file name\n"
          @

          EDIT: never mind, looks like that remove the normal include files.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            loladiro
            wrote on last edited by
            #5

            I've had a look at it and it's actually really easy to implement. I can open a merge request with the changes (won't get to it until Sunday though).

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              ZapB
              wrote on last edited by
              #6

              I've not looked in detail but does it not work if you just use the PRECOMPILED_HEADER variable in your .pro file as described "here":http://doc.qt.nokia.com/4.7-snapshot/qmake-precompiledheaders.html?

              Nokia Certified Qt Specialist
              Interested in hearing about Qt related work

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jds21
                wrote on last edited by
                #7

                Thanks for the replies. I created a bug report under the category "suggestion" : https://bugreports.qt.nokia.com/browse/QTBUG-20785 .

                I have found the /FI compile option for the c compiler which I think I can use instead. ( http://msdn.microsoft.com/en-us/library/8c5ztk84(v=VS.100).aspx ).

                I have been using cmake rather than qmake so far, so the PRECOMPILED_HEADER variable was not an option.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  steno
                  wrote on last edited by
                  #8

                  If using vs2010, the pre compiled headers switch is pretty much obsolete imo. I find the /MP much more usefull in compiling huge projects, which is incompatible with the /Yu switch.

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    loladiro
                    wrote on last edited by
                    #9

                    I have created a "merge request":https://qt.gitorious.org/qt/qtbase/merge_requests/41 for this feature

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      jds21
                      wrote on last edited by
                      #10

                      steno : To me the pch is not obsolete. I think it depends greatly on the project type, and it is important to benchmark. I use /MP and /Yu together - I think it is only the pch generation (/Yc) that is not compatible with /MP. The combination gives faster compile times on my projects than either on its own, the pch giving 50% reduction in time and the MP another 20%.

                      I prefer not to use /FI as it implicitly adds an include you cannot see in the source code, which can have unexpected consequences.

                      loladiro : thanks for the merge request.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        steno
                        wrote on last edited by
                        #11

                        So what do you do, have another propject create the pre-compiled header and just use it with another project using the /MP switch?

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          jds21
                          wrote on last edited by
                          #12

                          I use /MP for the whole project, it seems that /Yc overrides it for the one file that generates the pch. I'm actually using a cmake macro, which also sets the dependency of the pch-users on the pch binary. VS may do this automatically if you manually setup the project, I'm not sure.

                          1 Reply Last reply
                          0
                          • _ Offline
                            _ Offline
                            _nob
                            wrote on last edited by
                            #13

                            I actually hacked the Cmake-Script to include StdAfx.h for me. First test seems to work.

                            @

                            PATCHED QT4_WRAP_CPP for use with StdAfx

                            Original source: Qt4Macros.cmake

                            MACRO (PCH_QT4_WRAP_CPP outfiles )

                            get include dirs

                            QT4_GET_MOC_FLAGS(moc_flags)
                            QT4_EXTRACT_OPTIONS(moc_files moc_options ${ARGN})

                            FOREACH (it ${moc_files})
                            GET_FILENAME_COMPONENT(it ${it} ABSOLUTE)
                            QT4_MAKE_OUTPUT_FILE(${it} moc_ cxx outfile)
                            set (moc_flags_append "-fStdAfx.h" "-f${it}") # StdAfx hack.

                            message (STATUS "Moc Flags append ${moc_flags_append}")

                            QT4_CREATE_MOC_COMMAND(${it} ${outfile} "${moc_flags};${moc_flags_append}" "${moc_options}")
                            SET(${outfiles} ${${outfiles}} ${outfile})
                            ENDFOREACH(it)
                            ENDMACRO (PCH_QT4_WRAP_CPP)
                            @

                            1 Reply Last reply
                            0
                            • L Offline
                              L Offline
                              loladiro
                              wrote on last edited by
                              #14

                              Starting with Qt5, the moc will now support the -b<file> option to add optional includes.

                              1 Reply Last reply
                              1
                              • J Offline
                                J Offline
                                joonhwan
                                wrote on last edited by
                                #15

                                great.

                                joonhwan at gmail dot com

                                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