Project: Split the compiler id detection into a separate function.
This can be extended with parameters to control the output and re-used in other contexts.
This commit is contained in:
parent
9d285600d4
commit
9a083bce83
|
@ -0,0 +1,99 @@
|
||||||
|
|
||||||
|
#=============================================================================
|
||||||
|
# Copyright 2014 Stephen Kelly <steveire@gmail.com>
|
||||||
|
#
|
||||||
|
# Distributed under the OSI-approved BSD License (the "License");
|
||||||
|
# see accompanying file Copyright.txt for details.
|
||||||
|
#
|
||||||
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||||
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
# See the License for more information.
|
||||||
|
#=============================================================================
|
||||||
|
# (To distribute this file outside of CMake, substitute the full
|
||||||
|
# License text for the above reference.)
|
||||||
|
|
||||||
|
function(_readFile file)
|
||||||
|
include(${file})
|
||||||
|
get_filename_component(name ${file} NAME_WE)
|
||||||
|
string(REGEX REPLACE "-.*" "" CompilerId ${name})
|
||||||
|
set(_compiler_id_version_compute_${CompilerId} ${_compiler_id_version_compute} PARENT_SCOPE)
|
||||||
|
set(_compiler_id_pp_test_${CompilerId} ${_compiler_id_pp_test} PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(compiler_id_detection outvar lang)
|
||||||
|
|
||||||
|
file(GLOB lang_files
|
||||||
|
"${CMAKE_ROOT}/Modules/Compiler/*-${lang}-DetermineCompiler.cmake")
|
||||||
|
|
||||||
|
if (NOT lang STREQUAL Fortran)
|
||||||
|
file(GLOB non_lang_files
|
||||||
|
"${CMAKE_ROOT}/Modules/Compiler/*-DetermineCompiler.cmake")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(files ${lang_files} ${non_lang_files})
|
||||||
|
if (files)
|
||||||
|
foreach(file ${files})
|
||||||
|
_readFile(${file})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
set(ordered_compilers
|
||||||
|
# Order is relevant here. For example, compilers which pretend to be
|
||||||
|
# GCC must appear before the actual GCC.
|
||||||
|
Comeau
|
||||||
|
Intel
|
||||||
|
PathScale
|
||||||
|
AppleClang
|
||||||
|
Clang
|
||||||
|
Embarcadero
|
||||||
|
Borland
|
||||||
|
Watcom
|
||||||
|
OpenWatcom
|
||||||
|
SunPro
|
||||||
|
HP
|
||||||
|
Compaq
|
||||||
|
zOS
|
||||||
|
XL
|
||||||
|
VisualAge
|
||||||
|
PGI
|
||||||
|
Cray
|
||||||
|
TI
|
||||||
|
SCO
|
||||||
|
GNU
|
||||||
|
MSVC
|
||||||
|
ADSP
|
||||||
|
IAR
|
||||||
|
MIPSpro)
|
||||||
|
|
||||||
|
set(pp_if "#if")
|
||||||
|
set(CMAKE_${lang}_COMPILER_ID_CONTENT "/* Version number components: V=Version, R=Revision, P=Patch
|
||||||
|
Version date components: YYYY=Year, MM=Month, DD=Day */\n")
|
||||||
|
|
||||||
|
foreach(Id ${ordered_compilers})
|
||||||
|
if (NOT _compiler_id_pp_test_${Id})
|
||||||
|
message(FATAL_ERROR "No preprocessor test for \"${Id}\"")
|
||||||
|
endif()
|
||||||
|
set(id_content "${pp_if} ${_compiler_id_pp_test_${Id}}\n# define COMPILER_ID \"${Id}\"${_compiler_id_version_compute_${Id}}\n")
|
||||||
|
set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n${id_content}")
|
||||||
|
set(pp_if "#elif")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
set(platform_compiler_detection "
|
||||||
|
/* These compilers are either not known or too old to define an
|
||||||
|
identification macro. Try to identify the platform and guess that
|
||||||
|
it is the native compiler. */
|
||||||
|
#elif defined(__sgi)
|
||||||
|
# define COMPILER_ID \"MIPSpro\"
|
||||||
|
|
||||||
|
#elif defined(__hpux) || defined(__hpua)
|
||||||
|
# define COMPILER_ID \"HP\"
|
||||||
|
|
||||||
|
#else /* unknown compiler */
|
||||||
|
# define COMPILER_ID \"\"
|
||||||
|
|
||||||
|
#endif")
|
||||||
|
|
||||||
|
set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n${platform_compiler_detection}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(${outvar} ${CMAKE_${lang}_COMPILER_ID_CONTENT} PARENT_SCOPE)
|
||||||
|
endfunction()
|
|
@ -97,13 +97,7 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
|
||||||
set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
|
set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(_readFile file)
|
include(CMakeCompilerIdDetection)
|
||||||
include(${file})
|
|
||||||
get_filename_component(name ${file} NAME_WE)
|
|
||||||
string(REGEX REPLACE "-.*" "" CompilerId ${name})
|
|
||||||
set(_compiler_id_version_compute_${CompilerId} ${_compiler_id_version_compute} PARENT_SCOPE)
|
|
||||||
set(_compiler_id_pp_test_${CompilerId} ${_compiler_id_pp_test} PARENT_SCOPE)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Function to write the compiler id source file.
|
# Function to write the compiler id source file.
|
||||||
|
@ -111,73 +105,7 @@ function(CMAKE_DETERMINE_COMPILER_ID_WRITE lang src)
|
||||||
find_file(src_in ${src}.in PATHS ${CMAKE_ROOT}/Modules ${CMAKE_MODULE_PATH} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
|
find_file(src_in ${src}.in PATHS ${CMAKE_ROOT}/Modules ${CMAKE_MODULE_PATH} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
|
||||||
file(READ ${src_in} ID_CONTENT_IN)
|
file(READ ${src_in} ID_CONTENT_IN)
|
||||||
|
|
||||||
file(GLOB lang_files
|
compiler_id_detection(CMAKE_${lang}_COMPILER_ID_CONTENT ${lang})
|
||||||
"${CMAKE_ROOT}/Modules/Compiler/*-${lang}-DetermineCompiler.cmake")
|
|
||||||
|
|
||||||
if (NOT lang STREQUAL Fortran)
|
|
||||||
file(GLOB non_lang_files
|
|
||||||
"${CMAKE_ROOT}/Modules/Compiler/*-${lang}-DetermineCompiler.cmake")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(files ${lang_files} ${non_lang_files})
|
|
||||||
if (files)
|
|
||||||
foreach(file ${files})
|
|
||||||
_readFile(${file})
|
|
||||||
endforeach()
|
|
||||||
set(pp_if "#if")
|
|
||||||
set(CMAKE_CXX_COMPILER_ID_CONTENT "/* Version number components: V=Version, R=Revision, P=Patch
|
|
||||||
Version date components: YYYY=Year, MM=Month, DD=Day */\n")
|
|
||||||
|
|
||||||
foreach(Id
|
|
||||||
Comeau
|
|
||||||
Intel
|
|
||||||
PathScale
|
|
||||||
AppleClang
|
|
||||||
Clang
|
|
||||||
Embarcadero
|
|
||||||
Borland
|
|
||||||
Watcom
|
|
||||||
OpenWatcom
|
|
||||||
SunPro
|
|
||||||
HP
|
|
||||||
Compaq
|
|
||||||
zOS
|
|
||||||
XL
|
|
||||||
VisualAge
|
|
||||||
PGI
|
|
||||||
Cray
|
|
||||||
TI
|
|
||||||
SCO
|
|
||||||
GNU
|
|
||||||
MSVC
|
|
||||||
ADSP
|
|
||||||
IAR
|
|
||||||
MIPSpro)
|
|
||||||
if (NOT _compiler_id_pp_test_${Id})
|
|
||||||
message(FATAL_ERROR "No test for \"${Id}\"")
|
|
||||||
endif()
|
|
||||||
set(id_content "${pp_if} ${_compiler_id_pp_test_${Id}}\n# define COMPILER_ID \"${Id}\"${_compiler_id_version_compute_${Id}}\n")
|
|
||||||
set(CMAKE_CXX_COMPILER_ID_CONTENT "${CMAKE_CXX_COMPILER_ID_CONTENT}\n${id_content}")
|
|
||||||
set(pp_if "#elif")
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
set(platform_compiler_detection "
|
|
||||||
/* These compilers are either not known or too old to define an
|
|
||||||
identification macro. Try to identify the platform and guess that
|
|
||||||
it is the native compiler. */
|
|
||||||
#elif defined(__sgi)
|
|
||||||
# define COMPILER_ID \"MIPSpro\"
|
|
||||||
|
|
||||||
#elif defined(__hpux) || defined(__hpua)
|
|
||||||
# define COMPILER_ID \"HP\"
|
|
||||||
|
|
||||||
#else /* unknown compiler */
|
|
||||||
# define COMPILER_ID \"\"
|
|
||||||
|
|
||||||
#endif")
|
|
||||||
|
|
||||||
set(CMAKE_CXX_COMPILER_ID_CONTENT "${CMAKE_CXX_COMPILER_ID_CONTENT}\n${platform_compiler_detection}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
unset(src_in CACHE)
|
unset(src_in CACHE)
|
||||||
string(CONFIGURE "${ID_CONTENT_IN}" ID_CONTENT_OUT @ONLY)
|
string(CONFIGURE "${ID_CONTENT_IN}" ID_CONTENT_OUT @ONLY)
|
||||||
|
|
Loading…
Reference in New Issue