summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeDetermineCompilerId.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2013-08-06 20:55:15 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2013-08-06 20:55:15 (GMT)
commit5b141a7b293bc26b35fc1b3320931f8cc16901a1 (patch)
tree297cf6ddb6ddfa87e9dddd639fa792106e659b7f /Modules/CMakeDetermineCompilerId.cmake
parent1ed726a46c11ac3b9836b210584cd90e91ae3174 (diff)
parentbd827f98efc1d4294b9a7d0fc134629b7507f4a1 (diff)
downloadCMake-5b141a7b293bc26b35fc1b3320931f8cc16901a1.zip
CMake-5b141a7b293bc26b35fc1b3320931f8cc16901a1.tar.gz
CMake-5b141a7b293bc26b35fc1b3320931f8cc16901a1.tar.bz2
Merge topic 'peheader'
bd827f9 WIN: Use COFF file header header for architecture detection (#14083)
Diffstat (limited to 'Modules/CMakeDetermineCompilerId.cmake')
-rw-r--r--Modules/CMakeDetermineCompilerId.cmake29
1 files changed, 29 insertions, 0 deletions
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake
index 9f2c797..ebd9ce0 100644
--- a/Modules/CMakeDetermineCompilerId.cmake
+++ b/Modules/CMakeDetermineCompilerId.cmake
@@ -330,6 +330,35 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
endif()
endforeach()
+ # Detect the exact architecture from the PE header.
+ if(WIN32)
+ # The offset to the PE signature is stored at 0x3c.
+ file(READ ${file} peoffsethex LIMIT 1 OFFSET 60 HEX)
+ string(SUBSTRING "${peoffsethex}" 0 1 peoffsethex1)
+ string(SUBSTRING "${peoffsethex}" 1 1 peoffsethex2)
+ set(peoffsetexpression "${peoffsethex1} * 16 + ${peoffsethex2}")
+ string(REPLACE "a" "10" peoffsetexpression "${peoffsetexpression}")
+ string(REPLACE "b" "11" peoffsetexpression "${peoffsetexpression}")
+ string(REPLACE "c" "12" peoffsetexpression "${peoffsetexpression}")
+ string(REPLACE "d" "13" peoffsetexpression "${peoffsetexpression}")
+ string(REPLACE "e" "14" peoffsetexpression "${peoffsetexpression}")
+ string(REPLACE "f" "15" peoffsetexpression "${peoffsetexpression}")
+ math(EXPR peoffset "${peoffsetexpression}")
+
+ file(READ ${file} peheader LIMIT 6 OFFSET ${peoffset} HEX)
+ if(peheader STREQUAL "50450000a201")
+ set(ARCHITECTURE_ID "SH3")
+ elseif(peheader STREQUAL "50450000a301")
+ set(ARCHITECTURE_ID "SH3DSP")
+ elseif(peheader STREQUAL "50450000a601")
+ set(ARCHITECTURE_ID "SH4")
+ elseif(peheader STREQUAL "50450000a801")
+ set(ARCHITECTURE_ID "SH5")
+ elseif(peheader STREQUAL "50450000c201")
+ set(ARCHITECTURE_ID "THUMB")
+ endif()
+ endif()
+
# Check if a valid compiler and platform were found.
if(COMPILER_ID AND NOT COMPILER_ID_TWICE)
set(CMAKE_${lang}_COMPILER_ID "${COMPILER_ID}")