1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
5 function(_readFile file)
7 get_filename_component(name ${file} NAME_WE)
8 string(REGEX REPLACE "-.*" "" CompilerId ${name})
9 set(_compiler_id_version_compute_${CompilerId} ${_compiler_id_version_compute} PARENT_SCOPE)
10 set(_compiler_id_simulate_${CompilerId} ${_compiler_id_simulate} PARENT_SCOPE)
11 set(_compiler_id_pp_test_${CompilerId} ${_compiler_id_pp_test} PARENT_SCOPE)
14 function(compiler_id_detection outvar lang)
16 if (NOT "x${lang}" STREQUAL "xFortran" AND NOT "x${lang}" STREQUAL "xCSharp"
17 AND NOT "x${lang}" STREQUAL "xISPC")
19 "${CMAKE_ROOT}/Modules/Compiler/*-DetermineCompiler.cmake")
21 if ("x${lang}" STREQUAL "xCXX")
25 file(GLOB nonlang_files
26 "${CMAKE_ROOT}/Modules/Compiler/*-${nonlang}-DetermineCompiler.cmake")
27 list(REMOVE_ITEM lang_files ${nonlang_files})
30 set(files ${lang_files})
32 foreach(file ${files})
36 set(options ID_STRING VERSION_STRINGS ID_DEFINE PLATFORM_DEFAULT_COMPILER)
37 set(oneValueArgs PREFIX)
38 cmake_parse_arguments(CID "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
39 if (CID_UNPARSED_ARGUMENTS)
40 message(FATAL_ERROR "Unrecognized arguments: \"${CID_UNPARSED_ARGUMENTS}\"")
43 # Order is relevant here. For example, compilers which pretend to be
44 # GCC must appear before the actual GCC.
45 if ("x${lang}" STREQUAL "xCXX")
46 list(APPEND ordered_compilers
50 list(APPEND ordered_compilers
75 if ("x${lang}" STREQUAL "xC")
76 list(APPEND ordered_compilers
81 list(APPEND ordered_compilers
87 list(APPEND ordered_compilers
95 if ("x${lang}" STREQUAL "xC")
96 list(APPEND ordered_compilers
101 if("x${lang}" STREQUAL "xCUDA")
102 set(ordered_compilers NVIDIA Clang)
106 foreach(Id ${ordered_compilers})
107 string(APPEND CMAKE_${lang}_COMPILER_ID_CONTENT "# define ${CID_PREFIX}COMPILER_IS_${Id} 0\n")
109 # Hard-code definitions for compilers that are no longer supported.
110 string(APPEND CMAKE_${lang}_COMPILER_ID_CONTENT "# define ${CID_PREFIX}COMPILER_IS_MIPSpro 0\n")
114 if (CID_VERSION_STRINGS)
115 string(APPEND CMAKE_${lang}_COMPILER_ID_CONTENT "\n/* Version number components: V=Version, R=Revision, P=Patch
116 Version date components: YYYY=Year, MM=Month, DD=Day */\n")
119 foreach(Id ${ordered_compilers})
120 if (NOT _compiler_id_pp_test_${Id})
121 message(FATAL_ERROR "No preprocessor test for \"${Id}\"")
123 set(id_content "${pp_if} ${_compiler_id_pp_test_${Id}}\n")
125 set(PREFIX ${CID_PREFIX})
126 string(CONFIGURE "${_compiler_id_simulate_${Id}}" SIMULATE_BLOCK @ONLY)
127 string(APPEND id_content "# define ${CID_PREFIX}COMPILER_ID \"${Id}\"${SIMULATE_BLOCK}")
130 string(APPEND id_content "# undef ${CID_PREFIX}COMPILER_IS_${Id}\n")
131 string(APPEND id_content "# define ${CID_PREFIX}COMPILER_IS_${Id} 1\n")
133 if (CID_VERSION_STRINGS)
134 set(PREFIX ${CID_PREFIX})
137 string(CONFIGURE "${_compiler_id_version_compute_${Id}}" VERSION_BLOCK @ONLY)
138 string(APPEND id_content "${VERSION_BLOCK}\n")
140 string(APPEND CMAKE_${lang}_COMPILER_ID_CONTENT "\n${id_content}")
144 if (CID_PLATFORM_DEFAULT_COMPILER)
145 set(platform_compiler_detection "
146 /* These compilers are either not known or too old to define an
147 identification macro. Try to identify the platform and guess that
148 it is the native compiler. */
149 #elif defined(__hpux) || defined(__hpua)
150 # define ${CID_PREFIX}COMPILER_ID \"HP\"
152 #else /* unknown compiler */
153 # define ${CID_PREFIX}COMPILER_ID \"\"")
156 string(APPEND CMAKE_${lang}_COMPILER_ID_CONTENT "\n${platform_compiler_detection}\n#endif")
159 set(${outvar} ${CMAKE_${lang}_COMPILER_ID_CONTENT} PARENT_SCOPE)