Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: smacky on April 18, 2011, 12:10:53 pm

Title: Compiler defines from custom variables with embedded scripts
Post by: smacky on April 18, 2011, 12:10:53 pm
I define the following custom variable at the project level:

Code
<Variable name="port" value='&quot;[[ $if (PLATFORM == PLATFORM_MSW) { print(&quot;WIN32&quot;) } { print(&quot;LINUX&quot;) } ]]&quot;' />

Then use this variable in the compiler defines, also at the project level:

Code
<Add option="-D$(port)" />

This doesn't produce the desired result however. The build log tells me:

Code
<command-line>: error: macro names must be identifiers

IDK how to see the actual command line. My first thought was that the problem was that the script is itself within "..." but these seem to be inserted automatically by CB so I assume that is not the problem.

I have tried not using print():

Code
<Variable name="port" value='&quot;[[ $if (PLATFORM == PLATFORM_MSW) { WIN32 } { LINUX } ]]&quot;' />
     and
<Variable name="port" value='&quot;[[ $if (PLATFORM == PLATFORM_MSW) { return WIN32 } { return LINUX } ]]&quot;' />

But these both produce the same result. Any help?
Title: Re: Compiler defines from custom variables with embedded scripts
Post by: MortenMacFly on April 18, 2011, 12:51:24 pm
I don't know what exactly you are doing, but changing he project file at file level is not supposed to work. What's the content in the appropriate settings of your project?
Title: Re: Compiler defines from custom variables with embedded scripts
Post by: smacky on April 18, 2011, 01:45:50 pm
Possibly I'm approaching this entirely the wrong way.

The code is sometime 20-30 years old and (at least currently) has lots of conditional sections all over the place (#ifdef WIN32 ... #else ... #endif).

With make I simply define the appropriate port and off it goes.

My understanding/supposition was that I could use a single CB project in a similar way to compile for multiple platforms. Hence the above which is intended to replicate the make process.

Perhaps if I have per-platform targets with the correct platform option which have the appropriate -D... switch? Ie, Release-win32 and Release-linux which have <Add option="-DWIN32" /> and <Add option="-DLINUX" /> that would work better (well,  at all)?
Title: Re: Compiler defines from custom variables with embedded scripts
Post by: MortenMacFly on April 18, 2011, 03:24:24 pm
OK - you could do all with macros but I believe this won't make things simpler. At least when it comes to link libraries you will be lost sooner or later.

A good setup would be (as you've proposed) to have a project with different targets for the different platforms. You exclude the targets from compiling per platform by choosing the target's platform at the project settings. Then you can define platform specific flags at target level and common (same) flags at project level (you can choose per target how the combination is built, e.g. before project options, after or no project options at all. You can use virtual targets to have e.g. compile multiple (1..n) targets on a platform. Finally you can setup a compiler per target, if this is needed.

Consult the documentation of C::B how to setup things more detailed:
http://www.codeblocks.org/docs/main_codeblocks_en.html
Title: Re: Compiler defines from custom variables with embedded scripts
Post by: smacky on April 18, 2011, 03:55:01 pm
TYVM. I did set up the per-platform targets in between our two posts, and it works a treat. :)

Gotta read up about virtual targets...