-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix build on 64bit machines using GCC. - Add clang tool to silently use clang compiler when present. - Closes #7
- Loading branch information
Jamie Kirkpatrick
committed
Aug 30, 2010
1 parent
8857990
commit 0282472
Showing
3 changed files
with
136 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
############################################################################# | ||
## Copyright (c) 2009-2010 Alan Wright. All rights reserved. | ||
## Distributable under the terms of either the Apache License (Version 2.0) | ||
## or the GNU Lesser General Public License. | ||
############################################################################# | ||
|
||
from TaskGen import feature | ||
import Options | ||
import sys | ||
|
||
|
||
@feature('cc') | ||
def apply_clang(self): | ||
''' | ||
Replaced the default compiler with clang if required. | ||
''' | ||
if not getattr(self, 'clang', True) or Options.options.disable_clang: | ||
return | ||
self.env['CC'] = self.env['CLANG'] or self.env['CC'] | ||
if sys.platform == "darwin": | ||
# workaround problems with non-static inline functions | ||
# http://clang.llvm.org/compatibility.html | ||
self.env['CCFLAGS'] += ['-std=gnu89'] | ||
|
||
|
||
@feature('cc') | ||
def apply_clang_cpp(self): | ||
''' | ||
Replaced the default compiler with clang if required. | ||
''' | ||
if not getattr(self, 'clang', True) or Options.options.disable_clang: | ||
return | ||
self.env['CPP'] = self.env['CLANGPP'] or self.env['CXX'] | ||
self.env['CXX'] = self.env['CLANGPP'] or self.env['CXX'] | ||
if sys.platform == "darwin": | ||
self.env['shlib_CXXFLAGS'] = ['-fPIC'] | ||
|
||
|
||
def set_options(opt): | ||
""" | ||
Add options specific the codehash tool | ||
""" | ||
opt.add_option('--noclang', | ||
dest = 'disable_clang', | ||
action = 'store_true', | ||
default = False, | ||
help = 'disable the clang compiler if it is available') | ||
|
||
|
||
def detect(conf): | ||
search_paths = ['/Xcode4/usr/bin/'] if sys.platform == "darwin" else [] | ||
conf.find_program('clang', var='CLANG') | ||
conf.find_program('clang++', var='CLANGPP', path_list = search_paths) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
############################################################################# | ||
## Copyright (c) 2009-2010 Alan Wright. All rights reserved. | ||
## Distributable under the terms of either the Apache License (Version 2.0) | ||
## or the GNU Lesser General Public License. | ||
############################################################################# | ||
|
||
from TaskGen import feature, after | ||
from copy import copy | ||
import Task, ccroot | ||
import os | ||
|
||
cmd = '${CXX} ${CXXFLAGS} ${_CXXINCFLAGS} ${_CXXDEFFLAGS} ${SRC} -o ${TGT}' | ||
cls = Task.simple_task_type('gch', cmd, before='cc cxx', shell = False) | ||
cls.scan = ccroot.scan | ||
|
||
|
||
def requires_pch(task, pch_name): | ||
""" | ||
Determines if a task requires a PCH prefix header | ||
Assume that missing source files equate to "generated" sources | ||
and will require a PCH header. | ||
""" | ||
def is_include_line(line): | ||
line = line.strip() | ||
return line.startswith("#include") or line.startswith("#import") | ||
generated_sources = False | ||
for source_file in task.inputs: | ||
if not os.path.isfile(source_file.abspath()): | ||
generated_sources = True | ||
continue | ||
source_path = source_file.abspath() | ||
if source_file.suffix() not in ["cpp", "c"]: | ||
continue | ||
for line in open(source_path): | ||
if is_include_line(line): | ||
return line.find(pch_name) | ||
return generated_sources | ||
|
||
|
||
@feature('cxx') | ||
@after('apply_link', 'apply_incpaths') | ||
def process_pch(self): | ||
""" | ||
Routine to add PCH generation if a pch header was specified | ||
for a target. | ||
""" | ||
if not getattr(self, 'pch', None): | ||
return | ||
node = self.path.find_resource(self.pch) | ||
if not node: | ||
print "Invalid PCH specified for %s" % self | ||
return | ||
output = node.parent.find_or_declare(node.name + '.gch') | ||
pch_task = self.create_task('gch') | ||
pch_task.set_inputs(node) | ||
pch_task.set_outputs(output) | ||
altered_envs = [] | ||
for task in self.compiled_tasks: | ||
if not requires_pch(task, self.pch): | ||
continue | ||
task.env = task.env.copy() | ||
task.env.append_unique("CXXFLAGS", "-include%s" | ||
% output.abspath(self.env).replace(".gch", "")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters