I want to use different tricore-gcc.exe
for different project in windows OS
the two tricore-gcc.exe
are in the following paths and they are not in PATH:
C:\HighTec\toolchains\tricore\v4.6.3.0\bin\tricore-gcc.exe
C:\HighTec\toolchains\tricore\v4.9.2.0\bin\tricore-gcc.exe
My question is how to config it in waf?
Is compiler_c
only search msvc
, gcc
and clang
?
Thanks for any suggestion!
(I have searched in Stackoverflow, such as Specify different compilers in waf but I found no answer about how to set an absolute path in Windows )
my wscript
:
def options(opt):
print("start opt ------------------")
opt.load('compiler_c')
def configure(conf):
# here we are in default variant/env
# we load the default compiler, probably gcc
conf.load('compiler_c')
# config for tricore 4.6.3 variant
print("start ------------------")
conf.setenv('t463')
conf.env.CC = ['C:\HighTec\toolchains\tricore\v4.6.3.0\bin\tricore-gcc.exe']
conf.load('compiler_c')
# config for tricore 4.9.2 variant
print("start ------------------")
conf.setenv('t492')
conf.env.CC = ['C:\HighTec\toolchains\tricore\v4.9.2.0\bin\tricore-gcc.exe']
conf.load('compiler_c')
# back to default config
conf.setenv('')
def build(bld):
bld.program(source = 'main.c', target = 'myexe')
# this create variants commands and build directories
from waflib.Build import (
BuildContext,
CleanContext,
InstallContext,
UninstallContext,
)
for variant in ['t463', 't492']:
for context in [BuildContext, CleanContext, InstallContext, UninstallContext]:
name = context.__name__.replace('Context','').lower()
class tmp(context):
cmd = name + '_' + variant
variant = variant
I tested it and get the result:
D:\CX\15_waf\test1>python waf configure
start opt ------------------
Setting top to : D:\CX\15_waf\test1
Setting out to : D:\CX\15_waf\test1\build
Checking for 'msvc' (C compiler) : not found
Checking for 'gcc' (C compiler) : not found
Checking for 'clang' (C compiler) : not found
could not configure a C compiler!
(complete log in D:\CX\15_waf\test1\build\config.log)
The config.log
:
# project configured on Tue Dec 29 14:42:29 2020 by
# waf 2.0.21 (abi 20, python 30803f0 on win32)
# using waf configure
#
----------------------------------------
Setting top to D:\CX\15_waf\test1
----------------------------------------
Setting out to D:\CX\15_waf\test1\build
----------------------------------------
Checking for 'msvc' (C compiler)
['C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\vswhere.exe', '-products', '*', '-legacy', '-format', 'json']
from D:\CX\15_waf\test1: msvc: Impossible to find a valid architecture for building [] - []
not found
----------------------------------------
Checking for 'gcc' (C compiler)
find program=['gcc', 'cc'] paths=['C:\\Testwell\\CTC', 'C:\\Java\\j2sdk1.4.2_11\\bin', 'C:\\Windows\\system32', 'C:\\Windows', 'C:\\Windows\\System32\\Wbem', 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\', 'C:\\Program Files\\Intel\\WiFi\\bin\\', 'C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\', 'C:\\Program Files (x86)\\Common Files\\ETAS\\3rdParty1.0', 'C:\\Program Files (x86)\\Toolbase Client', 'C:\\Users\\xia.chen\\AppData\\Local\\Programs\\Microsoft VS Code\\bin', 'C:\\Users\\xia.chen\\AppData\\Local\\Programs\\Git\\cmd', 'C:\\HighTec\\toolchains\\tricore\\v4.9.2.0\\bin', 'D:\\tools\\Python38', 'D:\\tools\\Python38\\Scripts', 'C:\\HighTec\\toolchains\\tricore\\v4.9.2.0\\bin'] var='CC' -> None
from D:\CX\15_waf\test1: Could not find the program ['gcc', 'cc']
not found
----------------------------------------
Checking for 'clang' (C compiler)
find program=['clang'] paths=['C:\\Testwell\\CTC', 'C:\\Java\\j2sdk1.4.2_11\\bin', 'C:\\Windows\\system32', 'C:\\Windows', 'C:\\Windows\\System32\\Wbem', 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\', 'C:\\Program Files\\Intel\\WiFi\\bin\\', 'C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\', 'C:\\Program Files (x86)\\Common Files\\ETAS\\3rdParty1.0', 'C:\\Program Files (x86)\\Toolbase Client', 'C:\\Users\\xia.chen\\AppData\\Local\\Programs\\Microsoft VS Code\\bin', 'C:\\Users\\xia.chen\\AppData\\Local\\Programs\\Git\\cmd', 'C:\\HighTec\\toolchains\\tricore\\v4.9.2.0\\bin', 'D:\\tools\\Python38', 'D:\\tools\\Python38\\Scripts', 'C:\\HighTec\\toolchains\\tricore\\v4.9.2.0\\bin'] var='CC' -> None
from D:\CX\15_waf\test1: Could not find the program ['clang']
not found
from D:\CX\15_waf\test1: could not configure a C compiler!
Yes waf detect only supported compilers defined in compiler_c.
If your compiler is "compatible" as clang is compatible to gcc (ie its command line work the same) then you just have to define CC
:
from waflib import Logs
# this is to check only for gcc-like compiler, on win32, compiler_c begins with msvc
from waflib.Tools.compiler_c import c_compiler
c_compiler['win32'] = ['gcc']
def options(opt):
opt.load('compiler_c')
def configure(conf):
conf.setenv('t463')
conf.env.CC = ['c:/toolchains/tricore/v4.6.3.0/bin/tricore-gcc.exe']
conf.load('compiler_c')
conf.setenv('t492')
conf.env.CC = ['c:/toolchains/tricore/v4.9.2.0/bin/tricore-gcc.exe']
conf.load('compiler_c')
def build(bld):
Logs.info("Using compiler {}".format(bld.env.CC))
bld.program(source = 'main.c', target = 'myexe')
Note: I tested on Linux, no win32 box available :)
To detect a new "incompatible" compiler, you have to do something like:
from waflib.Tools.compiler_c import c_compiler
c_compiler['win32'] = ['tricore', 'msvc', 'gcc']
def options(opt):
opt.load('compiler_c')
def configure(cnf):
cnf.load('compiler_c')
def build(bld):
bld.program(source='main.c', target='myexe')
And define a tricore
tool to detect the compiler:
# from waflib/Tools/clang.py
from waflib.Tools import ccroot, ar, gcc
from waflib.Configure import conf
@conf
def find_tricore(conf):
cc = conf.find_program('tricore', var='CC')
conf.get_cc_version(cc)
conf.env.CC_NAME = 'tricore'
def configure(conf):
conf.find_tricore()
conf.find_ar()
conf.gcc_common_flags()
conf.gcc_modifier_platform()
conf.cc_load_tools()
conf.cc_add_flags()
conf.link_add_flags()
You can have a look at gcc.py
, clang.py
, suncc.py
or icc.py
for a compiler like gcc
. Look at msvc.py
for a compiler really different from gcc
.