Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: w1ck3dg0ph3r on March 07, 2012, 10:04:38 pm

Title: Cross-platform Pre/Post-Build Steps
Post by: w1ck3dg0ph3r on March 07, 2012, 10:04:38 pm
Hola!
Is there a way to make pre-build script cross-platform? I've looked into attaching a build script like that:
Code
function SetBuildOptions(base)
{
    if (PLATFORM == PLATFORM_MSW) {
        IO.Execute(_T("blahblah.bat"));
    } else {
        IO.Execute(_T("blahblah.sh"))
    }
}
But the problem is it gets executed three times during build process. Which could be a huge bummer, given script execution time. Maybe there is a way to determine which execution it is from the script that I've missed?
Thanks in advance.
Title: Re: Cross-platform Pre/Post-Build Steps
Post by: Jenna on March 07, 2012, 11:30:25 pm
You can use something like
Code
$if(PLATFORM == PLATFORM_MSW){ [[ print(_T("ls -l")); ]] }{ [[ print(_T("pwd")); ]] }
as pre- or post-build step.
Title: Re: Cross-platform Pre/Post-Build Steps
Post by: MortenMacFly on March 08, 2012, 06:50:39 am
Code
$if(PLATFORM == PLATFORM_MSW){ [[ print(_T("ls -l")); ]] }{ [[ print(_T("pwd")); ]] }
Besides the fact that ls -l is not a proper Windows command (except i.e. you have GnuWin32 installed) this is correct.
Title: Re: Cross-platform Pre/Post-Build Steps
Post by: w1ck3dg0ph3r on March 08, 2012, 11:56:19 am
Thanks, didn't knew that, could be useful.
But still, since build script is the only (am I wrong?) way to automatically build against different libs for different platforms, it would be nice to do abovementioned in build script too.
Title: Re: Cross-platform Pre/Post-Build Steps
Post by: oBFusCATed on March 08, 2012, 12:03:21 pm
Have you tried to use http://wiki.codeblocks.org/index.php?title=Global_compiler_variables ?
Title: Re: Cross-platform Pre/Post-Build Steps
Post by: w1ck3dg0ph3r on March 08, 2012, 03:29:02 pm
Have you tried to use http://wiki.codeblocks.org/index.php?title=Global_compiler_variables ?
Sure thing. But it doesn't cover different lib names. Anyhow, I ended up using smth like the following for now, and putting up with it being executed thrice.

Code
function SetBuildOptions(base)
{
    if (PLATFORM == PLATFORM_MSW)
    {
        IO.Execute(_T("qrc.bat"));

        base.AddLinkLib(_T("QtCore4"));
        base.AddLinkLib(_T("QtGui4"));
        base.AddLinkLib(_T("sqlite3"));
    }
    else if (PLATFORM == PLATFORM_GTK)
    {
        IO.Execute(_T("qrc.sh"))

        base.AddLinkLib(_T("QtCore"));
        base.AddLinkLib(_T("QtGui"));
        base.AddLinkLib(_T("sqlite3"));
    }
}

Interesting thing, though, even if attached to debug target, script getting executed when release target active. This (http://wiki.codeblocks.org/index.php?title=Build_scripts) one says "SetBuildOptions(base) is called before the project/target is built". I can assume it is called for every build target and project itself. Still maybe theres a way, that I don't know of, to tell which is the case for current execution?
Title: Re: Cross-platform Pre/Post-Build Steps
Post by: oBFusCATed on March 08, 2012, 03:47:08 pm
In fact you can specify different library names. See the cflags and lflags.
You can use something like #myvar.cflags and #myvar.lflags or even you can define some user fields.
I've not tried the user fields, but I guess they should just work.