CORE: added uuid helper method

master
Martin Gerhardy 2018-11-03 17:07:58 +01:00
parent 4ce7fc79b4
commit 0c9c0637be
8 changed files with 71 additions and 2 deletions

View File

@ -179,6 +179,7 @@ find_host_program(GDB_EXECUTABLE NAMES ${GDB_BINARY} gdb)
find_host_program(LLDB_EXECUTABLE NAMES ${LLDB_BINARY} lldb)
find_host_program(GIT_EXECUTABLE NAMES ${GIT_BINARY} git)
find_host_program(HG_EXECUTABLE NAMES ${HG_BINARY} hg)
check_include_files("uuid/uuid.h" HAVE_UUID_H)
configure_file(src/engine-config.h.in engine-config.h @ONLY)
message(STATUS "Generate config.h in ${CMAKE_CURRENT_BINARY_DIR}")

View File

@ -22,12 +22,13 @@ Voxel MMO RPG engine.
* turbobadger
* gtest
* opencl
* libuuid
* qt (for the rcon tool)
Some of these dependencies might not be available as packages in your toolchain - most of them are also bundled with the application. But local installed headers always have the higher priority.
## Debian
apt-get install libglm-dev libassimp-dev lua5.3 liblua5.3-dev libsdl2-dev postgresql-server-dev-10 libpq-dev libenet-dev libgtk-3-dev qt5-default qttools5-dev qttools5-dev-tools opencl-c-headers wayland-protocols pkg-config
apt-get install libglm-dev libassimp-dev lua5.3 liblua5.3-dev libsdl2-dev postgresql-server-dev-10 libpq-dev libenet-dev libgtk-3-dev qt5-default qttools5-dev qttools5-dev-tools opencl-c-headers wayland-protocols pkg-config uuid-dev
If you want to run the database server locally, you have to install the postgres server package:

2
cmake/FindUUID.cmake Normal file
View File

@ -0,0 +1,2 @@
include("${PROJECT_SOURCE_DIR}/cmake/macros.cmake")
engine_find(uuid uuid/uuid.h "" "" "")

View File

@ -16,6 +16,7 @@
#cmakedefine HAVE_CLOCKGETTIME 1
#cmakedefine HAVE_SYS_RESOURCE_H 1
#cmakedefine HAVE_POSTGRES 1
#cmakedefine HAVE_UUID_H 1
#cmakedefine OPENCL_LIBRARY "@OPENCL_LIBRARY@"
#cmakedefine BASE_URL "@BASE_URL@"

View File

@ -35,6 +35,7 @@ set(SRCS
Tokenizer.h Tokenizer.cpp
Trace.cpp Trace.h
UTF8.cpp UTF8.h
UUID.cpp UUID.h
Var.cpp Var.h
Vector.h
Vertex.h
@ -44,7 +45,10 @@ set(LIB core)
set(FILES
shared/autoexec.cfg
)
engine_add_module(TARGET ${LIB} SRCS ${SRCS} FILES ${FILES} DEPENDENCIES collection io metric restclient-cpp zlib ${CMAKE_DL_LIBS})
find_package(UUID)
engine_add_module(TARGET ${LIB} SRCS ${SRCS} FILES ${FILES} DEPENDENCIES collection io metric restclient-cpp zlib ${CMAKE_DL_LIBS} ${UUID_LIBRARIES})
set(TEST_SRCS
tests/AbstractTest.cpp
@ -61,6 +65,7 @@ set(TEST_SRCS
tests/PoolAllocatorTest.cpp
tests/StringTest.cpp
tests/ReadWriteLockTest.cpp
tests/UUIDTest.cpp
tests/ZipTest.cpp
)

29
src/modules/core/UUID.cpp Normal file
View File

@ -0,0 +1,29 @@
/**
* @file
*/
#include "UUID.h"
#include "engine-config.h"
#ifdef HAVE_UUID_H
#include <uuid/uuid.h>
#else
#warning "No uuid implementation found"
#endif
namespace core {
std::string generateUUID() {
#ifdef HAVE_UUID_H
uuid_t uuid;
uuid_generate_random(uuid);
char buf[37];
uuid_unparse(uuid, buf);
return std::string(buf);
#else
return "";
#endif
}
}

13
src/modules/core/UUID.h Normal file
View File

@ -0,0 +1,13 @@
/**
* @file
*/
#pragma once
#include <string>
namespace core {
extern std::string generateUUID();
}

View File

@ -0,0 +1,17 @@
/**
* @file
*/
#include "core/tests/AbstractTest.h"
#include "core/UUID.h"
namespace core {
class UUIDTest: public AbstractTest {
};
TEST_F(UUIDTest, test) {
ASSERT_TRUE(core::generateUUID() != "") << "No uuid implementation was found";
}
}