Skip to content

Commit

Permalink
crypto: add support for CMake function check.
Browse files Browse the repository at this point in the history
  • Loading branch information
aleflm committed Jan 15, 2025
1 parent 01ee5d3 commit 38159c9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ if(BUILD_FOR_FUZZING)
endif()

include(ProcessConfigurations)
include(CheckFunctionExists)

include(TryAppendCXXFlags)
include(TryAppendLinkerFlag)
Expand Down
9 changes: 9 additions & 0 deletions cmake/module/TestAppendRequiredLibraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,12 @@ function(test_append_atomic_library target)
message(FATAL_ERROR "Cannot figure out how to use std::atomic.")
endif()
endfunction()

macro(check_function_exists_and_define FUNC_NAME TARGET_NAME SCOPE MACRO_NAME)
check_function_exists(${FUNC_NAME} ${MACRO_NAME})
if(${MACRO_NAME})
target_compile_definitions(${TARGET_NAME} ${SCOPE} ${MACRO_NAME}=0)
else()
target_compile_definitions(${TARGET_NAME} ${SCOPE} ${MACRO_NAME}=1)
endif()
endmacro()
18 changes: 18 additions & 0 deletions src/crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ add_library(bitcoin_crypto STATIC EXCLUDE_FROM_ALL
../support/cleanse.cpp
)

# Check all endian conversion functions for 16-bit
check_function_exists_and_define(htobe16 bitcoin_crypto PRIVATE HAVE_DECL_HTOBE16)
check_function_exists_and_define(htole16 bitcoin_crypto PRIVATE HAVE_DECL_HTOLE16)
check_function_exists_and_define(be16toh bitcoin_crypto PRIVATE HAVE_DECL_BE16TOH)
check_function_exists_and_define(le16toh bitcoin_crypto PRIVATE HAVE_DECL_LE16TOH)

# Check all endian conversion functions for 32-bit
check_function_exists_and_define(htobe32 bitcoin_crypto PRIVATE HAVE_DECL_HTOBE32)
check_function_exists_and_define(htole32 bitcoin_crypto PRIVATE HAVE_DECL_HTOLE32)
check_function_exists_and_define(be32toh bitcoin_crypto PRIVATE HAVE_DECL_BE32TOH)
check_function_exists_and_define(le32toh bitcoin_crypto PRIVATE HAVE_DECL_LE32TOH)

# Check all endian conversion functions for 64-bit
check_function_exists_and_define(htobe64 bitcoin_crypto PRIVATE HAVE_DECL_HTOBE64)
check_function_exists_and_define(htole64 bitcoin_crypto PRIVATE HAVE_DECL_HTOLE64)
check_function_exists_and_define(be64toh bitcoin_crypto PRIVATE HAVE_DECL_BE64TOH)
check_function_exists_and_define(le64toh bitcoin_crypto PRIVATE HAVE_DECL_LE64TOH)

target_link_libraries(bitcoin_crypto
PRIVATE
core_interface
Expand Down
1 change: 1 addition & 0 deletions src/crypto/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <stdint.h>
#include <string.h>
#include <endian.h>

#include "compat/endian.h"

Expand Down

0 comments on commit 38159c9

Please sign in to comment.