Compiler flags detection in setup.py is incorrect

Issue #65 resolved
Jan Blechta created an issue

Detection of compiler flags is performed by running distutils.ccompiler.new_compiler() which is not necessarily the correct one used for actual compilation of FFC and JITing.

This is a show-stopper for some hashdist installs with custom compiler and appeared already as https://bitbucket.org/fenics-project/dolfin/issue/449 and http://fenicsproject.org/pipermail/fenics-support/2015-February/001277.html.

Comments (9)

  1. Corrado Maurini

    Exporting CXXFLAGS='-std=c++11’ before running a python fenics script is an effective workaround but the issue remains valid.

  2. Jan Blechta reporter

    The following patch could do the job on FFC side

    diff --git a/INSTALL b/INSTALL
    index df0423c..0cb5648 100644
    --- a/INSTALL
    +++ b/INSTALL
    @@ -5,6 +5,10 @@ To install FFC, type
     This will install FFC in the default Python path of your system,
     something like /usr/lib/python2.6/site-packages/.
    
    +To specify C++ compiler and/or compiler flags used for compiling UFC
    +and JITing, set environment variables CXX, CXXFLAGS respectively
    +before invoking setup.py.
    +
     The installation script requires the Python module distutils, which
     for Debian users is available with the python-dev package.  Other
     dependencies are listed in the file README.
    diff --git a/setup.py b/setup.py
    index 9dd02e1..21bfde9 100644
    --- a/setup.py
    +++ b/setup.py
    @@ -231,6 +231,9 @@ def run_install():
    
         # Check that compiler supports C++11 features
         cc = new_compiler()
    +    CXX = os.environ.get("CXX")
    +    if CXX:
    +        cc.set_executables(compiler_so=CXX)
         CXX_FLAGS = os.environ.get("CXXFLAGS", "")
         if has_cxx_flag(cc, "-std=c++11"):
             CXX_FLAGS += " -std=c++11"
    

    @johannes_ring, could you try it?

    Note the tricky thing in distutils/unixccompiler.py:_compile, it uses compiler_so, not compiler nor compiler_cxx.

    The rest would be to export CXX on hashdist side.

  3. Sean Farley

    Just to chime in from MacPorts but this was a surprising (perhaps more surprising that this isn't automatically solved within distutils) bug.

  4. Jan Blechta reporter

    @johannes_ring Ok. Can I have write access to FFC repo so that we don't have to deal with other repo?

  5. Johannes Ring

    Yes @blechta, I assume that is fine since you already have write access to the DOLFIN repository. I have given you write access to the FFC repository now.

  6. Log in to comment