cmake: hex: fix conversion of zero to hex

Previously, `to_hex(0 output)` would have placed `0x` into the `output`
variable, which is undesirable... this fix ensures that `0x0` is placed
into this variable if the input is zero.

Signed-off-by: Attie Grande <attie.grande@argentum-systems.co.uk>
This commit is contained in:
Attie Grande 2024-01-15 14:50:53 +00:00 committed by Fabio Baltieri
parent 554f2ba08e
commit 902751a19e

View file

@ -34,6 +34,10 @@ function(from_hex HEX DEC)
endfunction() endfunction()
function(to_hex DEC HEX) function(to_hex DEC HEX)
if(DEC EQUAL 0)
set(${HEX} "0x0" PARENT_SCOPE)
return()
endif()
while(DEC GREATER 0) while(DEC GREATER 0)
math(EXPR _val "${DEC} % 16") math(EXPR _val "${DEC} % 16")
math(EXPR DEC "${DEC} / 16") math(EXPR DEC "${DEC} / 16")