A modern C++ implementation of Universally Unique Identifiers (UUID) variant as defined in RFC-4122.
This library intends to support the following UUID versions, all are RFC-4122 compliant:
- Version 1, based on timestamp and MAC address as node id
- Version 2, based on DCE security version [1]
- Version 3, based on MD5 hashing of a named value
- Version 4, based on random numbers
- Version 5, based on SHA-1 hashing of a named value
- The provided v2 implementation is included only for completeness, it may not be fully compliant to DCE's security requirements. See comments in the source file. DO NOT use it in production.
#include <iostream>
#include "uuidxx/uuidxx.h"
int main()
{
auto u = uuidxx::make_v4();
std::cout << "Generated v4 UUID " << u.to_string();
return 0;
}
uuidxx is sub-project aware, therefore you can
- Download the uuidxx and copy it into a subdirectory in your CMake project or add uuidxx as a git submodule
- Then use
add_subdirectory()
to include uuidxx direclty in your CMake project - Use
target_link_libraries()
declare dependency of uuidxx.
cmake_minimum_required(VERSION 3.16)
project(my_project)
set(CMAKE_CXX_STANDARD 17)
add_subdirectory(uuidxx)
add_executable(my_exe source.cpp)
target_link_libraries(my_exe uuidxx)
CPM.cmake is a setup-free CMake dependency management.
Simply download the cmake file and add to your CMake project, then
cmake_minimum_required(VERSION 3.16)
project(my_project)
set(CMAKE_CXX_STANDARD 17)
include(cmake/CPM.cmake)
CPMAddPackage("gh:kingsamchen/uuidxx#tag")
add_executable(my_exe source.cpp)
target_link_libraries(my_exe uuidxx)
Building uuidxx requires:
- C++ 17 compatible compiler [1]
- CMake 3.16 or higher
- Python 3.5 or higher
- Ninja build (optional) [2]
- It is possible to back port to C++ 11 & 14
- Ninja build is used only on *nix platforms, and Makefile would be used if ninja was not found.
build.py
wraps a few CMake commands for easy use:
$ cd uuidxx
$ python(3) ./build.py # Run a release build
$ cd path-to-build && ctest --output-on-failure # Run tests
Run python(3) ./build.py --help
for details.
If you want fine control over the configuration and building, feel free to use CMake commands directly:
$ cd uuidxx
$ cmake -DCPM_SOURCE_CACHE=path/to/cache/deps -DCMAKE_BUILD_TYPE=Release -B path/to/out -S .
$ cmake --build path/to/out -- -j 8
uuidxx is licensed under the terms of the MIT license. see LICENSE