Author Topic: How can I use build scripts?  (Read 3157 times)

Offline blend

  • Multiple posting newcomer
  • *
  • Posts: 32
How can I use build scripts?
« on: February 22, 2009, 02:59:06 pm »
Hello,

Because I have some OS specific code and I need to make my library cross-platform, I decided to use build-scripts so as to link the right libraries on the right OS.
But it seems that I didn't code well the build script: a library which would normally be linked under linux is linked under windows and so makes the compilation failed!

Here is part of my build-script:

Code
function SetBuildOptions( compilerManager )
{
    if( compilerManager.SupportsCurrentPlatform( PLATFORM_X11 ) )
    {
        compilerManager.AddLinkLib( _T("X11") );//for example
    }
    else if( compilerManager.SupportsCurrentPlatform( PLATFORM_WIN ) )
    {
    //other libraries
    }
}
How to correctly do what I would like?

I use C::B 8.02 on Windows Vista.

Thank you for your help.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: How can I use build scripts?
« Reply #1 on: February 22, 2009, 03:43:01 pm »
Try
Quote
function SetBuildOptions( compilerManager )
{
    if( PLATFORM == PLATFORM_X11  )
    {
        compilerManager.AddLinkLib( _T("X11") );//for example
    }
    else if( PLATFORM == PLATFORM_MSW  )
    {
    //other libraries
    }
}

I think the wiki has an error in this case
See :
http://wiki.codeblocks.org/index.php?title=Scripting_commands#CompileOptionsBase

But SupportsCurrentPlatform is implemented as:

Code
bool CompileOptionsBase::SupportsCurrentPlatform() const
{
    if(platform::windows)
        return m_Platform & spWindows;
    if(platform::unix)
        return m_Platform & spUnix;
    if(platform::macosx)
        return m_Platform & spMac;

    return false;
}

in compileoptionsbase.cpp.

That means it returns true on all supported platforms.


EDIT:
I just corrected the wiki in this point.
« Last Edit: February 22, 2009, 03:46:04 pm by jens »

Offline blend

  • Multiple posting newcomer
  • *
  • Posts: 32
Re: How can I use build scripts?
« Reply #2 on: February 22, 2009, 05:53:59 pm »
Thank you so much! It works like a charm now  :D!

But if I do a cross-compilation from windows for linux, will it be correct?