Merge pull request #28 from egor-spk/refactor-cmake-project
Refactor cmake project
This commit is contained in:
commit
1b74bbc183
130
CMakeLists.txt
130
CMakeLists.txt
@ -1,83 +1,67 @@
|
|||||||
cmake_minimum_required(VERSION 3.7.0)
|
cmake_minimum_required(VERSION 3.7.0)
|
||||||
project(test_uuid CXX)
|
project(stduuid CXX)
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
option(UUID_BUILD_TESTS "Build the unit tests" ON)
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/catch)
|
option(UUID_SYSTEM_GENERATOR "Enable operating system uuid generator" OFF)
|
||||||
|
option(UUID_USING_CXX20_SPAN "Using span from std instead of gsl" OFF)
|
||||||
|
|
||||||
file(GLOB headers ${CMAKE_SOURCE_DIR}/include/*.h)
|
# Library target
|
||||||
file(GLOB SOURCES "test/*.cpp" "include/*.cpp")
|
add_library(${PROJECT_NAME} INTERFACE)
|
||||||
|
target_include_directories(${PROJECT_NAME} INTERFACE
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:include>)
|
||||||
|
|
||||||
if(BUILD_TESTS)
|
# Using system uuid generator
|
||||||
include(CTest)
|
if (UUID_SYSTEM_GENERATOR)
|
||||||
endif()
|
target_compile_definitions(${PROJECT_NAME} INTERFACE UUID_SYSTEM_GENERATOR)
|
||||||
|
|
||||||
if(UUID_SYSTEM_GENERATOR)
|
if (WIN32)
|
||||||
add_definitions(-DUUID_SYSTEM_GENERATOR)
|
elseif (APPLE)
|
||||||
endif()
|
find_library(CFLIB CoreFoundation REQUIRED)
|
||||||
|
target_link_libraries(${PROJECT_NAME} INTERFACE ${CFLIB})
|
||||||
|
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 ()
|
||||||
|
|
||||||
if(WIN32)
|
# Using span from std
|
||||||
message(status "Setting MSVC flags")
|
if (NOT UUID_USING_CXX20_SPAN)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHc /std:c++17")
|
target_include_directories(${PROJECT_NAME} INTERFACE
|
||||||
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/gsl>
|
||||||
elseif(APPLE)
|
$<INSTALL_INTERFACE:include/gsl>)
|
||||||
message(status "Setting Clang flags")
|
install(DIRECTORY gsl TYPE INCLUDE)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fexceptions -g -Wall")
|
endif ()
|
||||||
else()
|
|
||||||
#include_directories(${LIBUUID_INCLUDE_DIR})
|
|
||||||
message(status "Setting GCC flags")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fexceptions -g -Wall")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_executable(test_uuid ${SOURCES} ${headers})
|
# Install step and imported target
|
||||||
|
install(FILES include/uuid.h TYPE INCLUDE)
|
||||||
|
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets)
|
||||||
|
install(EXPORT ${PROJECT_NAME}-targets
|
||||||
|
DESTINATION lib/cmake/${PROJECT_NAME})
|
||||||
|
|
||||||
if(WIN32)
|
# Config files for find_package()
|
||||||
elseif(APPLE)
|
include(CMakePackageConfigHelpers)
|
||||||
find_library(CFLIB CoreFoundation)
|
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
|
||||||
target_link_libraries(test_uuid ${CFLIB})
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
|
||||||
else()
|
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME})
|
||||||
FIND_PATH(LIBUUID_INCLUDE_DIRS uuid/uuid.h)
|
write_basic_package_version_file(
|
||||||
FIND_LIBRARY(LIBUUID_LIBRARIES uuid)
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-version.cmake"
|
||||||
|
VERSION "1.0"
|
||||||
|
COMPATIBILITY AnyNewerVersion)
|
||||||
|
install(FILES
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-version.cmake"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindLibuuid.cmake"
|
||||||
|
DESTINATION lib/cmake/${PROJECT_NAME})
|
||||||
|
export(EXPORT ${PROJECT_NAME}-targets
|
||||||
|
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}-targets.cmake")
|
||||||
|
|
||||||
IF (LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
|
# Tests
|
||||||
SET(LIBUUID_FOUND 1)
|
if (UUID_BUILD_TESTS)
|
||||||
IF (NOT LibUuid_FIND_QUIETLY)
|
|
||||||
MESSAGE(STATUS "Found libuuid: ${LIBUUID_LIBRARIES}")
|
|
||||||
ENDIF ( NOT LibUuid_FIND_QUIETLY )
|
|
||||||
ELSE (LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
|
|
||||||
IF (LibUuid_FIND_REQUIRED)
|
|
||||||
MESSAGE(SEND_ERROR "Could NOT find libuuid")
|
|
||||||
ELSE (LibUuid_FIND_REQUIRED)
|
|
||||||
IF (NOT LIBUUID_FIND_QUIETLY)
|
|
||||||
MESSAGE(STATUS "Could NOT find libuuid")
|
|
||||||
ENDIF (NOT LIBUUID_FIND_QUIETLY)
|
|
||||||
ENDIF (LibUuid_FIND_REQUIRED)
|
|
||||||
ENDIF (LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
|
|
||||||
|
|
||||||
MARK_AS_ADVANCED(LIBUUID_LIBRARIES LIBUUID_INCLUDE_DIRS)
|
|
||||||
|
|
||||||
include_directories(${LIBUUID_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
#find_package(Libuuid REQUIRED NO_MODULE)
|
|
||||||
#if (NOT LIBUUID_FOUND)
|
|
||||||
# message(FATAL_ERROR
|
|
||||||
# "You might need to run 'sudo apt-get install uuid-dev' or similar")
|
|
||||||
#endif()
|
|
||||||
target_link_libraries(test_uuid ${LIBUUID_LIBRARY})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
message(status "** CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
|
||||||
|
|
||||||
if(BUILD_TESTS)
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
add_subdirectory(test)
|
||||||
add_test(NAME "test_uuid" COMMAND "test_uuid" "-r compact")
|
endif ()
|
||||||
set_tests_properties("test_uuid"
|
|
||||||
PROPERTIES
|
|
||||||
PASS_REGULAR_EXPRESSION "Passed all.*")
|
|
||||||
set_tests_properties("test_uuid"
|
|
||||||
PROPERTIES
|
|
||||||
FAIL_REGULAR_EXPRESSION "Failed \\d+ test cases")
|
|
||||||
set_tests_properties("test_uuid"
|
|
||||||
PROPERTIES
|
|
||||||
TIMEOUT 120)
|
|
||||||
endif()
|
|
||||||
8601
catch/catch.hpp
8601
catch/catch.hpp
File diff suppressed because it is too large
Load Diff
14
cmake/Config.cmake.in
Normal file
14
cmake/Config.cmake.in
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
include(CMakeFindDependencyMacro)
|
||||||
|
if (@UUID_SYSTEM_GENERATOR@)
|
||||||
|
if (WIN32 OR APPLE)
|
||||||
|
else ()
|
||||||
|
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
|
||||||
|
find_dependency(Libuuid REQUIRED)
|
||||||
|
endif ()
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")
|
||||||
|
|
||||||
|
check_required_components(@PROJECT_NAME@)
|
||||||
17
cmake/FindLibuuid.cmake
Normal file
17
cmake/FindLibuuid.cmake
Normal file
@ -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 ()
|
||||||
@ -17,13 +17,13 @@
|
|||||||
#ifndef GSL_GSL_H
|
#ifndef GSL_GSL_H
|
||||||
#define GSL_GSL_H
|
#define GSL_GSL_H
|
||||||
|
|
||||||
#include <gsl/gsl_algorithm> // copy
|
#include "gsl_algorithm" // copy
|
||||||
#include <gsl/gsl_assert> // Ensures/Expects
|
#include "gsl_assert" // Ensures/Expects
|
||||||
#include <gsl/gsl_byte> // byte
|
#include "gsl_byte" // byte
|
||||||
#include <gsl/gsl_util> // finally()/narrow()/narrow_cast()...
|
#include "gsl_util" // finally()/narrow()/narrow_cast()...
|
||||||
#include <gsl/multi_span> // multi_span, strided_span...
|
#include "multi_span" // multi_span, strided_span...
|
||||||
#include <gsl/pointers> // owner, not_null
|
#include "pointers" // owner, not_null
|
||||||
#include <gsl/span> // span
|
#include "span" // span
|
||||||
#include <gsl/string_span> // zstring, string_span, zstring_builder...
|
#include "string_span" // zstring, string_span, zstring_builder...
|
||||||
|
|
||||||
#endif // GSL_GSL_H
|
#endif // GSL_GSL_H
|
||||||
@ -17,8 +17,8 @@
|
|||||||
#ifndef GSL_ALGORITHM_H
|
#ifndef GSL_ALGORITHM_H
|
||||||
#define GSL_ALGORITHM_H
|
#define GSL_ALGORITHM_H
|
||||||
|
|
||||||
#include <gsl/gsl_assert> // for Expects
|
#include "gsl_assert" // for Expects
|
||||||
#include <gsl/span> // for dynamic_extent, span
|
#include "span" // for dynamic_extent, span
|
||||||
|
|
||||||
#include <algorithm> // for copy_n
|
#include <algorithm> // for copy_n
|
||||||
#include <cstddef> // for ptrdiff_t
|
#include <cstddef> // for ptrdiff_t
|
||||||
@ -17,7 +17,7 @@
|
|||||||
#ifndef GSL_UTIL_H
|
#ifndef GSL_UTIL_H
|
||||||
#define GSL_UTIL_H
|
#define GSL_UTIL_H
|
||||||
|
|
||||||
#include <gsl/gsl_assert> // for Expects
|
#include "gsl_assert" // for Expects
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstddef> // for ptrdiff_t, size_t
|
#include <cstddef> // for ptrdiff_t, size_t
|
||||||
@ -17,9 +17,9 @@
|
|||||||
#ifndef GSL_MULTI_SPAN_H
|
#ifndef GSL_MULTI_SPAN_H
|
||||||
#define GSL_MULTI_SPAN_H
|
#define GSL_MULTI_SPAN_H
|
||||||
|
|
||||||
#include <gsl/gsl_assert> // for Expects
|
#include "gsl_assert" // for Expects
|
||||||
#include <gsl/gsl_byte> // for byte
|
#include "gsl_byte" // for byte
|
||||||
#include <gsl/gsl_util> // for narrow_cast
|
#include "gsl_util" // for narrow_cast
|
||||||
|
|
||||||
#include <algorithm> // for transform, lexicographical_compare
|
#include <algorithm> // for transform, lexicographical_compare
|
||||||
#include <array> // for array
|
#include <array> // for array
|
||||||
@ -17,7 +17,7 @@
|
|||||||
#ifndef GSL_POINTERS_H
|
#ifndef GSL_POINTERS_H
|
||||||
#define GSL_POINTERS_H
|
#define GSL_POINTERS_H
|
||||||
|
|
||||||
#include <gsl/gsl_assert> // for Ensures, Expects
|
#include "gsl_assert" // for Ensures, Expects
|
||||||
|
|
||||||
#include <algorithm> // for forward
|
#include <algorithm> // for forward
|
||||||
#include <iosfwd> // for ptrdiff_t, nullptr_t, ostream, size_t
|
#include <iosfwd> // for ptrdiff_t, nullptr_t, ostream, size_t
|
||||||
@ -17,9 +17,9 @@
|
|||||||
#ifndef GSL_SPAN_H
|
#ifndef GSL_SPAN_H
|
||||||
#define GSL_SPAN_H
|
#define GSL_SPAN_H
|
||||||
|
|
||||||
#include <gsl/gsl_assert> // for Expects
|
#include "gsl_assert" // for Expects
|
||||||
#include <gsl/gsl_byte> // for byte
|
#include "gsl_byte" // for byte
|
||||||
#include <gsl/gsl_util> // for narrow_cast, narrow
|
#include "gsl_util" // for narrow_cast, narrow
|
||||||
|
|
||||||
#include <algorithm> // for lexicographical_compare
|
#include <algorithm> // for lexicographical_compare
|
||||||
#include <array> // for array
|
#include <array> // for array
|
||||||
@ -17,9 +17,9 @@
|
|||||||
#ifndef GSL_STRING_SPAN_H
|
#ifndef GSL_STRING_SPAN_H
|
||||||
#define GSL_STRING_SPAN_H
|
#define GSL_STRING_SPAN_H
|
||||||
|
|
||||||
#include <gsl/gsl_assert> // for Ensures, Expects
|
#include "gsl_assert" // for Ensures, Expects
|
||||||
#include <gsl/gsl_util> // for narrow_cast
|
#include "gsl_util" // for narrow_cast
|
||||||
#include <gsl/span> // for operator!=, operator==, dynamic_extent
|
#include "span" // for operator!=, operator==, dynamic_extent
|
||||||
|
|
||||||
#include <algorithm> // for equal, lexicographical_compare
|
#include <algorithm> // for equal, lexicographical_compare
|
||||||
#include <array> // for array
|
#include <array> // for array
|
||||||
@ -15,7 +15,7 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <gsl/span>
|
#include <span>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#ifndef WIN32_LEAN_AND_MEAN
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
@ -50,6 +50,14 @@
|
|||||||
|
|
||||||
namespace uuids
|
namespace uuids
|
||||||
{
|
{
|
||||||
|
#ifdef __cpp_lib_span
|
||||||
|
template <class ElementType, std::size_t Extent>
|
||||||
|
using span = std::span<ElementType, Extent>;
|
||||||
|
#else
|
||||||
|
template <class ElementType, std::ptrdiff_t Extent>
|
||||||
|
using span = gsl::span<ElementType, Extent>;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
@ -352,7 +360,7 @@ namespace uuids
|
|||||||
std::copy(std::cbegin(arr), std::cend(arr), std::begin(data));
|
std::copy(std::cbegin(arr), std::cend(arr), std::begin(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit uuid(gsl::span<value_type, 16> bytes)
|
explicit uuid(span<value_type, 16> bytes)
|
||||||
{
|
{
|
||||||
std::copy(std::cbegin(bytes), std::cend(bytes), std::begin(data));
|
std::copy(std::cbegin(bytes), std::cend(bytes), std::begin(data));
|
||||||
}
|
}
|
||||||
@ -403,9 +411,9 @@ namespace uuids
|
|||||||
data.swap(other.data);
|
data.swap(other.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline gsl::span<std::byte const, 16> as_bytes() const
|
inline span<std::byte const, 16> as_bytes() const
|
||||||
{
|
{
|
||||||
return gsl::span<std::byte const, 16>(reinterpret_cast<std::byte const*>(data.data()), 16);
|
return span<std::byte const, 16>(reinterpret_cast<std::byte const*>(data.data()), 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class CharT = char>
|
template<class CharT = char>
|
||||||
|
|||||||
31
test/CMakeLists.txt
Normal file
31
test/CMakeLists.txt
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Test target
|
||||||
|
add_executable(test_${PROJECT_NAME} main.cpp test_generators.cpp test_uuid.cpp)
|
||||||
|
target_include_directories(test_${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/catch)
|
||||||
|
target_link_libraries(test_${PROJECT_NAME} PRIVATE ${PROJECT_NAME})
|
||||||
|
if (UUID_USING_CXX20_SPAN)
|
||||||
|
set_target_properties(test_${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)
|
||||||
|
else ()
|
||||||
|
set_target_properties(test_${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
|
||||||
|
endif ()
|
||||||
|
if (WIN32)
|
||||||
|
target_compile_options(test_${PROJECT_NAME} PRIVATE /EHc)
|
||||||
|
target_compile_definitions(test_${PROJECT_NAME} PRIVATE _SCL_SECURE_NO_WARNINGS)
|
||||||
|
elseif (APPLE)
|
||||||
|
target_compile_options(test_${PROJECT_NAME} PRIVATE -fexceptions -g -Wall)
|
||||||
|
else ()
|
||||||
|
target_compile_options(test_${PROJECT_NAME} PRIVATE -fexceptions -g -Wall)
|
||||||
|
endif ()
|
||||||
|
get_target_property(CURRENT_COMPILE_OPTIONS test_${PROJECT_NAME} COMPILE_OPTIONS)
|
||||||
|
message(STATUS "** ${CMAKE_CXX_COMPILER_ID} flags: ${CURRENT_COMPILE_OPTIONS}")
|
||||||
|
|
||||||
|
# Tests
|
||||||
|
add_test(NAME "test_${PROJECT_NAME}" COMMAND "test_${PROJECT_NAME}" "-r compact")
|
||||||
|
set_tests_properties("test_${PROJECT_NAME}"
|
||||||
|
PROPERTIES
|
||||||
|
PASS_REGULAR_EXPRESSION "Passed all.*")
|
||||||
|
set_tests_properties("test_${PROJECT_NAME}"
|
||||||
|
PROPERTIES
|
||||||
|
FAIL_REGULAR_EXPRESSION "Failed \\d+ test cases")
|
||||||
|
set_tests_properties("test_${PROJECT_NAME}"
|
||||||
|
PROPERTIES
|
||||||
|
TIMEOUT 120)
|
||||||
Loading…
Reference in New Issue
Block a user