Skip to content

Commit

Permalink
Revert back to libuuid
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Jan 27, 2024
1 parent a9cdd71 commit 52c648a
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
uses: johnwason/vcpkg-action@v5
id: vcpkg
with:
pkgs: boost-locale curl gettext-libintl glib gtest jsoncpp libsecret maddy openssl stduuid
pkgs: boost-locale curl gettext-libintl glib gtest jsoncpp libsecret libuuid maddy openssl
triplet: x64-linux
cache-key: ${{ matrix.config.os }}
revision: 7032c5759f823fc8699a5c37d5f7072464ccb9a8
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: johnwason/vcpkg-action@v5
id: vcpkg
with:
pkgs: boost-locale curl gettext-libintl gtest jsoncpp maddy openssl stduuid
pkgs: boost-locale curl gettext-libintl gtest jsoncpp maddy openssl
triplet: x64-windows
cache-key: ${{ matrix.config.os }}
revision: 7032c5759f823fc8699a5c37d5f7072464ccb9a8
Expand Down
16 changes: 12 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ include(CTest)

#libnick Setup
add_compile_definitions(SQLITE_HAS_CODEC)
add_compile_definitions(UUID_SYSTEM_GENERATOR)
if(LINUX)
add_compile_definitions(HAVE_USLEEP)
endif()
Expand Down Expand Up @@ -76,8 +75,7 @@ find_package(CURL REQUIRED)
find_package(jsoncpp CONFIG REQUIRED)
find_package(Intl REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(stduuid CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost Boost::locale CURL::libcurl JsonCpp::JsonCpp Intl::Intl OpenSSL::SSL OpenSSL::Crypto stduuid)
target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost Boost::locale CURL::libcurl JsonCpp::JsonCpp Intl::Intl OpenSSL::SSL OpenSSL::Crypto)
if(USING_VCPKG)
find_package(unofficial-maddy CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC unofficial::maddy::maddy)
Expand All @@ -97,6 +95,16 @@ elseif(LINUX)
pkg_check_modules(gthread REQUIRED IMPORTED_TARGET gthread-2.0)
pkg_check_modules(libsecret REQUIRED IMPORTED_TARGET libsecret-1)
target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads PkgConfig::glib PkgConfig::gio PkgConfig::gmodule PkgConfig::gobject PkgConfig::gthread PkgConfig::libsecret)
if(USING_VCPKG)
find_package(unofficial-libuuid CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC unofficial::UUID::uuid)
else()
find_package(Libuuid REQUIRED)
if(Libuuid_FOUND)
target_include_directories(${PROJECT_NAME} INTERFACE ${Libuuid_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} INTERFACE ${Libuuid_LIBRARIES})
endif()
endif()
endif()

#libnick Install
Expand All @@ -107,7 +115,7 @@ install(TARGETS ${PROJECT_NAME} EXPORT "${PROJECT_NAME}Targets" LIBRARY DESTINAT
install(DIRECTORY "${CMAKE_SOURCE_DIR}/include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}")
install(FILES "${CMAKE_BINARY_DIR}/cmake/${PROJECT_NAME}.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
install(EXPORT "${PROJECT_NAME}Targets" FILE "${PROJECT_NAME}Targets.cmake" NAMESPACE ${PROJECT_NAME}:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
install(FILES "${CMAKE_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake" "${CMAKE_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
install(FILES "${CMAKE_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake" "${CMAKE_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake" "${CMAKE_SOURCE_DIR}/cmake/FindLibuuid.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
export(EXPORT "${PROJECT_NAME}Targets" FILE "${CMAKE_BINARY_DIR}/cmake/${PROJECT_NAME}Targets.cmake" NAMESPACE ${PROJECT_NAME}::)

#libnick Test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ The following are a list of dependencies used by libnick.
- maddy
- openssl
- Used for sqlcipher, as libnick manually includes and compiles sqlcipher.
- stduuid

### Linux Only
The above dependencies must be installed, plus the following for linux systems:
- glib
- libsecret
- libuuid

## Consuming libnick via vcpkg
libnick is available through `vcpkg`.
Expand Down
17 changes: 17 additions & 0 deletions cmake/FindLibuuid.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
find_path(Libuuid_INCLUDE_DIRS uuid/uuid.h)
find_library(Libuuid_LIBRARIES uuid)

if(Libuuid_LIBRARIES AND Libuuid_INCLUDE_DIRS)
set(Libuuid_FOUND YES)
if(NOT Libuuid_FIND_QUIETLY)
message(STATUS "Found libuuid: ${Libuuid_LIBRARIES}")
endif()
else()
if(Libuuid_FIND_REQUIRED)
message(SEND_ERROR "Could NOT find libuuid")
else()
if(NOT Libuuid_FIND_QUIETLY)
message(STATUS "Could NOT find libuuid")
endif()
endif()
endif()
40 changes: 28 additions & 12 deletions cmake/config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/libnickTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
include(CMakeFindDependencyMacro)

if(DEFINED ENV{VCPKG_ROOT})
file(TO_CMAKE_PATH $ENV{VCPKG_ROOT} VCPKG_ROOT)
if(EXISTS "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
set(USING_VCPKG ON)
endif()
endif()

find_dependency(Boost REQUIRED COMPONENTS locale)
find_dependency(CURL REQUIRED)
find_dependency(jsoncpp REQUIRED)
find_dependency(jsoncpp CONFIG REQUIRED)
find_dependency(Intl REQUIRED)
find_dependency(OpenSSL REQUIRED)
find_dependency(unofficial-maddy REQUIRED)
if(USING_VCPKG)
find_dependency(unofficial-maddy REQUIRED)
else()
find_dependency(maddy REQUIRED)
endif()
if(LINUX)
find_dependency(Threads REQUIRED)
find_dependency(PkgConfig REQUIRED)
pkg_check_modules(glib REQUIRED IMPORTED_TARGET glib-2.0)
pkg_check_modules(gio REQUIRED IMPORTED_TARGET gio-2.0)
pkg_check_modules(gmodule REQUIRED IMPORTED_TARGET gmodule-2.0)
pkg_check_modules(gobject REQUIRED IMPORTED_TARGET gobject-2.0)
pkg_check_modules(gthread REQUIRED IMPORTED_TARGET gthread-2.0)
pkg_check_modules(libsecret REQUIRED IMPORTED_TARGET libsecret-1)
find_dependency(unofficial-libuuid CONFIG REQUIRED)
find_dependency(Threads REQUIRED)
find_dependency(PkgConfig REQUIRED)
pkg_check_modules(glib REQUIRED IMPORTED_TARGET glib-2.0)
pkg_check_modules(gio REQUIRED IMPORTED_TARGET gio-2.0)
pkg_check_modules(gmodule REQUIRED IMPORTED_TARGET gmodule-2.0)
pkg_check_modules(gobject REQUIRED IMPORTED_TARGET gobject-2.0)
pkg_check_modules(gthread REQUIRED IMPORTED_TARGET gthread-2.0)
pkg_check_modules(libsecret REQUIRED IMPORTED_TARGET libsecret-1)
if(USING_VCPKG)
find_dependency(unofficial-libuuid CONFIG REQUIRED)
else()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
find_dependency(Libuuid REQUIRED)
endif()
endif()

check_required_components(libnick)
4 changes: 0 additions & 4 deletions include/helpers/stringhelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING

#ifndef UUID_SYSTEM_GENERATOR
#define UUID_SYSTEM_GENERATOR
#endif

#include <string>
#include <type_traits>
#include <vector>
Expand Down
61 changes: 59 additions & 2 deletions src/helpers/stringhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
#include <regex>
#include <sstream>
#include <curl/curl.h>
#include <stduuid/uuid.h>
#ifdef _WIN32
#include <windows.h>
#elif defined(__linux__)
#include <uuid/uuid.h>
#endif

namespace Nickvision
{
Expand Down Expand Up @@ -85,7 +89,60 @@ namespace Nickvision

std::string StringHelpers::newGuid() noexcept
{
return uuids::to_string(uuids::uuid_system_generator{}());
std::array<unsigned char, 16> guid;
#ifdef _WIN32
GUID win;
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if (CoCreateGuid(&win) != S_OK)
{
return "";
}
guid = {
(unsigned char)((win.Data1 >> 24) & 0xFF),
(unsigned char)((win.Data1 >> 16) & 0xFF),
(unsigned char)((win.Data1 >> 8) & 0xFF),
(unsigned char)((win.Data1) & 0xff),

(unsigned char)((win.Data2 >> 8) & 0xFF),
(unsigned char)((win.Data2) & 0xff),

(unsigned char)((win.Data3 >> 8) & 0xFF),
(unsigned char)((win.Data3) & 0xFF),

(unsigned char)win.Data4[0],
(unsigned char)win.Data4[1],
(unsigned char)win.Data4[2],
(unsigned char)win.Data4[3],
(unsigned char)win.Data4[4],
(unsigned char)win.Data4[5],
(unsigned char)win.Data4[6],
(unsigned char)win.Data4[7]
};
#elif defined(__linux__)
uuid_generate(guid.data());
#endif
std::ostringstream out;
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[0]);
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[1]);
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[2]);
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[3]);
out << "-";
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[4]);
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[5]);
out << "-";
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[6]);
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[7]);
out << "-";
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[8]);
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[9]);
out << "-";
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[10]);
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[11]);
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[12]);
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[13]);
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[14]);
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[15]);
return out.str();
}

bool StringHelpers::isValidUrl(const std::string& s) noexcept
Expand Down

0 comments on commit 52c648a

Please sign in to comment.