User forums > Using Code::Blocks

Conditional Pre-build step?

(1/2) > >>

ironhead:
Is it possible to create a conditional pre-build step (based on a custom variable)?  Basically I need to be able to dynamically generate a file that contains the svn version of HEAD and write it to a file.  I currently have:


--- Code: ---cmd /c if $(SVN_BUILD) == yes svn info --revision HEAD | grep Revision | sed -e "s/Revision:/#define SVN_VERSION/" > svnversion.h

--- End code ---

But this is to me is really cludgy because it's dependant on the 'if' functionality built in to cmd.  Is there a 'native' if / then / else, etc. that can be used in the pre-build steps?

mariocup:
Hi ironhead,

yes it is possible to make a conditional pre/post-build step. In the user manual chapter "variable expansion" in the section "conditional evaluation" you will find an example.


--- Code: --- [[ if (PLATFORM ==  PLATFORM_MSW) { print (_T("cmd /c")); } else { print (_T("sh ")); } ]] <command>

--- End code ---

Bye,

Mario

ironhead:
How do I check a project specific Custom Variable?

I have SVN_BUILD = 0 in the projects Custom Variable tab, in the pre-build, for testing I have:


--- Code: ---[[ if ($SVN_BUILD ==  0) { print (_T("cmd /c")); } ]] echo hello

--- End code ---

But I get an expression expected error.  Am I accessing the Custom Variable in the wrong way?

thomas_on_vacation:
Fighting with a French keyboard on a public PC in the lounge (as usual, the airport nazis broke my laptop, like every time)... how the hell do they type in France...

Mario mixed up $if()  and [[ ]], you want to simply use $if().
I forgot whether or not the "else" branch is obligatory... so if it fails, you may have to add an  else{}.

[[ ]] does not know custom vars, it is for scripts.

So long and thanks for the fish, going back to holidays.

ironhead:
I'm getting there, I know have:


--- Code: ---$if(SVN_BUILD){cmd /c echo true}

--- End code ---

which works if I have:


--- Code: ---$if(0){cmd /c echo true}

--- End code ---

In that the 'true' clause isn't executed.  The problem is that when using SVN_BUILD (or $SVN_BUILD or $(SVN_BUILD)) the 'true' clause is always being execute, despite the fact that I've defined SVN_BUILD as '0' (or if I leave it undefined) in the Custom Variables tab.  I take it I'm missing something?

Navigation

[0] Message Index

[#] Next page

Go to full version