Skip to content

Commit f1637f1

Browse files
committed
Work around Xcode 5.1 build issues PYTHON-654
This patch attempts to work around the unrecognized cflag errors raised by clang 3.4 - shipped with Xcode 5.1.
1 parent 97be203 commit f1637f1

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

doc/installation.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,26 @@ versions of Python 2.7 >= 2.7.4 or Python 3.x >= 3.2.4 downloaded from
9595
python.org. In all cases Xcode must be installed with 'UNIX Development
9696
Support'.
9797

98+
**Xcode 5.1**: Starting with version 5.1 the version of clang that ships with
99+
Xcode throws an error when it encounters compiler flags it doesn't recognize.
100+
This may cause C extension builds to fail with an error similar to::
101+
102+
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
103+
104+
There are workarounds::
105+
106+
# Apple specified workaround for Xcode 5.1
107+
# easy_install
108+
$ ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future easy_install pymongo
109+
# or pip
110+
$ ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install pymongo
111+
112+
# Alternative workaround using CFLAGS
113+
# easy_install
114+
$ CFLAGS=-Qunused-arguments easy_install pymongo
115+
# or pip
116+
$ CFLAGS=-Qunused-arguments pip install pymongo
117+
98118
Installing from source
99119
----------------------
100120

setup.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import glob
22
import os
3+
import platform
4+
import re
35
import subprocess
46
import sys
57
import warnings
@@ -44,6 +46,22 @@
4446

4547
PY3 = sys.version_info[0] == 3
4648

49+
# PYTHON-654 - Clang doesn't support -mno-fused-madd but the pythons Apple
50+
# ships are built with it. This is a problem starting with Xcode 5.1
51+
# since clang 3.4 errors out when it encounters unrecognized compiler
52+
# flags. This hack removes -mno-fused-madd from the CFLAGS automatically
53+
# generated by distutils for Apple provided pythons, allowing C extension
54+
# builds to complete without error. The inspiration comes from older
55+
# versions of distutils.sysconfig.get_config_vars.
56+
if sys.platform == 'darwin' and 'clang' in platform.python_compiler().lower():
57+
from distutils.sysconfig import get_config_vars
58+
res = get_config_vars()
59+
for key in ('CFLAGS', 'PY_CFLAGS'):
60+
if key in res:
61+
flags = res[key]
62+
flags = re.sub('-mno-fused-madd', '', flags)
63+
res[key] = flags
64+
4765
nose_config_options = {
4866
'with-xunit': '1', # Write out nosetests.xml for CI.
4967
'py3where': 'build', # Tell nose where to find tests under PY3.

0 commit comments

Comments
 (0)