mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 16:32:14 -06:00
Modules: Use math() for hex to decimal conversion
math() can parse hex numbers prefixed with "0x" since 3.13.
This commit is contained in:
@@ -1094,17 +1094,7 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
|
||||
# The offset to the PE signature is stored at 0x3c.
|
||||
file(READ ${file} peoffsethex LIMIT 1 OFFSET 60 HEX)
|
||||
if(NOT peoffsethex STREQUAL "")
|
||||
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}")
|
||||
|
||||
math(EXPR peoffset "0x${peoffsethex}")
|
||||
file(READ ${file} peheader LIMIT 6 OFFSET ${peoffset} HEX)
|
||||
if(peheader STREQUAL "50450000a201")
|
||||
set(ARCHITECTURE_ID "SH3")
|
||||
|
||||
@@ -573,37 +573,6 @@ if(_OpenSSL_has_dependencies)
|
||||
_OpenSSL_add_dependencies( OPENSSL_LIBRARIES )
|
||||
endif()
|
||||
|
||||
function(from_hex HEX DEC)
|
||||
string(TOUPPER "${HEX}" HEX)
|
||||
set(_res 0)
|
||||
string(LENGTH "${HEX}" _strlen)
|
||||
|
||||
while (_strlen GREATER 0)
|
||||
math(EXPR _res "${_res} * 16")
|
||||
string(SUBSTRING "${HEX}" 0 1 NIBBLE)
|
||||
string(SUBSTRING "${HEX}" 1 -1 HEX)
|
||||
if (NIBBLE STREQUAL "A")
|
||||
math(EXPR _res "${_res} + 10")
|
||||
elseif (NIBBLE STREQUAL "B")
|
||||
math(EXPR _res "${_res} + 11")
|
||||
elseif (NIBBLE STREQUAL "C")
|
||||
math(EXPR _res "${_res} + 12")
|
||||
elseif (NIBBLE STREQUAL "D")
|
||||
math(EXPR _res "${_res} + 13")
|
||||
elseif (NIBBLE STREQUAL "E")
|
||||
math(EXPR _res "${_res} + 14")
|
||||
elseif (NIBBLE STREQUAL "F")
|
||||
math(EXPR _res "${_res} + 15")
|
||||
else()
|
||||
math(EXPR _res "${_res} + ${NIBBLE}")
|
||||
endif()
|
||||
|
||||
string(LENGTH "${HEX}" _strlen)
|
||||
endwhile()
|
||||
|
||||
set(${DEC} ${_res} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h")
|
||||
file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str
|
||||
REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*")
|
||||
@@ -620,16 +589,14 @@ if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h")
|
||||
"\\1;\\2;\\3;\\4;\\5" OPENSSL_VERSION_LIST "${openssl_version_str}")
|
||||
list(GET OPENSSL_VERSION_LIST 0 OPENSSL_VERSION_MAJOR)
|
||||
list(GET OPENSSL_VERSION_LIST 1 OPENSSL_VERSION_MINOR)
|
||||
from_hex("${OPENSSL_VERSION_MINOR}" OPENSSL_VERSION_MINOR)
|
||||
math(EXPR OPENSSL_VERSION_MINOR "0x${OPENSSL_VERSION_MINOR}")
|
||||
list(GET OPENSSL_VERSION_LIST 2 OPENSSL_VERSION_FIX)
|
||||
from_hex("${OPENSSL_VERSION_FIX}" OPENSSL_VERSION_FIX)
|
||||
math(EXPR OPENSSL_VERSION_FIX "0x${OPENSSL_VERSION_FIX}")
|
||||
list(GET OPENSSL_VERSION_LIST 3 OPENSSL_VERSION_PATCH)
|
||||
|
||||
if (NOT OPENSSL_VERSION_PATCH STREQUAL "00")
|
||||
from_hex("${OPENSSL_VERSION_PATCH}" _tmp)
|
||||
# 96 is the ASCII code of 'a' minus 1
|
||||
math(EXPR OPENSSL_VERSION_PATCH_ASCII "${_tmp} + 96")
|
||||
unset(_tmp)
|
||||
math(EXPR OPENSSL_VERSION_PATCH_ASCII "0x${OPENSSL_VERSION_PATCH} + 96")
|
||||
# Once anyone knows how OpenSSL would call the patch versions beyond 'z'
|
||||
# this should be updated to handle that, too. This has not happened yet
|
||||
# so it is simply ignored here for now.
|
||||
|
||||
Reference in New Issue
Block a user