Author Topic: Cross-platform Pre/Post-Build Steps  (Read 5820 times)

Offline w1ck3dg0ph3r

  • Single posting newcomer
  • *
  • Posts: 3
Cross-platform Pre/Post-Build Steps
« 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.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Cross-platform Pre/Post-Build Steps
« Reply #1 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.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Cross-platform Pre/Post-Build Steps
« Reply #2 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline w1ck3dg0ph3r

  • Single posting newcomer
  • *
  • Posts: 3
Re: Cross-platform Pre/Post-Build Steps
« Reply #3 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Cross-platform Pre/Post-Build Steps
« Reply #4 on: March 08, 2012, 12:03:21 pm »
(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!]

Offline w1ck3dg0ph3r

  • Single posting newcomer
  • *
  • Posts: 3
Re: Cross-platform Pre/Post-Build Steps
« Reply #5 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 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?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Cross-platform Pre/Post-Build Steps
« Reply #6 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.
(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!]