3rdParty-devel: Introduce rhash-tohex.cmake

Upstream rhash requires to define RHASH_XVERSION as:

printf "0x%02x%02x%02x%02x" major minor patch 0

However, the CMakeLists.txt introduced by the experimental branch [1]
did not include this definition.

Since calculating this string requires complex string manipulation in
CMake, a new file, namely rhash-tohex.cmake, and a function with the
same name have been introduced.


git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9569 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: f4600f8fdd048d6638cfb600443c7c15e87cbc5e
Former-commit-id: 42557b46093e35d032de3d3aa7cf190ab5da3e9b
This commit is contained in:
xavi92 2024-10-27 07:45:42 +00:00
parent d84bbd1140
commit e31ceadeb0
2 changed files with 18 additions and 0 deletions

View file

@ -2,6 +2,7 @@
cmake_minimum_required(VERSION 3.1)
project(rhash)
include(rhash-tohex.cmake)
file(READ "version.h" versionfile)
string(REGEX MATCH "#define VERSION \"([0-9]*)\.([0-9]*)\.([0-9]*)\"" _ ${versionfile})
@ -9,6 +10,11 @@ set(RHASH_VERSION_MAJOR ${CMAKE_MATCH_1})
set(RHASH_VERSION_MINOR ${CMAKE_MATCH_2})
set(RHASH_VERSION_PATCH ${CMAKE_MATCH_3})
set(RHASH_VERSION "${RHASH_VERSION_MAJOR}.${RHASH_VERSION_MINOR}.${RHASH_VERSION_PATCH}")
rhash_tohex(${RHASH_VERSION_MAJOR} RHASH_XVERSION_MAJOR)
rhash_tohex(${RHASH_VERSION_MINOR} RHASH_XVERSION_MINOR)
rhash_tohex(${RHASH_VERSION_PATCH} RHASH_XVERSION_PATCH)
# The last two zeros are equivalent to "printf %02x 0".
set(RHASH_XVERSION "0x${RHASH_XVERSION_MAJOR}${RHASH_XVERSION_MINOR}${RHASH_XVERSION_PATCH}00")
option(USE_GETTEXT "Enable gettext (localization) support")
@ -46,6 +52,7 @@ add_subdirectory("librhash")
add_executable(${CMAKE_PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES})
target_link_libraries(${CMAKE_PROJECT_NAME} librhash)
target_compile_definitions(librhash PRIVATE RHASH_XVERSION=${RHASH_XVERSION})
if (USE_GETTEXT)
find_package(Intl REQUIRED)

View file

@ -0,0 +1,11 @@
function(rhash_tohex in out)
math(EXPR hex "${in}" OUTPUT_FORMAT HEXADECIMAL)
string(SUBSTRING ${hex} 2 -1 clean_hex)
string(LENGTH ${clean_hex} length)
if(length LESS 2)
string(PREPEND clean_hex "0")
endif()
set(${out} ${clean_hex} PARENT_SCOPE)
endfunction()