Make a patch to support the ossp UUID Library
This commit is contained in:
parent
ea43d8127d
commit
0a990f4331
|
@ -107,6 +107,22 @@ find_package(UUID REQUIRED)
|
|||
target_include_directories(${PROJECT_NAME} PRIVATE ${UUID_INCLUDE_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${UUID_LIBRARIES})
|
||||
|
||||
try_compile(normal_uuid ${CMAKE_BINARY_DIR}/cmaketest
|
||||
${PROJECT_SOURCE_DIR}/cmake/tests/normal_uuid_lib_test.cc
|
||||
LINK_LIBRARIES ${UUID_LIBRARIES}
|
||||
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${UUID_INCLUDE_DIR}")
|
||||
try_compile(ossp_uuid ${CMAKE_BINARY_DIR}/cmaketest
|
||||
${PROJECT_SOURCE_DIR}/cmake/tests/ossp_uuid_lib_test.cc
|
||||
LINK_LIBRARIES ${UUID_LIBRARIES}
|
||||
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${UUID_INCLUDE_DIR}")
|
||||
if(normal_uuid)
|
||||
add_definitions(-DUSE_OSSP_UUID=0)
|
||||
elseif(ossp_uuid)
|
||||
add_definitions(-DUSE_OSSP_UUID=1)
|
||||
else()
|
||||
message(FATAL_ERROR "uuid lib error")
|
||||
endif()
|
||||
|
||||
find_package(ZLIB REQUIRED)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${ZLIB_INCLUDE_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${ZLIB_LIBRARIES})
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#include <uuid.h>
|
||||
int main()
|
||||
{
|
||||
uuid_t uu;
|
||||
uuid_generate(uu);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#include <uuid.h>
|
||||
int main()
|
||||
{
|
||||
uuid_t *uuid;
|
||||
uuid_create(&uuid);
|
||||
uuid_make(uuid, UUID_MAKE_V1);
|
||||
return 0;
|
||||
}
|
|
@ -260,9 +260,22 @@ std::set<std::string> splitStringToSet(const std::string &str,
|
|||
|
||||
std::string getUuid()
|
||||
{
|
||||
#if USE_OSSP_UUID
|
||||
uuid_t *uuid;
|
||||
uuid_create(&uuid);
|
||||
uuid_make(uuid, UUID_MAKE_V4);
|
||||
char *str{nullptr};
|
||||
size_t len{0};
|
||||
uuid_export(uuid, UUID_FMT_BIN, &str, &len);
|
||||
uuid_destroy(uuid);
|
||||
std::string ret(binaryStringToHex((const unsigned char *)str, len));
|
||||
free(str);
|
||||
return ret;
|
||||
#else
|
||||
uuid_t uu;
|
||||
uuid_generate(uu);
|
||||
return binaryStringToHex(uu, 16);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string base64Encode(const unsigned char *bytes_to_encode,
|
||||
|
|
Loading…
Reference in New Issue