Skip to content

Commit d79b596

Browse files
committed
Add logic to detect and discriminate C++-11.
1 parent 8a58f71 commit d79b596

4 files changed

Lines changed: 85 additions & 19 deletions

File tree

.travis.yml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,30 @@ dist: trusty
1111

1212
language: cpp
1313

14-
env:
15-
matrix:
16-
- PYTHON=python CCFLAGS=-std=c++98
17-
- PYTHON=python CCFLAGS=-std=c++11
18-
- PYTHON=python3 CCFLAGS=-std=c++98
19-
- PYTHON=python3 CCFLAGS=-std=c++11
20-
- PYTHON=python DOC=1
14+
matrix:
15+
include:
16+
- compiler: gcc
17+
env: CXX=g++ PYTHON=python CXXFLAGS=-std=c++98
18+
- compiler: gcc
19+
env: CXX=g++ PYTHON=python CXXFLAGS=-std=c++11
20+
- compiler: gcc
21+
env: CXX=g++ PYTHON=python3 CXXFLAGS=-std=c++98
22+
- compiler: gcc
23+
env: CXX=g++ PYTHON=python3 CXXFLAGS=-std=c++11
24+
- compiler: clang
25+
env: CXX=clang++ PYTHON=python3 CXXFLAGS=-std=c++98
26+
- compiler: clang
27+
env: CXX=clang++ PYTHON=python3 CXXFLAGS=-std=c++11
28+
- env: PYTHON=python DOC=1
2129
global:
2230
- secure: mqoxglbUN/At/r8O7nLVccGldnB1jvhLHNyYjfCXrdOD0GNX+TY2TS1+kIEv9Deg/P6X/QvrBa/ZzbDNryn3mDXBfOSy400ebSIUHHP3HtGHJShOGDyXedY3hZ/dqmxdV3p9hIxv4lcx1HPyC96s4wpiR0S9F1JBzD6scIabezM=
2331

24-
compiler:
25-
- gcc
26-
2732
addons:
2833
apt:
2934
sources:
3035
- ubuntu-toolchain-r-test
3136
packages:
37+
- scons
3238
- gcc-4.8
3339
- g++-4.8
3440
- clang
@@ -46,11 +52,14 @@ before_install:
4652
- sudo pip install future
4753

4854
install:
49-
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi
55+
56+
before_script:
57+
- scons --version
5058

5159
script:
5260
- scons config --python=$PYTHON
5361
- if [ "$DOC" ]; then scons doc; else scons && scons test; fi
5462

5563
after_success:
56-
- if [ "$DOC" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then .ci/upload_docs.sh; fi
64+
# Upload docs only when building upstream.
65+
- if [ "$DOC" -a "$TRAVIS_REPO_SLUG" = "boostorg/python" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then .ci/upload_docs.sh; fi

SConstruct

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import config
1212
import config.ui
1313
import platform
1414
import os
15-
15+
import subprocess
16+
import re
1617

1718
#
1819
# We try to mimic the typical autotools-workflow.
@@ -35,10 +36,23 @@ if not os.path.exists('bin.SCons/'):
3536
vars = Variables('bin.SCons/config.py', ARGUMENTS)
3637
config.add_options(vars)
3738
arch = ARGUMENTS.get('arch', platform.machine())
39+
env_vars = {}
40+
if 'CXX' in os.environ: env_vars['CXX'] = os.environ['CXX']
41+
if 'CXXFLAGS' in os.environ: env_vars['CXXFLAGS'] = os.environ['CXXFLAGS'].split()
3842
env = Environment(toolpath=['config/tools'],
3943
tools=['default', 'libs', 'tests', 'doc'],
4044
variables=vars,
41-
TARGET_ARCH=arch)
45+
TARGET_ARCH=arch,
46+
**env_vars)
47+
if 'gcc' in env['TOOLS']:
48+
# Earlier SCons versions (~ 2.3.0) can't handle CXX=clang++.
49+
version = subprocess.check_output([env['CXX'], '--version'])
50+
match = re.search(r'[0-9]+(\.[0-9]+)+', version)
51+
if match:
52+
version = match.group(0)
53+
else:
54+
version = 'unknown'
55+
env['CXXVERSION'] = version
4256

4357
Help(config.ui.help(vars, env) + """
4458
Variables are saved in bin.SCons/config.py and persist between scons invocations.

config/__init__.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from collections import OrderedDict
1212
import platform
1313
from . import ui
14+
from . import cxx
1415
from . import python
1516
from . import boost
1617

@@ -19,14 +20,17 @@ def add_options(vars):
1920
python.add_options(vars)
2021
boost.add_options(vars)
2122

23+
vars.Add('CXX')
2224
vars.Add('CPPPATH', converter=lambda v:v.split())
2325
vars.Add('CCFLAGS', converter=lambda v:v.split())
26+
vars.Add('CXXFLAGS', converter=lambda v:v.split())
2427
vars.Add('LIBPATH', converter=lambda v:v.split())
2528
vars.Add('LIBS', converter=lambda v:v.split())
2629
vars.Add('PYTHON')
2730
vars.Add('PYTHONLIBS')
2831
vars.Add('prefix')
29-
vars.Add('boostbook_prefix')
32+
vars.Add('boostbook_prefix',
33+
vars.Add('CXX11'))
3034

3135
ui.add_variable(vars, ("arch", "target architeture", platform.machine()))
3236
ui.add_variable(vars, ("toolchain", "toolchain to use", 'gcc'))
@@ -40,6 +44,7 @@ def add_options(vars):
4044

4145
def get_checks():
4246
checks = OrderedDict()
47+
checks['cxx'] = cxx.check
4348
checks['python'] = python.check
4449
checks['boost'] = boost.check
4550
return checks
@@ -64,7 +69,10 @@ def boost_suffix(env):
6469

6570
if env["layout"] == "versioned":
6671
if "gcc" in env["TOOLS"]:
67-
suffix += "-gcc" + "".join(env["CCVERSION"].split(".")[0:2])
72+
if env['CXX'] in ('clang', 'clang++'):
73+
suffix += "-clang" + "".join(env["CXXVERSION"].split(".")[0:2])
74+
else: # assume g++
75+
suffix += "-gcc" + "".join(env["CXXVERSION"].split(".")[0:2])
6876
if env["THREADING"] == "multi":
6977
suffix += "-mt"
7078
if env["DEBUG"]:
@@ -80,10 +88,15 @@ def prepare_build_dir(env):
8088
vars = {}
8189
env["boost_suffix"] = boost_suffix
8290
build_dir="bin.SCons"
91+
# FIXME: Support 'toolchain' variable properly.
92+
# For now, we simply check whether $CXX refers to clang or gcc.
8393
if "gcc" in env["TOOLS"]:
84-
build_dir+="/gcc-%s"%env["CCVERSION"]
85-
vars['CXXFLAGS'] = ['-ftemplate-depth-128', '-Wall']
86-
94+
if env['CXX'] in ('clang', 'clang++'):
95+
build_dir+="/clang-%s"%env["CXXVERSION"]
96+
else: # assume g++
97+
build_dir+="/gcc-%s"%env["CXXVERSION"]
98+
default_cxxflags = ['-ftemplate-depth-128', '-Wall', '-g', '-O2']
99+
vars['CXXFLAGS'] = env.get('CXXFLAGS', default_cxxflags)
87100
elif "msvc" in env["TOOLS"]:
88101
build_dir+="/msvc-%s"%env["MSVS_VERSION"]
89102
vars['BOOST_BUILD_DIR'] = build_dir

config/cxx.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Copyright (c) 2016 Stefan Seefeld
3+
# All rights reserved.
4+
#
5+
# Distributed under the Boost Software License, Version 1.0.
6+
# (See accompanying file LICENSE_1_0.txt or copy at
7+
# http://www.boost.org/LICENSE_1_0.txt)
8+
9+
from . import ui
10+
import os
11+
12+
def add_options(vars):
13+
14+
pass
15+
16+
def check(context):
17+
18+
source = r"""#if __cplusplus < 201103L
19+
#error no C++11
20+
#endif"""
21+
22+
context.Message('Checking for C++11 support...')
23+
24+
if not context.TryCompile(source, '.cpp'):
25+
context.env['CXX11'] = False
26+
context.Result(0)
27+
else:
28+
context.env['CXX11'] = True
29+
context.Result(1)
30+
return True

0 commit comments

Comments
 (0)