waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

compiler_cxx.py (3309B)


      1 #!/usr/bin/env python
      2 # encoding: utf-8
      3 # Matthias Jahn jahn dôt matthias ât freenet dôt de 2007 (pmarat)
      4 
      5 """
      6 Try to detect a C++ compiler from the list of supported compilers (g++, msvc, etc)::
      7 
      8 	def options(opt):
      9 		opt.load('compiler_cxx')
     10 	def configure(cnf):
     11 		cnf.load('compiler_cxx')
     12 	def build(bld):
     13 		bld.program(source='main.cpp', target='app')
     14 
     15 The compilers are associated to platforms in :py:attr:`waflib.Tools.compiler_cxx.cxx_compiler`. To register
     16 a new C++ compiler named *cfoo* (assuming the tool ``waflib/extras/cfoo.py`` exists), use::
     17 
     18 	from waflib.Tools.compiler_cxx import cxx_compiler
     19 	cxx_compiler['win32'] = ['cfoo', 'msvc', 'gcc']
     20 
     21 	def options(opt):
     22 		opt.load('compiler_cxx')
     23 	def configure(cnf):
     24 		cnf.load('compiler_cxx')
     25 	def build(bld):
     26 		bld.program(source='main.c', target='app')
     27 
     28 Not all compilers need to have a specific tool. For example, the clang compilers can be detected by the gcc tools when using::
     29 
     30 	$ CXX=clang waf configure
     31 """
     32 
     33 
     34 import re
     35 from waflib.Tools import ccroot
     36 from waflib import Utils
     37 from waflib.Logs import debug
     38 
     39 cxx_compiler = {
     40 'win32':       ['msvc', 'g++', 'clang++'],
     41 'cygwin':      ['g++', 'clang++'],
     42 'darwin':      ['clang++', 'g++'],
     43 'aix':         ['xlc++', 'g++', 'clang++'],
     44 'linux':       ['g++', 'clang++', 'icpc'],
     45 'sunos':       ['sunc++', 'g++'],
     46 'irix':        ['g++'],
     47 'hpux':        ['g++'],
     48 'osf1V':       ['g++'],
     49 'gnu':         ['g++', 'clang++'],
     50 'java':        ['g++', 'msvc', 'clang++', 'icpc'],
     51 'gnukfreebsd': ['g++', 'clang++'],
     52 'default':     ['clang++', 'g++']
     53 }
     54 """
     55 Dict mapping the platform names to Waf tools finding specific C++ compilers::
     56 
     57 	from waflib.Tools.compiler_cxx import cxx_compiler
     58 	cxx_compiler['linux'] = ['gxx', 'icpc', 'suncxx']
     59 """
     60 
     61 def default_compilers():
     62 	build_platform = Utils.unversioned_sys_platform()
     63 	possible_compiler_list = cxx_compiler.get(build_platform, cxx_compiler['default'])
     64 	return ' '.join(possible_compiler_list)
     65 
     66 def configure(conf):
     67 	"""
     68 	Detects a suitable C++ compiler
     69 
     70 	:raises: :py:class:`waflib.Errors.ConfigurationError` when no suitable compiler is found
     71 	"""
     72 	try:
     73 		test_for_compiler = conf.options.check_cxx_compiler or default_compilers()
     74 	except AttributeError:
     75 		conf.fatal("Add options(opt): opt.load('compiler_cxx')")
     76 
     77 	for compiler in re.split('[ ,]+', test_for_compiler):
     78 		conf.env.stash()
     79 		conf.start_msg('Checking for %r (C++ compiler)' % compiler)
     80 		try:
     81 			conf.load(compiler)
     82 		except conf.errors.ConfigurationError as e:
     83 			conf.env.revert()
     84 			conf.end_msg(False)
     85 			debug('compiler_cxx: %r', e)
     86 		else:
     87 			if conf.env.CXX:
     88 				conf.end_msg(conf.env.get_flat('CXX'))
     89 				conf.env.COMPILER_CXX = compiler
     90 				conf.env.commit()
     91 				break
     92 			conf.env.revert()
     93 			conf.end_msg(False)
     94 	else:
     95 		conf.fatal('could not configure a C++ compiler!')
     96 
     97 def options(opt):
     98 	"""
     99 	This is how to provide compiler preferences on the command-line::
    100 
    101 		$ waf configure --check-cxx-compiler=gxx
    102 	"""
    103 	test_for_compiler = default_compilers()
    104 	opt.load_special_tools('cxx_*.py')
    105 	cxx_compiler_opts = opt.add_option_group('Configuration options')
    106 	cxx_compiler_opts.add_option('--check-cxx-compiler', default=None,
    107 		help='list of C++ compilers to try [%s]' % test_for_compiler,
    108 		dest="check_cxx_compiler")
    109 
    110 	for x in test_for_compiler.split():
    111 		opt.load('%s' % x)
    112