Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify C++ compiler in waf

Tags:

c++

build

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.

like image 745
Amit Moscovich Avatar asked Feb 20 '15 01:02

Amit Moscovich


People also ask

What is WAF compiler?

Waf is a Python-based framework for configuring, compiling and installing applications. Here are perhaps the most important features of Waf: Automatic build order: the build order is computed from input and output files, among others. Automatic dependencies: tasks to execute are detected by hashing files and commands.


1 Answers

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')
like image 159
pingul Avatar answered Sep 28 '22 15:09

pingul