Problem 1335

Summary: CMake fails to detect Clang compiler
Product: Geant4 Reporter: Michael Kelsey <kelsey>
Component: cmakeAssignee: Ben Morgan <Ben.Morgan>
Status: CLOSED FIXED    
Severity: major CC: evagena
Priority: P5    
Version: 9.5   
Hardware: All   
OS: All   

Description Michael Kelsey 2012-07-10 00:50:28 CEST
Several users had problems using 9.5-patch-01 on their MacOSX Lion (10.7.x) systems.  The G4 installation would complete successfully with no errors or warnings, but they could not build any applications (e.g., examples/novice/*).

The failure is due to G4SYSTEM being set to "Darwin-UNSUPPORTED", where the "UNSUPPORTED" tag itself is a consequence of the default Lion compiler being "clang" instead of "g++".

In cmake/Modules/Geant4LibraryBuildOptions.cmake, the compiler string for G4SYSTEM is determined by:

#------------------------------------------------------------------------------
# Determine the backward compatible compiler name
#
if(CMAKE_COMPILER_IS_GNUCXX)
    set(GEANT4_COMPILER "g++")
elseif(MSVC)
    set(GEANT4_COMPILER "VC")
elseif(CMAKE_CXX_COMPILER MATCHES "icpc.*")
    set(GEANT4_COMPILER "icc")
else()
    set(GEANT4_COMPILER "UNSUPPORTED")
endif()

Notice that in 9.5-patch-01 (and also in the trunk of SVN), the "clang" string is not a valid option.  

I see that in SVN, the "icc" option has been modified.  A further modification is needed, and ought to be tagged to include in 9.5-patch-02, to support "clang".

As a temporary workaround, since g++ is available on Lion, I have instructed users to set the "CMAKE_COMPILER_IS_GNUCXX=ON" option.
Comment 1 Ben Morgan 2012-07-10 14:46:18 CEST
This is in progress. You can also use the GNU compilers on 10.7 (On Xcode > 4.3, the command line tools are needed) by running

CXX=g++ CC=gcc cmake <ARGS>
Comment 2 Ben Morgan 2012-07-10 16:03:47 CEST
Changing summary to identify core issue clearly.
Broaden platforms affect to all as Clang is cross-platform.
Comment 3 Ben Morgan 2012-07-10 16:11:56 CEST
Preliminary fix committed in r60366. Tag 'cmake-V09-05-36' proposed for testing.

Currently CMake > 2.8.1 is required as this has built in support for detecting Clang - Geant4's cmake system will need to backport this functionality for support of CMake 2.6.4-2.8.1, so I'm leaving this bug as ASSIGNED for now.
Comment 4 Ben Morgan 2012-09-14 11:46:49 CEST
Marking as LATER - and postponing to after 9.6

Problem is resolved for CMake > 2.8.1, so will add note on this in installation guide
Comment 5 Eleni Vagena 2012-11-20 10:36:08 CET
I am running OS X Mountain Lion (version 10.8). To jump over that issue type in your bash_profile

export CXX=g++ //makes GNU the default compiler for C++
export CC=gcc    //makes GNU the default compiler for C
Comment 6 Ben Morgan 2018-05-08 14:38:51 CEST
Resolved by CMake > 2.8.1, and in now required CMake 3