From 375498a5a66a28ee5d75118c70edc6a6a5409d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vedran=20Mileti=C4=87?= Date: Wed, 20 May 2020 16:29:37 +0200 Subject: [PATCH] Fixes for FreeBSD (#440) * Use uuid(3) to generate UUIDs on FreeBSD FreeBSD is now handled like Windows so additional UUID libraries are not required. * Modify build.sh script to work on FreeBSD - /bin/bash -> /usr/bin/env bash - nproc -> sysctl -n hw.ncpu --- CMakeLists.txt | 4 ++-- build.sh | 16 +++++++++++----- cmake/templates/DrogonConfig.cmake.in | 4 ++-- lib/src/Utilities.cc | 13 +++++++++++++ trantor | 2 +- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 49bb9039..46748236 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,7 +92,7 @@ find_package(Jsoncpp REQUIRED) target_link_libraries(${PROJECT_NAME} PUBLIC Jsoncpp_lib) list(APPEND INCLUDE_DIRS_FOR_DYNAMIC_VIEW ${JSONCPP_INCLUDE_DIRS}) -if(NOT WIN32) +if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND NOT WIN32) find_package(UUID REQUIRED) target_link_libraries(${PROJECT_NAME} PRIVATE UUID_lib) @@ -109,7 +109,7 @@ if(NOT WIN32) else() message(FATAL_ERROR "uuid lib error") endif() -endif(NOT WIN32) +endif(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND NOT WIN32) find_package(Brotli) if(Brotli_FOUND) diff --git a/build.sh b/build.sh index 07803961..bebfeb5d 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash #build drogon function build_drogon() { @@ -58,16 +58,22 @@ make_flags='' cmake_gen='' parallel=1 +if [ $(uname) = 'FreeBSD' ]; then + nproc=$(sysctl -n hw.ncpu) +else + nproc=$(nproc) +fi + # simulate ninja's parallelism -case $(nproc) in +case nproc in 1) - parallel=$(( $(nproc) + 1 )) + parallel=$(( nproc + 1 )) ;; 2) - parallel=$(( $(nproc) + 1 )) + parallel=$(( nproc + 1 )) ;; *) - parallel=$(( $(nproc) + 2 )) + parallel=$(( nproc + 2 )) ;; esac diff --git a/cmake/templates/DrogonConfig.cmake.in b/cmake/templates/DrogonConfig.cmake.in index 4c6f721b..eb6ddf82 100644 --- a/cmake/templates/DrogonConfig.cmake.in +++ b/cmake/templates/DrogonConfig.cmake.in @@ -14,9 +14,9 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) find_dependency(Jsoncpp REQUIRED) find_dependency(Trantor REQUIRED) -if(NOT WIN32) +if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND NOT WIN32) find_dependency(UUID REQUIRED) -endif(NOT WIN32) +endif(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND NOT WIN32) find_dependency(ZLIB REQUIRED) if(@pg_FOUND@) find_dependency(pg) diff --git a/lib/src/Utilities.cc b/lib/src/Utilities.cc index c8e5f063..cee30590 100644 --- a/lib/src/Utilities.cc +++ b/lib/src/Utilities.cc @@ -335,6 +335,19 @@ std::string getUuid() std::string ret{binaryStringToHex((const unsigned char *)str, len)}; free(str); return ret; +#elif defined __FreeBSD__ + uuid_t *uuid = new uuid_t; + char* binstr = (char *) malloc(16); + uuidgen(uuid, 1); +#if _BYTE_ORDER == _LITTLE_ENDIAN + uuid_enc_le(binstr, uuid); +#else /* _BYTE_ORDER != _LITTLE_ENDIAN */ + uuid_enc_be(binstr, uuid); +#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */ + delete uuid; + std::string ret{binaryStringToHex((const unsigned char *)binstr, 16)}; + free(binstr); + return ret; #elif defined _WIN32 uuid_t uu; UuidCreate(&uu); diff --git a/trantor b/trantor index 5ab4a4c8..d74f4475 160000 --- a/trantor +++ b/trantor @@ -1 +1 @@ -Subproject commit 5ab4a4c85eb119fae96541d7f6723ba4ecef4791 +Subproject commit d74f4475ef317da8fc968f1fb6aa8dbcc076c933