Author Topic: Best way to integrate an "Other" file  (Read 7033 times)

Offline burtbick

  • Multiple posting newcomer
  • *
  • Posts: 10
Best way to integrate an "Other" file
« on: January 07, 2012, 04:59:43 pm »
Hi,
I've been using CB 10.05 for some time and it is great.

My current project is a C project with several source, and header files.

There is also a "protocol" file that is processed by a separate tool that "compiles" the protocol file and generates a .C and .H file that is included in the project.

I was using a pre-build step for running the protocol "compiler" and while that works it doesn't know that the protocol file has not changed and the .C and .H files don't need to be generated.  So it causes all of the files that include the generated .H file to be recompiled when they do not need to be.

So I next tried removing the pre-build step and from the properties for the protocol file I set a custom build using the same command that was used in the pre-build step.

This also works fine, but still compiles the protocol file every time.  How can I set up the dependency so that the custom build step for the protocol file only runs when the protocol file has changed?

I've done a preliminary search in the forums, but didn't find a direct answer.  If I have missed something in my search, or in the docs, I would appreciate it if someone could point me to the appropriate reference.

Thanks,
Burt

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7678
    • My Best Post
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline burtbick

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Best way to integrate an "Other" file
« Reply #2 on: January 07, 2012, 10:09:19 pm »
Thanks Tim,

That is getting me much closer.

It builds when my protocol file changes and creates the generated .C and .H files. 

But it doesn't build the rest of my project on that pass.  If I build again it builds the rest of my project that depends on the two generated files.

I can live with that but I'm still missing a piece that should cause the files that include the generated .H file to build when a new file is generated.

I would prefer it if I can configure C:B to rebuild the entire project when the protocol file changes.

I've experimented with the dependency settings that I can find but haven't yet found the way to make the other files build based on either my protocol file changing or the generated .H file.

Is there a way to set up the dependencies so that when my protocol file changes, or the generated .H file which is included in my project changes that the entire project will build with having to do a second build request?

I saw one discussion in the forum where someone was asking a similar question about an option to specify the dependency on a generated file but that was more in the form of a request than a solution.

Do I need to set up some additional rule for the protocol file to generate dependencies?

What am I missing in getting the dependency configured properly?

Thanks again,
Burt



Offline stahta01

  • Lives here!
  • ****
  • Posts: 7678
    • My Best Post
Re: Best way to integrate an "Other" file
« Reply #3 on: January 07, 2012, 10:40:39 pm »
Try right clicking on "protocol" file an adjust file "properties"
Tab Build
slider "Priority Weight" to make the "protocol" file build first.

No idea if that we help or not.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline burtbick

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Best way to integrate an "Other" file
« Reply #4 on: January 08, 2012, 01:37:21 am »
Thanks,

I'd already tried different settings for the priority weight.

I'll live with it for right now, just have to remember to do the second build and when I get some more time I'll dig into it deeper..
Burt

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: Best way to integrate an "Other" file
« Reply #5 on: January 08, 2012, 07:02:56 am »
I'd already tried different settings for the priority weight.
This really should work. Note that files with a lower value will be build first!
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline burtbick

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Best way to integrate an "Other" file
« Reply #6 on: January 08, 2012, 05:15:33 pm »
Thanks,

I'll try experimenting with it again.  I only changed it on the protocol file and it didn't appear to change the behavior.  

If I edit the protocol file and hit the build button the protocol file is compiled and the .C and .H files are generated.  But then the build completes without building the files that depend on the newly generated .H file (and the newly generated .C file).

If I immediately hit build again then all of the files that depend on the generated .H file are built, as well as the newly generated .C file and the executable is built.

The macro I used to specify the build is the 'Build one file...' but that was the same one that was used in the two examples from the Wiki so I would expect that to be correct.

Regards,
Burt

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7678
    • My Best Post
Re: Best way to integrate an "Other" file
« Reply #7 on: January 08, 2012, 05:23:20 pm »
What macro did you put in the box below that covers generated files?

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline burtbick

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Best way to integrate an "Other" file
« Reply #8 on: January 08, 2012, 06:14:26 pm »
Hi Tim,

From the Advanced Options Dialog

Source ext: proto

Command:
'Compile single file to object file'

protoc-c --c_out=. $file_name.proto

Generated Files:
$file_dir/$file_name.pb-c.c
$file_dir/$file_name.pb-c.h

Note: I've tried it with and without the .h

Close project and reopen between changes to Advanced Options.

Looking closer at what C:B is doing when I edit the protocol file and build:

  • Get to a clean build state where everything is update to date.
  • Edit protocol file to change a member name which will cause a compile error from one of the project files that doesn't know the new name.
  • Proto file compiles, generates .H and .C files.  But the files that include the generated .H do not get compiled and linked.
  • Hit build again, the files that include .H are compiled and in this case I get the error I induced.

Edit proto file again to fix error.

  • Hit build.
  • Proto file compiles, generates .H and .C files.
  • C file that failed on previous build is also compiled in this case but none of the other .C files that include the generated .H file get compiled.

After build finishes "successfully"

  • Hit build again.
  • The other .C files that include the generated .H are compiled and linked.

Protocol source file Build priority weight at 20% so it should build ahead of the others, and generate the .H file (and .C) file before compiling others.  I would expect that this would have the .H file available for the rest of the project to then scan.  I'm thinking that perhaps C:B does the dependency scan before the build starts, and doesn't realize that the Protocol compile step is going to change things by generating new files that the rest of the project depend on.  Could that be what is happening, since it seems to fit if you follow the steps above?

If so is there a way with in the project to regenerate the dependencies after the protocol compile step completes? And if so is there a good example of how to do that somewhere in the docs that I haven't seen?

Thanks,
Burt


Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: Best way to integrate an "Other" file
« Reply #9 on: January 08, 2012, 07:38:18 pm »
Generated Files:
$file_dir/$file_name.pb-c.c
$file_dir/$file_name.pb-c.h
Did you add them to the project (once they are created) and leave the project as it is (even they are not there - and flagged as missing)?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline burtbick

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Best way to integrate an "Other" file
« Reply #10 on: January 08, 2012, 08:10:02 pm »
I've tried both ways.

That is I removed them from the Project and just let them appear as generated files.

And I tried it with not in the generated files and added back to the project.

No difference either way.

Thanks,
Burt

Offline burtbick

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Best way to integrate an "Other" file
« Reply #11 on: January 09, 2012, 12:23:50 am »
One other wrinkle.

I have two projects which are sharing the same protocol file.  A Server application and a Client application.
Using the Advanced setting option unfortunately applies the protocol compiler to both projects, and for the Client project I need a different macro to set a path to the protocol file that lives in the Server project's source / project directory.

What would be great would be a per project option that would work to build like the Advanced option solution.

I know about the file properties setting to use a custom compiler and I was using that before, but I wasn't able to get it to only compile the protocol file when changes were made.  Maybe that approach is better if I can get the file to only be compiled when a change is made to it.

Of course for that to work I need to include the generated .C and .H files in my project which isn't a big deal as long as the protocol compiler runs to create them.

Thanks,
Burt