Question

Currently I can build my program using boost build in different platforms by setting the toolset and parameters in the command line. For example :

Linux

b2

MacOS

b2 toolset=clang cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++"

Is there a way to create a rule in the Jamroot file to decide which compiler to use based on the operating system? I am looking for something along these lines:

import os ;
if [ os.on-macos ] {
    using clang : <cxxflags>"-stdlib=libc++" <linkflags>"-stdlib=libc++c ;"
}

in linux it automatically decides to use gcc but in the mac if I don't specify the clang toolset it will try (without success) to compile it with gcc.

Just for reference, here is my current jamroot (any suggestions also appreciated):

# Project requirements (note, if running on a Mac you have to build foghorn with clang with libc++)
project myproject
    : requirements <cxxflags>-std=c++11 <linkflags>-std=c++11 ;

# Build  binaries in src
lib boost_program_options ;
exe app 
    : src/main.cpp src/utils src/tools boost_program_options 
;
Was it helpful?

Solution 2

After a long time I have found out that there is really no way (apart from very hacky) to do this. The goal of Boost.Build is to let the toolset option for the user to define.

The user has several ways to specify the toolset:

  1. in the command line with --toolset=gcc for example
  2. in the user configuration by setting it in the user-config.jam for all projects compiled by the user
  3. in the site configuration by setting it in the site-config.jam for all users

the user-config.jam can be in the user's $HOME or in the boost build path.

the site-config.jam should be in the /etc directory, but could also be in the two locations above.

In summary, setup your site-config or user-config for a pleasant experience, and write a nice README file for users trying to compile your program.

Hope this helps someone else.

OTHER TIPS

How abou using a Jamroot? I have the following in mine. It selects between two GCC versions on Linux, depending on what's in an environmen variable, and chooses vacpp on AIX.

if [ os.name ] = LINUX
{
    switch [ modules.peek : ODSHOME ]
    {
        case *gcc-4*    : using gcc : 4.4 : g++-4.4 ;

        case *gcc-3.3*  : using gcc : 3.3 : g++-3.3 ;

        case *          : error Only gcc v4 and gcc v3.3 supported. ;
    }

}
else if [ os.name ] = AIX
{
    using vacpp ;
}
else
{
    error Only Linux and AIX supported at present. ;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top