mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-04 12:49:36 -06:00
CMakeDetermineCompilerId: Consider UTF-16 encodings of INFO strings
Our compiler identification source encodes `INFO:compiler[...]` and similar strings in compiled objects or binaries that we then extract to get information about the compiler. With most compilers the strings are encoded in the binaries as a simple byte sequence. However, some compilers use other encodings. For example, the MS CSharp compiler uses UTF-16LE and a TI compiler uses UTF-16BE. Try each encoding. Fixes: #19459
This commit is contained in:
@@ -18,7 +18,6 @@ if(NOT CMAKE_CSharp_COMPILER_ID_RUN)
|
||||
set(CMAKE_CSharp_COMPILER_ID_RUN 1)
|
||||
|
||||
# Try to identify the compiler.
|
||||
set(CMAKE_CSharp_COMPILER_ID_STRINGS_PARAMETERS ENCODING UTF-16LE)
|
||||
set(CMAKE_CSharp_COMPILER_ID)
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ID(CSharp CSFLAGS CMakeCSharpCompilerId.cs)
|
||||
|
||||
@@ -640,10 +640,14 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
|
||||
set(ARCHITECTURE_ID)
|
||||
set(SIMULATE_ID)
|
||||
set(SIMULATE_VERSION)
|
||||
file(STRINGS ${file}
|
||||
CMAKE_${lang}_COMPILER_ID_STRINGS LIMIT_COUNT 38
|
||||
${CMAKE_${lang}_COMPILER_ID_STRINGS_PARAMETERS}
|
||||
REGEX ".?I.?N.?F.?O.?:.?[A-Za-z0-9_]+\\[[^]]*\\]")
|
||||
foreach(encoding "" "ENCODING;UTF-16LE" "ENCODING;UTF-16BE")
|
||||
file(STRINGS "${file}" CMAKE_${lang}_COMPILER_ID_STRINGS
|
||||
LIMIT_COUNT 38 ${encoding}
|
||||
REGEX ".?I.?N.?F.?O.?:.?[A-Za-z0-9_]+\\[[^]]*\\]")
|
||||
if(NOT CMAKE_${lang}_COMPILER_ID_STRINGS STREQUAL "")
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
set(COMPILER_ID_TWICE)
|
||||
# With the IAR Compiler, some strings are found twice, first time as incomplete
|
||||
# list like "?<Constant "INFO:compiler[IAR]">". Remove the incomplete copies.
|
||||
|
||||
Reference in New Issue
Block a user