Recognize Clang to be a GCC-compatible compiler

Clang aims to be compatible with GCC when it comes to command-line
parameters. Where we enable functionality based on the presence of
a GCC-compiler, we can use the same functionality with Clang.

This patch introduces a new variable CXX_COMPAT_GCC which is true if
the compiler handles the same options as GCC, and this variable is
subsequently used in tests instead of CMAKE_COMPILER_IS_GNUCXX (which
remains if we need to test if we really have GCC, e.g. for version)
This commit is contained in:
Roland Kaufmann
2013-08-06 22:43:35 +02:00
parent 1951f796af
commit 52a36f77fa
8 changed files with 81 additions and 28 deletions

View File

@@ -2,6 +2,8 @@
include(TestCXXAcceptsFlag)
include (AddOptions)
include (UseCompVer)
is_compiler_gcc_compatible ()
# mapping from profile name (in CMAKE_BUILD_TYPE) to variable part
set (_prof_DEBUG "Debug")
@@ -11,7 +13,7 @@ set (_prof_RELEASE "Release;RelWithDebInfo;MinSizeRel")
# otherwise, turn them on. indicate to the code what we have done
# so it can turn on assertions etc.
if (CMAKE_COMPILER_IS_GNUCXX)
if (CXX_COMPAT_GCC)
# extra flags passed for optimization
set (_opt_flags "")
@@ -44,7 +46,7 @@ if (CMAKE_COMPILER_IS_GNUCXX)
# use these options for release builds - full optimization
add_options (ALL_LANGUAGES "${_prof_RELEASE}" ${_opt_rel} "-DNDEBUG" ${_opt_flags})
else (CMAKE_COMPILER_IS_GNUCXX)
else ()
# default information from system
foreach (lang IN ITEMS C CXX Fortran)
if (lang STREQUAL "Fortran")
@@ -59,4 +61,4 @@ else (CMAKE_COMPILER_IS_GNUCXX)
endif (NOT CMAKE_${lang}_FLAGS_${profile})
endforeach (profile)
endforeach (lang)
endif (CMAKE_COMPILER_IS_GNUCXX)
endif ()