News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Making the creation of a cpp file dependand of a .h

Started by xanatose, March 06, 2008, 01:03:21 AM

Previous topic - Next topic

xanatose

I have a cpp file that want to create from a header every time the header changes.

I found that by changing the precompiled headers rule build to be a custom build I can do this. But the way is not perfect as the
file will be recreated on every build. Since I found no way of changing the expected output file for precompile headers.

Is there a way to recreate a cpp file from a header every time the header changes without using a custom build file?


thomas

I am almost inclined to say: no. Not unless you do some nasty things, at least.

You might be lucky, maybe... if you make a separate build target for just this one header, and try to fool the compiler using the -c, -x and -o flags in "extra options".
Something like  -c -x c++ -o $(file_name).cpp might possibly do... not sure.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

thomas

Oi! Stop!   -c isn't good, you probably want -E.

You want the preprocessor to run, and have that output as cpp file, right?
So I guess this is what you need.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

xanatose

Actually I am creating the cpp from the header using an internal tool.

Basically what I need is that the cpp is remade every time the header changes.
O well, I can always use a custom make file.  Thanks anyway.

Ceniza

What about marking the header file for compilation and adding a custom build command that calls the internal tool? I haven't tried it myself, but I think it can be done.

Revvy

I was trying Ceniza's suggestion to try to make Code::Blocks work the Qt and its moc build step, but the output target for .h files is locked as .h.pch or something like that.  It didn't seem to be a very flexible system.
Cheers,
Revvy

Ceniza

I just tried adding a custom command to build the file, and it did it. My test command was: cmd /c copy $file $file.cpp. Maybe a few more extra macros would help to create custom build commands more easily, like $file_dir, or $file_noext...

Jenna

Quote from: Revvy on March 08, 2008, 07:55:15 PM
I was trying Ceniza's suggestion to try to make Code::Blocks work the Qt and its moc build step, but the output target for .h files is locked as .h.pch or something like that.  It didn't seem to be a very flexible system.

I don't use Qt and therefore also not moc.
I looked in the moc-documentation to find out something about its command-line options.

If you right-click your .h-file (in the Manager) and chose properties you can create a coustom-build-command like "moc -E $file -o $file_dir/moc_$file_name.cpp" (tab "Advanced").

Don't forget to check compile on the "Build"-tab.
To make sure your moc_*.cpp file is created before compiling the other files you should decrease the priority-weight of the file (to 40 for example).

Other command macros you can use can be found under "Settings -> Compiler and Debugger -> Global Compiler Settings -> Other Settings (the right-most tab) -> Advanced Options".

As I wrote, I don't use Qt, so I could only test it with a .h file preprocessed with g++ instead of moc, that works fine, even it does not make much sense in the moment.