Boost logo

Boost-Build :

From: Jurko Gospodnetić (jurko.gospodnetic_at_[hidden])
Date: 2008-08-22 17:58:25


   Hi Jim.

> I am building an executable that links against a vendor's API. The
> vendor supplies an object file that contains main(). So, if I build on
> windows, this works:
>
> exe JimTest : [ glob *.cpp ] [ glob *.c ]
> ..//MyLib
> C:/vendor_install/lib/main.obj
> ;
>
>
> However, my project must be built on both windows and unix. So, I need
> a way for the target rule to look like this on unix:
>
> exe JimTest : [ glob *.cpp ] [ glob *.c ]
> ..//MyLib
> /opt/vendor_path/lib/main.o
> ;
>
> Actually, I really want the vendor path set by an environment
> variable. How can I refer to an environment variable in a target rule,

   You can read environment variables by using the os.environ rule. For
example:

     import os ;
     local unga-unga = [ os.environ UNGA_UNGA ] ;
     ECHO $(unga-unga) ;

   should display the content of the UNGA_UNGA environment variable or
nothing in case the variable is not defined. You can test whether the
environment variable is not defined (as opposed to being defined as an
empty string) like this:

     import os ;
     local unga-unga = [ os.environ UNGA_UNGA ] ;
     if ( $(unga-unga)-is-not-empty )
     {
         ECHO "UNGA_UNGA defined as" '$(unga-unga)' ;
     }
     else
     {
         ECHO "UNGA_UNGA not defined." ;
     }

   There are also some commands that can be used for reading registry
values on Windows, in case you want your build to, for instance,
automatically detect where the vendor's library got installed to on your
system. But you'll have to dig into the manuals for that one or perhaps
sip through the tools/msvc.jam module for examples.

> and how can I get the correct extension for the object file?

   Use the <target-os> or <host-os> features (which you should choose
depends on what you want to accomplish) to condition which object file
you want to list as your source. See the .os-names constant in the
tools/builtin.jam module for a full list of supported os's or just use
the --debug-building option to display the properties used for building
your targets and see what target-os/host-os feature value gets set in
your case. My suggestion would be to do something like this:

     ###############################################
     #
     # Vendor provided object file targets.
     #
     ###############################################

     alias vendor-obj : C:/vendor_install/lib/main.obj :
         <target-os>windows ;
     alias vendor-obj : /opt/vendor_path/lib/main.o :
         <target-os>unix ;
     alias vendor-obj : /opt/vendor_path/lib/main.o :
         <target-os>linux ;

     ###############################################
     #
     # Main build.
     #
     ###############################################

     exe JimTest : [ glob *.cpp ] [ glob *.c ]
          ..//MyLib
          vendor-obj ;

   Hope this helps.

   Best regards,
     Jurko Gospodnetić


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk