diff --git a/doc/installation.rst b/doc/installation.rst index 63d32b9ae..436c8c79f 100644 --- a/doc/installation.rst +++ b/doc/installation.rst @@ -95,6 +95,26 @@ versions of Python 2.7 >= 2.7.4 or Python 3.x >= 3.2.4 downloaded from python.org. In all cases Xcode must be installed with 'UNIX Development Support'. +**Xcode 5.1**: Starting with version 5.1 the version of clang that ships with +Xcode throws an error when it encounters compiler flags it doesn't recognize. +This may cause C extension builds to fail with an error similar to:: + + clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future] + +There are workarounds:: + + # Apple specified workaround for Xcode 5.1 + # easy_install + $ ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future easy_install pymongo + # or pip + $ ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install pymongo + + # Alternative workaround using CFLAGS + # easy_install + $ CFLAGS=-Qunused-arguments easy_install pymongo + # or pip + $ CFLAGS=-Qunused-arguments pip install pymongo + Installing from source ---------------------- diff --git a/setup.py b/setup.py index 4b8bf0521..4f203b0fc 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,7 @@ import glob import os +import platform +import re import subprocess import sys import warnings @@ -44,6 +46,22 @@ finally: PY3 = sys.version_info[0] == 3 +# PYTHON-654 - Clang doesn't support -mno-fused-madd but the pythons Apple +# ships are built with it. This is a problem starting with Xcode 5.1 +# since clang 3.4 errors out when it encounters unrecognized compiler +# flags. This hack removes -mno-fused-madd from the CFLAGS automatically +# generated by distutils for Apple provided pythons, allowing C extension +# builds to complete without error. The inspiration comes from older +# versions of distutils.sysconfig.get_config_vars. +if sys.platform == 'darwin' and 'clang' in platform.python_compiler().lower(): + from distutils.sysconfig import get_config_vars + res = get_config_vars() + for key in ('CFLAGS', 'PY_CFLAGS'): + if key in res: + flags = res[key] + flags = re.sub('-mno-fused-madd', '', flags) + res[key] = flags + nose_config_options = { 'with-xunit': '1', # Write out nosetests.xml for CI. 'py3where': 'build', # Tell nose where to find tests under PY3.