Skip to content

Commit

Permalink
Adding c++ 11 compile flag on Ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael authored and DeanF committed Dec 17, 2018
1 parent 78dc4eb commit 3dcc671
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
import os
import re
import sys
import platform
from distutils.core import setup, Extension, Command

MINIMUM_CYTHON_VERSION = '0.20'
BASE_DIR = os.path.dirname(__file__)
PY2 = sys.version_info[0] == 2
DEBUG = False

FLAG_PLATFORMS = ["ubuntu"]

# kludge; http://stackoverflow.com/a/37762853
try:
CLANG = os.environ['CC'] == 'clang'
Expand Down Expand Up @@ -75,6 +78,24 @@ def get_authors():
authors_f.close()
return ', '.join(authors)

def flag_platform():
# Some platforms require the `-std=c++11` flag. These are the platforms:
try:
return platform.linux_distribution()[0].lower() in FLAG_PLATFORMS
except:
return False

def add_cpp_flag():
# We add `-std=c++11` as a compiler flag in the following cases:
# 1. If the compiler is CLANG
# 2. If the platform requires the flag for compilaton

if CLANG:
return True
if flag_platform():
return True
return False

def main():
os.environ['GCC_COLORS'] = 'auto'
include_dirs = [os.path.join(re2_prefix, 'include')] if re2_prefix else []
Expand All @@ -84,7 +105,7 @@ def main():
] if re2_prefix else []
extra_compile_args = ['-O0', '-g'] if DEBUG else [
'-O3', '-march=native', '-DNDEBUG']
if CLANG:
if add_cpp_flag():
extra_compile_args.append('-std=c++11')
ext_modules = [
Extension(
Expand Down

0 comments on commit 3dcc671

Please sign in to comment.