MantisBT - CMake
View Issue Details
0014252CMake(No Category)public2013-06-28 09:132016-06-10 14:31
Mojca Miklavec 
Kitware Robot 
normalminoralways
closedmoved 
x86_64-darwinMac OS X10.7.5
CMake 2.8.10.2 
 
0014252: Unsupported "-arch x86_64" mysteriously ends up in Fortran_FLAGS
http://public.kitware.com/pipermail/cmake-developers/2013-January/006230.html [^]

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, so no project that needs Fortran and CMake can be compiled (luckily there are not many such projects, but it's still a showstopper to switch to CMake).


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.
Compiled Root (root.cern.ch) or any minimal project which needs Fortran with

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" ../path/to/sources

In that 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>

The flag "-arch x86_64" shouldn't be there.
Citing http://public.kitware.com/pipermail/cmake-developers/2013-January/006230.html [^]

The "-arch" flag is hard-coded here:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmLocalGenerator.cxx;hb=v2.8.10.2#l1826 [^]

It was added to CMake way back when universal binary support was
first added to OS X under the assumption that all compilers that
would be used in combination with CMAKE_OSX_ARCHITECTURES would
support the flag. Obviously the assumption is wrong.

The hard-coded flag needs to be replaced with a lookup of a new
per-language platform information variable, perhaps called

 CMAKE_<LANG>_OSX_ARCHITECTURE_FLAG

-Brad


Some more links:
- 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://sft.its.cern.ch/jira/browse/ROOT-4874 [^] (not strictly related)
No tags attached.
Issue History
2013-06-28 09:13Mojca MiklavecNew Issue
2013-06-28 09:28Brad KingAdditional Information Updatedbug_revision_view_page.php?rev_id=1203#r1203
2013-06-28 09:31Brad KingNote Added: 0033397
2016-06-10 14:29Kitware RobotNote Added: 0042305
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0033397)
Brad King   
2013-06-28 09:31   
For reference, the full thread where we previously discussed this is here:

 http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/5876 [^]
(0042305)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.