mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-02 11:47:56 +08:00
Merge pull request #313 from an-tao/ossp_uuid
This commit is contained in:
commit
20c43b3c2d
@ -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})
|
||||
|
7
cmake/tests/normal_uuid_lib_test.cc
Normal file
7
cmake/tests/normal_uuid_lib_test.cc
Normal file
@ -0,0 +1,7 @@
|
||||
#include <uuid.h>
|
||||
int main()
|
||||
{
|
||||
uuid_t uu;
|
||||
uuid_generate(uu);
|
||||
return 0;
|
||||
}
|
8
cmake/tests/ossp_uuid_lib_test.cc
Normal file
8
cmake/tests/ossp_uuid_lib_test.cc
Normal file
@ -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
Block a user