Author Topic: Making the creation of a cpp file dependand of a .h  (Read 4571 times)

xanatose

  • Guest
Making the creation of a cpp file dependand of a .h
« on: March 06, 2008, 01:03:21 am »
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?


Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Making the creation of a cpp file dependand of a .h
« Reply #1 on: March 06, 2008, 01:16:30 am »
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."

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Making the creation of a cpp file dependand of a .h
« Reply #2 on: March 06, 2008, 01:22:20 am »
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

  • Guest
Re: Making the creation of a cpp file dependand of a .h
« Reply #3 on: March 07, 2008, 12:27:13 am »
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.

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Making the creation of a cpp file dependand of a .h
« Reply #4 on: March 07, 2008, 08:53:02 am »
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.

Offline Revvy

  • Multiple posting newcomer
  • *
  • Posts: 32
Re: Making the creation of a cpp file dependand of a .h
« Reply #5 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.
Cheers,
Revvy

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Making the creation of a cpp file dependand of a .h
« Reply #6 on: March 09, 2008, 11:15:04 am »
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...

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Making the creation of a cpp file dependand of a .h
« Reply #7 on: March 09, 2008, 11:57:46 am »
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.