[moved] Adding an extra tool to the tool chain
-
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
-
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.
-
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?
-
Sure.
test.hm4:
@define(declaration,
class saysomething {
public:
void sayhello(void);
void saysayanara(void);
};
)declaration@
data_struct.pro:
@include(m4.pri)QT += core
QT -= guiTARGET = data_struct
CONFIG += console
CONFIG -= app_bundleTEMPLATE = app
SOURCES += main.cpp
coreapp.cpp
readevalprintloop.cppHEADERS +=
coreapp.h
readevalprintloop.hHM4SOURCES += 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 += hm4m4.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.
-
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