tags:

views:

69

answers:

1

Is it possible to include C/C++ header files in a qmake (.pro) file?

I have a version.h header file with several definitions for my project (strings, version numbers, etc.). I also have an .rc file for Windows to add version info to my exe/dll, which includes this header file.

So, can I somehow get the #defines in my header file to be processed in my .pro file, or what other way could I use to define strings and other constants in one file and have them accessible from my C++ code, the .rc file and the .pro file by including that file?

+2  A: 

You can use the DEFINES variable in the .pro file. The following works with gcc and clang.

# A definition without a value
DEFINES += USE_X86_ASM

# A definition with a value
DEFINES += SOME_DEFINITION=value

# A more complicated value needs quoting
DEFINES += COMPANY_NAME=\"Weird Apps LLC.\"

# Defining a string can be tricky
DEFINES += STRING_VALUE=\"\\\"This is a string literal\\\"\"

# The value comes from the build environment.
DEFINES += COMPILED_BY=$(USER)

The definitions are passed to the C/C++ compiler. I don’t know if the rc compiler also gets them, though.

andref
Thanks for your answer so far - unfortunately it seems that the definitions are not passed to the RC compiler though, as you said... do you have any idea how this might be done?
Jake Petroules
I am also having trouble with string values containing spaces, despite using your \"\\\" syntax.
Jake Petroules
It might be possible. I'll try something as soon as I have a Windows machine available.
andref
Are you using mingw or VisualStudio?
andref
I am using mingw.
Jake Petroules