User forums > Using Code::Blocks
Conditional code in Code::Blocks project files
Ben Key:
Is it possible to add conditional code to a project files? For example I would like to be able to add compiler options that are only used on the Windows platform. I know I can accomplish this by having a Windows specific target, but my project file already has four targets (Debug x64, Debug x86, Release x64, and Release x86) and this approach would require me to add four more targets.
The WiX project, which also uses an XML based file format, supports the following syntax.
<?ifdef condition ?>
<?else?>
<?endif?>
Is a similar syntax supported in Code::Blocks project files?
I found the Conditional Evaluation section of the Variable expansion page on the Code::Blocks Wiki but it fails to provide any details regarding the syntax of the condition or any indication of whether or not it can be used for this purpose.
stahta01:
Found in a CB wxWidgets Project in the other compiler option section.
--- Code: ---[[if (PLATFORM == PLATFORM_MSW && (GetCompilerFactory().GetCompilerVersionString(_T("gcc")) >= _T("4.0.0"))) print(_T("-Wno-attributes"));]]
--- End code ---
The above code adds the Compiler Option of "-Wno-attributes" if using a gcc compiler >= version 4.0 on the Windows platform.
Look under CB scripting for more info.
Tim S.
Ben Key:
+stahta01
Can you give a more complete example? I am not certain how to incorporate this into a <Compiler> section of a CBP file.
To begin with, the syntax for options seems to be "<Add option={option} />." I do not see anything that tells me where to put the [[{code}]] stuff.
Second, what are PLATFORM and PLATFORM_MSW? Are these global variables that are available everywhere in Code::Blocks project files.
As for the Scripting Code::Blocks page, it seems to describe changes to the Code::Blocks scripts, not project files.
In short, your answer, while helpful, does not provide near enough information.
stahta01:
No more info from me.
Tim S.
Ben Key:
Can anyone give me more information on how to do this?
Navigation
[0] Message Index
[#] Next page
Go to full version