[cmake-developers] Unsupported "-arch x86_64" mysteriously ends up in Fortran_FLAGS

Mojca Miklavec mojca.miklavec.lists at gmail.com
Tue Jan 22 14:11:44 EST 2013


Dear CMake developers,

I'm a newbie to CMake (I've never written any project myself), but
while trying to install a physics package Root from the master of
    https://github.com/bbannier/ROOT (https://root.cern.ch/svn/root/trunk)
I realised that an unsupported compiler flag "-arch x86_64"
mysteriously sneaks into Fortran_FLAGS when
    -DCMAKE_OSX_ARCHITECTURES="x86_64"
is passed to cmake. That flag CMAKE_OSX_ARCHITECTURES is added
automatically to all projects in MacPorts (third-party package manager
for Mac OS X) even when cross-compiling or compilation of fat binaries
(like i386+x86_64) is not needed.

The g95 compiler ignores "-arch <...>" flag, but GCC's gfortran 4.x
throws an error and breaks compilation. I could probably try to
prevent DCMAKE_OSX_ARCHITECTURES from being passed to cmake (via some
tricks in MacPorts or by modifying MacPorts sources), but I still
believe that passing "-arch x86_64" to Fortran_FLAGS is a bug in
CMake. I tried to figure out when those flags are set, but I don't
know enough about CMake. I've seen several places where compiler flags
are simply copied from C to Fortran, for example here:

# Create a set of shared library variable specific to Fortran
# For 90% of the systems, these are the same flags as the C versions
# so if these are not set just copy the flags from the c version
if(NOT DEFINED CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS)
  set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS
${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
endif()

but I don't have enough knowledge to be able to track the problem down
to a single spot. There is a slight chance that the problematic flag
is introduced by the project, but there are other projects in MacPorts
suffering from the same symptoms.


The command that I used to compile Root:

cmake \
-DCMAKE_Fortran_COMPILER=/opt/local/bin/gfortran-mp-4.5 \
-DCMAKE_C_COMPILER=/usr/bin/clang \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
-DCMAKE_INSTALL_PREFIX=/path/to/install \
-DCMAKE_OSX_ARCHITECTURES="x86_64" ../root_trunk

In case that anyone would want to try it on the particular project,
the generated file
    misc/minicern/CMakeFiles/minicern.dir/flags.make
ends up containing the following variables (among others):
    C_FLAGS =  -m64 -pipe -W -Wall -fsigned-char -fno-common -O2 -g
-arch x86_64 -fPIC -I<path/to/some/include/dirs>
    Fortran_FLAGS =  -m64 -std=legacy -arch x86_64 -fPIC
-I<path/to/some/include/dirs>
(Another problem is that -std=legacy is not recognised by g95 and
throws another error, but that one is a bug in the project.) I also
didn't know how to disable Fortran compiler altogether, but that's a
completely different issue.

I'm using 64-bit Mac OS X 10.7.4, cmake version 2.8.10.

I would be very grateful for any insight about how to get rid of that
"-arch x86_64" flag. Thanks and best regards,
    Mojca

Related tickets:
- https://trac.macports.org/ticket/37732 (about the -arch flag in Fortran)
- https://trac.macports.org/ticket/37688 ([also] about development of
a package for Root using CMake)
- https://savannah.cern.ch/bugs/index.php?99944 (not strictly related though)



More information about the cmake-developers mailing list