2016-09-27 22:01:08 +03:00
|
|
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
# file Copyright.txt or https://cmake.org/licensing for details.
|
2014-04-23 12:33:16 +04:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
2014-06-05 15:05:20 +04:00
|
|
|
set(_compiler_id_simulate_${CompilerId} ${_compiler_id_simulate} PARENT_SCOPE)
|
2014-04-23 12:33:16 +04:00
|
|
|
set(_compiler_id_pp_test_${CompilerId} ${_compiler_id_pp_test} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
2014-04-23 12:46:47 +04:00
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
|
|
|
|
|
2014-04-23 12:33:16 +04:00
|
|
|
function(compiler_id_detection outvar lang)
|
|
|
|
|
|
|
|
if (NOT lang STREQUAL Fortran)
|
2014-05-07 14:25:39 +04:00
|
|
|
file(GLOB lang_files
|
2014-04-23 12:33:16 +04:00
|
|
|
"${CMAKE_ROOT}/Modules/Compiler/*-DetermineCompiler.cmake")
|
2014-05-07 14:25:39 +04:00
|
|
|
set(nonlang CXX)
|
|
|
|
if (lang STREQUAL CXX)
|
|
|
|
set(nonlang C)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
file(GLOB nonlang_files
|
|
|
|
"${CMAKE_ROOT}/Modules/Compiler/*-${nonlang}-DetermineCompiler.cmake")
|
|
|
|
list(REMOVE_ITEM lang_files ${nonlang_files})
|
2014-04-23 12:33:16 +04:00
|
|
|
endif()
|
|
|
|
|
2014-05-07 14:25:39 +04:00
|
|
|
set(files ${lang_files})
|
2014-04-23 12:33:16 +04:00
|
|
|
if (files)
|
|
|
|
foreach(file ${files})
|
|
|
|
_readFile(${file})
|
|
|
|
endforeach()
|
|
|
|
|
2014-04-23 14:10:04 +04:00
|
|
|
set(options ID_STRING VERSION_STRINGS ID_DEFINE PLATFORM_DEFAULT_COMPILER)
|
2014-04-23 13:00:28 +04:00
|
|
|
set(oneValueArgs PREFIX)
|
2014-04-23 12:46:47 +04:00
|
|
|
cmake_parse_arguments(CID "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
|
|
if (CID_UNPARSED_ARGUMENTS)
|
|
|
|
message(FATAL_ERROR "Unrecognized arguments: \"${CID_UNPARSED_ARGUMENTS}\"")
|
|
|
|
endif()
|
|
|
|
|
2014-05-07 14:25:39 +04:00
|
|
|
# Order is relevant here. For example, compilers which pretend to be
|
|
|
|
# GCC must appear before the actual GCC.
|
|
|
|
if (lang STREQUAL CXX)
|
|
|
|
list(APPEND ordered_compilers
|
|
|
|
Comeau
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
list(APPEND ordered_compilers
|
2014-04-23 12:33:16 +04:00
|
|
|
Intel
|
|
|
|
PathScale
|
|
|
|
Embarcadero
|
|
|
|
Borland
|
|
|
|
Watcom
|
|
|
|
OpenWatcom
|
|
|
|
SunPro
|
|
|
|
HP
|
|
|
|
Compaq
|
|
|
|
zOS
|
|
|
|
XL
|
|
|
|
VisualAge
|
|
|
|
PGI
|
|
|
|
Cray
|
|
|
|
TI
|
2014-08-11 00:55:44 +04:00
|
|
|
Fujitsu
|
2014-05-07 14:25:39 +04:00
|
|
|
)
|
|
|
|
if (lang STREQUAL C)
|
|
|
|
list(APPEND ordered_compilers
|
|
|
|
TinyCC
|
2016-03-20 12:42:19 +03:00
|
|
|
Bruce
|
2014-05-07 14:25:39 +04:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
list(APPEND ordered_compilers
|
2014-04-23 12:33:16 +04:00
|
|
|
SCO
|
2014-06-13 12:50:07 +04:00
|
|
|
AppleClang
|
|
|
|
Clang
|
2014-04-23 12:33:16 +04:00
|
|
|
GNU
|
|
|
|
MSVC
|
|
|
|
ADSP
|
|
|
|
IAR
|
2015-10-26 16:51:09 +03:00
|
|
|
ARMCC
|
2014-05-07 14:25:39 +04:00
|
|
|
)
|
|
|
|
if (lang STREQUAL C)
|
|
|
|
list(APPEND ordered_compilers
|
|
|
|
SDCC
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
list(APPEND ordered_compilers
|
2014-04-23 12:33:16 +04:00
|
|
|
MIPSpro)
|
|
|
|
|
2014-04-23 12:51:33 +04:00
|
|
|
if(CID_ID_DEFINE)
|
|
|
|
foreach(Id ${ordered_compilers})
|
2014-04-23 13:00:28 +04:00
|
|
|
set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}# define ${CID_PREFIX}COMPILER_IS_${Id} 0\n")
|
2014-04-23 12:51:33 +04:00
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
2014-04-23 12:33:16 +04:00
|
|
|
set(pp_if "#if")
|
2014-04-23 12:46:47 +04:00
|
|
|
if (CID_VERSION_STRINGS)
|
2014-04-23 12:51:33 +04:00
|
|
|
set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n/* Version number components: V=Version, R=Revision, P=Patch
|
2014-04-23 12:33:16 +04:00
|
|
|
Version date components: YYYY=Year, MM=Month, DD=Day */\n")
|
2014-04-23 12:46:47 +04:00
|
|
|
endif()
|
2014-04-23 12:33:16 +04:00
|
|
|
|
|
|
|
foreach(Id ${ordered_compilers})
|
|
|
|
if (NOT _compiler_id_pp_test_${Id})
|
|
|
|
message(FATAL_ERROR "No preprocessor test for \"${Id}\"")
|
|
|
|
endif()
|
2014-04-23 12:46:47 +04:00
|
|
|
set(id_content "${pp_if} ${_compiler_id_pp_test_${Id}}\n")
|
|
|
|
if (CID_ID_STRING)
|
2014-06-05 15:05:20 +04:00
|
|
|
set(PREFIX ${CID_PREFIX})
|
|
|
|
string(CONFIGURE "${_compiler_id_simulate_${Id}}" SIMULATE_BLOCK @ONLY)
|
2016-07-28 01:41:13 +03:00
|
|
|
string(APPEND id_content "# define ${CID_PREFIX}COMPILER_ID \"${Id}\"${SIMULATE_BLOCK}")
|
2014-04-23 12:46:47 +04:00
|
|
|
endif()
|
2014-04-23 12:51:33 +04:00
|
|
|
if (CID_ID_DEFINE)
|
2016-07-28 01:41:13 +03:00
|
|
|
string(APPEND id_content "# undef ${CID_PREFIX}COMPILER_IS_${Id}\n")
|
|
|
|
string(APPEND id_content "# define ${CID_PREFIX}COMPILER_IS_${Id} 1\n")
|
2014-04-23 12:51:33 +04:00
|
|
|
endif()
|
2014-04-23 12:46:47 +04:00
|
|
|
if (CID_VERSION_STRINGS)
|
2014-04-23 13:00:28 +04:00
|
|
|
set(PREFIX ${CID_PREFIX})
|
2014-06-05 15:14:54 +04:00
|
|
|
set(MACRO_DEC DEC)
|
|
|
|
set(MACRO_HEX HEX)
|
2014-04-23 13:00:28 +04:00
|
|
|
string(CONFIGURE "${_compiler_id_version_compute_${Id}}" VERSION_BLOCK @ONLY)
|
2016-07-28 01:41:13 +03:00
|
|
|
string(APPEND id_content "${VERSION_BLOCK}\n")
|
2014-04-23 12:46:47 +04:00
|
|
|
endif()
|
2014-04-23 12:33:16 +04:00
|
|
|
set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n${id_content}")
|
|
|
|
set(pp_if "#elif")
|
|
|
|
endforeach()
|
|
|
|
|
2014-04-23 14:10:04 +04:00
|
|
|
if (CID_PLATFORM_DEFAULT_COMPILER)
|
|
|
|
set(platform_compiler_detection "
|
2014-04-23 12:33:16 +04:00
|
|
|
/* 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)
|
2014-04-23 13:00:28 +04:00
|
|
|
# define ${CID_PREFIX}COMPILER_ID \"MIPSpro\"
|
2014-04-23 12:33:16 +04:00
|
|
|
|
|
|
|
#elif defined(__hpux) || defined(__hpua)
|
2014-04-23 13:00:28 +04:00
|
|
|
# define ${CID_PREFIX}COMPILER_ID \"HP\"
|
2014-04-23 12:33:16 +04:00
|
|
|
|
|
|
|
#else /* unknown compiler */
|
2014-04-23 13:00:28 +04:00
|
|
|
# define ${CID_PREFIX}COMPILER_ID \"\"")
|
2014-04-23 14:10:04 +04:00
|
|
|
endif()
|
2014-04-23 12:33:16 +04:00
|
|
|
|
2014-04-23 14:10:04 +04:00
|
|
|
set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n${platform_compiler_detection}\n#endif")
|
2014-04-23 12:33:16 +04:00
|
|
|
endif()
|
|
|
|
|
|
|
|
set(${outvar} ${CMAKE_${lang}_COMPILER_ID_CONTENT} PARENT_SCOPE)
|
|
|
|
endfunction()
|