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. [moved] Adding an extra tool to the tool chain
Forum Updated to NodeBB v4.3 + New Features

[moved] Adding an extra tool to the tool chain

Scheduled Pinned Locked Moved Qt Creator and other tools
7 Posts 2 Posters 4.3k 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.
  • R Offline
    R Offline
    RickH
    wrote on last edited by
    #1

    Hi. I'm using QtCreator, and therefore I'm using qmake. I'd like to pre-process my source file with m4 before I run the compiler on them. So in whatever syntax you have to use with qmake, I'd like to state that x.cpp files have a dependency on x.cpp.m4 files, and x.h files have a dependency on x.h.m4 files, and the command to get from one to the other is something like m4 @.h.m4 >@.h. How would I go about saying that?

            Regards, Rick
    
    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Hi, I do something similar to what you need using bison to pre-process the input files. I foudn this technique at http://www.freehackers.org/thomas/2009/11/22/how-to-use-flex-and-bison-with-qmake-my-own-way/

      I'll illustrate using the solution for bison but it shoudl be easily modified to work with m4.

      Put the following into a .pri file (bison.pri in my case):

      @
      bison.name = Bison ${QMAKE_FILE_IN}
      bison.input = BISONSOURCES
      bison.output = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.parser.cpp
      win32 {
      bison.commands = bison.exe --defines=${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.parser.h -o ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.parser.cpp ${QMAKE_FILE_IN}
      } else {
      bison.commands = bison --defines=${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.parser.h -o ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.parser.cpp ${QMAKE_FILE_IN}
      }
      bison.CONFIG += target_predeps
      bison.variable_out = GENERATED_SOURCES
      silent:bison.commands = @echo Bison ${QMAKE_FILE_IN} && $$bison.commands
      QMAKE_EXTRA_COMPILERS += bison
      @

      Then in your .pro file you need to include the bison.pri file:

      @
      include(bison.pri)
      @

      and then specify the BISONSOURCES variable as you would with SOURCES for C++ files:

      @
      BISONSOURCES += zcalc.y
      @

      As an aside if you then add BISONSOURCES to the OTHER_FILES variable this has the effect of making these sources also show up in Qt-creator's project view:

      @
      OTHER_FILES += $$BISONSOURCES
      @

      I think you should be able to substitute bison for m4 in the above to get what you need.

      Hope this helps.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RickH
        wrote on last edited by
        #3

        Thanks! I'll go use this information.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          RickH
          wrote on last edited by
          #4

          I finally got back to this. My version, very similar to the one above, almost works. The resulting file is consistently placed in the target directory. The directory, parallel to the one that has the source files and header files, that has the object files and executable files. I'd like the results to go into the source directory. So that my file test.hm4 is processed into the file test.h, and further compilation and linking goes on as normal.

          I've tried a number of variants, but haven't succeeded in making the file appear in the source directory. Does anyone know how to do that?

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

            Can you post a very minimal trial project that uses what you have so far please so that we can take a look at it and try it for ourselves? It's difficult to see without it.

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply
            0
            • R Offline
              R Offline
              RickH
              wrote on last edited by
              #6

              Sure.

              test.hm4:
              @define(declaration,
              class saysomething {
              public:
              void sayhello(void);
              void saysayanara(void);
              };
              )

              declaration@

              data_struct.pro:
              @include(m4.pri)

              QT += core
              QT -= gui

              TARGET = data_struct
              CONFIG += console
              CONFIG -= app_bundle

              TEMPLATE = app

              SOURCES += main.cpp
              coreapp.cpp
              readevalprintloop.cpp

              HEADERS +=
              coreapp.h
              readevalprintloop.h

              HM4SOURCES += test.hm4

              OTHER_FILES +=
              m4.pri
              $$HM4SOURCES@

              m4.pri:
              @hm4.name = hm4
              hm4.input = HM4SOURCES
              hm4.output = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.h
              message("Here is the value of QMAKE_FILE_IN")
              message(${QMAKE_FILE_IN})
              hm4.commands = /m4/m4.exe ${QMAKE_FILE_IN} >${QMAKE_FILE_IN_BASE}.h
              hm4.CONFIG = target_predeps
              hm4.variable_out = HEADERS
              QMAKE_EXTRA_COMPILERS += hm4

              m4.output = $$replace(${QMAKE_FILE_IN}, ".m4", "")

              "Undocumented Qmake" says this doesn't work. QMAKE_FILE_IN substituted after replace is done.@

              I hope this is clearer.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                RickH
                wrote on last edited by
                #7

                I solved my problem, in probably an ugly way. I discovered that Qt Creator offers extra build steps, that you can place before or after the supplied build steps. In case it helps somebody else, here's the entry I made. Click the Project tab.

                Enable custom process step. (checked)
                Command: "c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\nmake" -f m4.mak
                Working directory: C:\Users\Rick\bazaar_repository\data_struct
                Command arguments: (empty)

                Rick

                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