Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: exchg on April 03, 2017, 09:30:25 pm

Title: default flags for debug/release target
Post by: exchg on April 03, 2017, 09:30:25 pm
Hi to all,

Is it possible to redefine default compiler flags for debug and release build target ?
I want that every new project release target by default have -O3 flag for example.
Title: Re: default flags for debug/release target
Post by: oBFusCATed on April 03, 2017, 10:47:37 pm
Yes, change the template script you're using to create your projects.
Title: Re: default flags for debug/release target
Post by: BlueHazzard on April 03, 2017, 10:53:10 pm
Yes, change the template script you're using to create your projects.
This can be done by right click on the project type in the "new project wizard" and then hit "edit this script"
Title: Re: default flags for debug/release target
Post by: exchg on April 03, 2017, 11:01:53 pm
ah, got it!
is there any script documentation ?

update:

i just try to use target.AddCompilerOption(_T("-O3")); and it works but it's toggle both flags -o2 and -o3 and also send both to compiler.
is it some bug or i just need also to add something like target.RemoveCompilerOption(_T("-O2")); ?
Title: Re: default flags for debug/release target
Post by: oBFusCATed on April 04, 2017, 09:42:57 am
Have you inspected if the script adds the -O2 explicitly?
Title: Re: default flags for debug/release target
Post by: exchg on April 04, 2017, 12:45:05 pm
Have you inspected if the script adds the -O2 explicitly?
No there is no explicit flags modification, you can check yourself, this is default console application script.

the place which was modified:
Code
function SetupTarget(target,is_debug)
{
    ...
    if (is_debug)
    {
        ...
    }
    else
    {
        ...
        target.AddCompilerOption(_T("-O3")); // <-- Set -o3
    }

    // all done!
    return true;
}
Title: Re: default flags for debug/release target
Post by: Miguel Gimenez on April 04, 2017, 01:25:10 pm
Look at share\CodeBlocks\templates\wizard\common_functions.script, line 173 (or 201, depending on the compiler).
Title: Re: default flags for debug/release target
Post by: exchg on April 04, 2017, 01:48:47 pm
Look at share\CodeBlocks\templates\wizard\common_functions.script, line 173 (or 201, depending on the compiler).
Yep, now it is works fine, thanks a lot.

But i am not sure that this is good from architectural point of view, because my changes will be reset after first update.
Title: Re: default flags for debug/release target
Post by: oBFusCATed on April 05, 2017, 12:06:31 am
You can place your own templates in your user settings folder. These won't be overridden with the next update.