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

@@ -34,6 +34,7 @@
# get compiler version
include (UseCompVer)
is_compiler_gcc_compatible ()
# reconstruct the compiler command line; this does NOT include the
# DEFINE_SYMBOL that is added for shared libraries. type is the TYPE
@@ -103,10 +104,23 @@ function (precompile_header
return ()
endif (NOT header)
# only support precompiled headers if the compiler is gcc >= 3.4
get_gcc_version (${language} GCC_VERSION)
if (GCC_VERSION)
if (GCC_VERSION VERSION_EQUAL 3.4 OR GCC_VERSION VERSION_GREATER 3.4)
# only support precompiled headers if the compiler is gcc >= 3.4 or clang
if (CXX_COMPAT_GCC)
if (CMAKE_COMPILER_IS_GNUCXX)
# genuine GCC; must test version
get_gcc_version (${language} GCC_VERSION)
if (GCC_VERSION VERSION_EQUAL 3.4 OR GCC_VERSION VERSION_GREATER 3.4)
set (_do_pch TRUE)
else ()
set (_do_pch FALSE)
endif ()
elseif (CMAKE_COMPILER_IS_CLANGXX)
# any Clang version that is new enough to compile us can do this
set (_do_pch TRUE)
else ()
set (_do_pch FALSE)
endif ()
if (_do_pch)
# command-line used to compile modules in this kind of target
compiler_cmdline (${language} ${type} _cmd _args)
@@ -150,8 +164,8 @@ function (precompile_header
# these flags need to be added to the target
set (${target} "${_pch_file}" PARENT_SCOPE)
set (${flags_name} "-Winvalid-pch -include ${_pch_dir}/${header}" PARENT_SCOPE)
endif (GCC_VERSION VERSION_EQUAL 3.4 OR GCC_VERSION VERSION_GREATER 3.4)
endif (GCC_VERSION)
endif ()
endif ()
endfunction (precompile_header
language type header tgt_kw target flgs_kw flags_name)