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
This commit is contained in:
Vedran Miletić 2020-05-20 16:29:37 +02:00 committed by GitHub
parent c754d65cf0
commit 375498a5a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 10 deletions

View File

@ -92,7 +92,7 @@ find_package(Jsoncpp REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC Jsoncpp_lib) target_link_libraries(${PROJECT_NAME} PUBLIC Jsoncpp_lib)
list(APPEND INCLUDE_DIRS_FOR_DYNAMIC_VIEW ${JSONCPP_INCLUDE_DIRS}) 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) find_package(UUID REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE UUID_lib) target_link_libraries(${PROJECT_NAME} PRIVATE UUID_lib)
@ -109,7 +109,7 @@ if(NOT WIN32)
else() else()
message(FATAL_ERROR "uuid lib error") message(FATAL_ERROR "uuid lib error")
endif() endif()
endif(NOT WIN32) endif(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND NOT WIN32)
find_package(Brotli) find_package(Brotli)
if(Brotli_FOUND) if(Brotli_FOUND)

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
#build drogon #build drogon
function build_drogon() { function build_drogon() {
@ -58,16 +58,22 @@ make_flags=''
cmake_gen='' cmake_gen=''
parallel=1 parallel=1
if [ $(uname) = 'FreeBSD' ]; then
nproc=$(sysctl -n hw.ncpu)
else
nproc=$(nproc)
fi
# simulate ninja's parallelism # simulate ninja's parallelism
case $(nproc) in case nproc in
1) 1)
parallel=$(( $(nproc) + 1 )) parallel=$(( nproc + 1 ))
;; ;;
2) 2)
parallel=$(( $(nproc) + 1 )) parallel=$(( nproc + 1 ))
;; ;;
*) *)
parallel=$(( $(nproc) + 2 )) parallel=$(( nproc + 2 ))
;; ;;
esac esac

View File

@ -14,9 +14,9 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
find_dependency(Jsoncpp REQUIRED) find_dependency(Jsoncpp REQUIRED)
find_dependency(Trantor REQUIRED) find_dependency(Trantor REQUIRED)
if(NOT WIN32) if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND NOT WIN32)
find_dependency(UUID REQUIRED) find_dependency(UUID REQUIRED)
endif(NOT WIN32) endif(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND NOT WIN32)
find_dependency(ZLIB REQUIRED) find_dependency(ZLIB REQUIRED)
if(@pg_FOUND@) if(@pg_FOUND@)
find_dependency(pg) find_dependency(pg)

View File

@ -335,6 +335,19 @@ std::string getUuid()
std::string ret{binaryStringToHex((const unsigned char *)str, len)}; std::string ret{binaryStringToHex((const unsigned char *)str, len)};
free(str); free(str);
return ret; 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 #elif defined _WIN32
uuid_t uu; uuid_t uu;
UuidCreate(&uu); UuidCreate(&uu);

@ -1 +1 @@
Subproject commit 5ab4a4c85eb119fae96541d7f6723ba4ecef4791 Subproject commit d74f4475ef317da8fc968f1fb6aa8dbcc076c933