Amit Moscovich
Amit Moscovich

Reputation: 2898

Specify C++ compiler in waf

When building C++ code using the waf build system, can I choose a specific C++ compiler command?

While it is possible to run something like "CXX=g++-4.9 waf configure", or to get the same effect by setting os.environ['CXX'] in the wscript file, is there a 'proper' way of doing this?

i.e. What is the waf equivalent of setting the CXX variable in a Makefile.

Upvotes: 6

Views: 3519

Answers (1)

pingul
pingul

Reputation: 3473

It's a little bit odd how little documentation I've found on this topic. I made do by setting the environment variable in the configure function, as you mention in your question.

Here's a small example for the curious:

import os

def options(opt):
    opt.load('wak.tools')
    opt.load('compiler_cxx')

def configure(conf):
    conf.load('wak.tools')

    conf.env.CXX = "g++-4.9" # default compiler

    if os.environ['CXX']: # Pull in the compiler
        conf.env.CXX = os.environ['CXX'] # override default

    # Additional setup of variables

    conf.load('compiler_cxx') # Will use the compiler from the environment path

def build(bld):
    bld.program(
        target='test',
        includes='include',
        source='src/main.cpp')

Upvotes: 2

Related Questions