News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Cross-platform Pre/Post-Build Steps

Started by w1ck3dg0ph3r, March 07, 2012, 10:04:38 PM

Previous topic - Next topic

w1ck3dg0ph3r

Hola!
Is there a way to make pre-build script cross-platform? I've looked into attaching a build script like that:
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.

Jenna

You can use something like
$if(PLATFORM == PLATFORM_MSW){ [[ print(_T("ls -l")); ]] }{ [[ print(_T("pwd")); ]] }
as pre- or post-build step.

MortenMacFly

Quote from: jens on March 07, 2012, 11:30:25 PM
$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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

w1ck3dg0ph3r

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.

oBFusCATed

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

w1ck3dg0ph3r

Quote from: oBFusCATed on March 08, 2012, 12:03:21 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.

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 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?

oBFusCATed

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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]