Fix mbedtls finding on macos (#156)
This commit is contained in:
parent
cfb4b5bd51
commit
1b98afe37d
@ -65,12 +65,12 @@ add_executable(imhex ${application_type}
|
||||
)
|
||||
|
||||
set_target_properties(imhex PROPERTIES CXX_VISIBILITY_PRESET hidden)
|
||||
target_link_directories(imhex PRIVATE ${MBEDTLS_LIBRARY_DIRS} ${CAPSTONE_LIBRARY_DIRS} ${MAGIC_LIBRARY_DIRS})
|
||||
target_link_directories(imhex PRIVATE ${CAPSTONE_LIBRARY_DIRS} ${MAGIC_LIBRARY_DIRS})
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(imhex libdl.a libmagic.a libgnurx.a libtre.a libintl.a libiconv.a libshlwapi.a libcapstone.a LLVMDemangle libimhex ${Python_LIBRARIES} wsock32 ws2_32)
|
||||
elseif (UNIX)
|
||||
target_link_libraries(imhex magic mbedtls ${CMAKE_DL_LIBS} capstone LLVMDemangle libimhex ${Python_LIBRARIES} dl)
|
||||
target_link_libraries(imhex magic ${CMAKE_DL_LIBS} capstone LLVMDemangle libimhex ${Python_LIBRARIES} dl)
|
||||
endif()
|
||||
|
||||
createPackage()
|
@ -36,12 +36,7 @@ macro(findLibraries)
|
||||
# Find packages
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
||||
pkg_search_module(MBEDTLS mbedtls)
|
||||
if(NOT MBEDTLS_FOUND)
|
||||
find_library(MBEDTLS mbedtls REQUIRED)
|
||||
else()
|
||||
set(MBEDTLS_INCLUDE_DIRS ${MBEDTLS_INCLUDEDIR})
|
||||
endif()
|
||||
find_package(mbedTLS REQUIRED)
|
||||
|
||||
pkg_search_module(CAPSTONE REQUIRED capstone)
|
||||
|
||||
|
70
cmake/modules/FindmbedTLS.cmake
Normal file
70
cmake/modules/FindmbedTLS.cmake
Normal file
@ -0,0 +1,70 @@
|
||||
# - Try to find mbedTLS
|
||||
# Once done this will define
|
||||
#
|
||||
# Read-Only variables
|
||||
# MBEDTLS_FOUND - system has mbedTLS
|
||||
# MBEDTLS_INCLUDE_DIR - the mbedTLS include directory
|
||||
# MBEDTLS_LIBRARY_DIR - the mbedTLS library directory
|
||||
# MBEDTLS_LIBRARIES - Link these to use mbedTLS
|
||||
# MBEDTLS_LIBRARY - path to mbedTLS library
|
||||
# MBEDX509_LIBRARY - path to mbedTLS X.509 library
|
||||
# MBEDCRYPTO_LIBRARY - path to mbedTLS Crypto library
|
||||
|
||||
# Copyright (c) 2004-2007 Sara Golemon <sarag@libssh2.org>
|
||||
# Copyright (c) 2005,2006 Mikhail Gusarov <dottedmag@dottedmag.net>
|
||||
# Copyright (c) 2006-2007 The Written Word, Inc.
|
||||
# Copyright (c) 2007 Eli Fant <elifantu@mail.ru>
|
||||
# Copyright (c) 2009-2019 Daniel Stenberg
|
||||
# Copyright (C) 2008, 2009 Simon Josefsson
|
||||
# All rights reserved.
|
||||
|
||||
|
||||
FIND_PATH(MBEDTLS_INCLUDE_DIR mbedtls/version.h)
|
||||
|
||||
SET(MBEDTLS_FIND_QUIETLY TRUE)
|
||||
|
||||
FIND_LIBRARY(MBEDTLS_LIBRARY NAMES mbedtls libmbedtls libmbedx509)
|
||||
FIND_LIBRARY(MBEDX509_LIBRARY NAMES mbedx509 libmbedx509)
|
||||
FIND_LIBRARY(MBEDCRYPTO_LIBRARY NAMES mbedcrypto libmbedcrypto)
|
||||
|
||||
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
|
||||
SET(MBEDTLS_FOUND TRUE)
|
||||
ENDIF()
|
||||
|
||||
IF(MBEDTLS_FOUND)
|
||||
# split mbedTLS into -L and -l linker options, so we can set them for pkg-config
|
||||
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH)
|
||||
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE)
|
||||
GET_FILENAME_COMPONENT(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE)
|
||||
GET_FILENAME_COMPONENT(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE)
|
||||
STRING(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE})
|
||||
STRING(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE})
|
||||
STRING(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE})
|
||||
SET(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}")
|
||||
|
||||
IF(NOT MBEDTLS_FIND_QUIETLY)
|
||||
MESSAGE(STATUS "Found mbedTLS:")
|
||||
FILE(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT)
|
||||
STRING(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT})
|
||||
IF (MBEDTLSMATCH)
|
||||
STRING(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH})
|
||||
MESSAGE(STATUS " version ${MBEDTLS_VERSION}")
|
||||
ENDIF(MBEDTLSMATCH)
|
||||
MESSAGE(STATUS " TLS: ${MBEDTLS_LIBRARY}")
|
||||
MESSAGE(STATUS " X509: ${MBEDX509_LIBRARY}")
|
||||
MESSAGE(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}")
|
||||
ENDIF(NOT MBEDTLS_FIND_QUIETLY)
|
||||
ELSE(MBEDTLS_FOUND)
|
||||
IF(MBEDTLS_FIND_REQUIRED)
|
||||
MESSAGE(FATAL_ERROR "Could not find mbedTLS")
|
||||
ENDIF(MBEDTLS_FIND_REQUIRED)
|
||||
ENDIF(MBEDTLS_FOUND)
|
||||
|
||||
MARK_AS_ADVANCED(
|
||||
MBEDTLS_INCLUDE_DIR
|
||||
MBEDTLS_LIBRARY_DIR
|
||||
MBEDTLS_LIBRARIES
|
||||
MBEDTLS_LIBRARY
|
||||
MBEDX509_LIBRARY
|
||||
MBEDCRYPTO_LIBRARY
|
||||
)
|
@ -37,7 +37,8 @@ add_library(libimhex SHARED
|
||||
source/views/view.cpp
|
||||
)
|
||||
|
||||
target_include_directories(libimhex PUBLIC include)
|
||||
target_include_directories(libimhex PUBLIC include ${MBEDTLS_INCLUDE_DIR})
|
||||
target_link_directories(libimhex PUBLIC ${MBEDTLS_LIBRARY_DIR})
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(libimhex PUBLIC imgui nlohmann_json libmbedcrypto.a)
|
||||
|
@ -99,16 +99,6 @@ namespace hex {
|
||||
return std::string(buffer.data(), buffer.data() + size);
|
||||
}
|
||||
|
||||
inline std::string toBinaryString(hex::integral auto number) {
|
||||
if (number == 0) return "0";
|
||||
|
||||
std::string result;
|
||||
for (u8 bit = std::bit_width(number); bit > 0; bit--)
|
||||
result += (number & (0b1 << bit)) == 0 ? '0' : '1';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr inline u64 extract(u8 from, u8 to, const hex::unsigned_integral auto &value) {
|
||||
using ValueType = std::remove_cvref_t<decltype(value)>;
|
||||
ValueType mask = (std::numeric_limits<ValueType>::max() >> (((sizeof(value) * 8) - 1) - (from - to))) << to;
|
||||
@ -190,6 +180,16 @@ namespace hex {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
inline std::string toBinaryString(hex::integral auto number) {
|
||||
if (number == 0) return "0";
|
||||
|
||||
std::string result;
|
||||
for (u8 bit = hex::bit_width(number); bit > 0; bit--)
|
||||
result += (number & (0b1 << bit)) == 0 ? '0' : '1';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#define SCOPE_EXIT(func) ScopeExit TOKEN_CONCAT(scopeGuard, __COUNTER__)([&] { func })
|
||||
class ScopeExit {
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user