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)
|
||||
project(test_uuid CXX)
|
||||
project(stduuid CXX)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/catch)
|
||||
option(UUID_BUILD_TESTS "Build the unit tests" ON)
|
||||
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)
|
||||
file(GLOB SOURCES "test/*.cpp" "include/*.cpp")
|
||||
# Library target
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
target_include_directories(${PROJECT_NAME} INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>)
|
||||
|
||||
if(BUILD_TESTS)
|
||||
include(CTest)
|
||||
endif()
|
||||
# Using system uuid generator
|
||||
if (UUID_SYSTEM_GENERATOR)
|
||||
target_compile_definitions(${PROJECT_NAME} INTERFACE UUID_SYSTEM_GENERATOR)
|
||||
|
||||
if(UUID_SYSTEM_GENERATOR)
|
||||
add_definitions(-DUUID_SYSTEM_GENERATOR)
|
||||
endif()
|
||||
if (WIN32)
|
||||
elseif (APPLE)
|
||||
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)
|
||||
message(status "Setting MSVC flags")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHc /std:c++17")
|
||||
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
|
||||
elseif(APPLE)
|
||||
message(status "Setting Clang flags")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fexceptions -g -Wall")
|
||||
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()
|
||||
# Using span from std
|
||||
if (NOT UUID_USING_CXX20_SPAN)
|
||||
target_include_directories(${PROJECT_NAME} INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/gsl>
|
||||
$<INSTALL_INTERFACE:include/gsl>)
|
||||
install(DIRECTORY gsl TYPE INCLUDE)
|
||||
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)
|
||||
elseif(APPLE)
|
||||
find_library(CFLIB CoreFoundation)
|
||||
target_link_libraries(test_uuid ${CFLIB})
|
||||
else()
|
||||
FIND_PATH(LIBUUID_INCLUDE_DIRS uuid/uuid.h)
|
||||
FIND_LIBRARY(LIBUUID_LIBRARIES uuid)
|
||||
# Config files for find_package()
|
||||
include(CMakePackageConfigHelpers)
|
||||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
|
||||
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME})
|
||||
write_basic_package_version_file(
|
||||
"${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)
|
||||
SET(LIBUUID_FOUND 1)
|
||||
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)
|
||||
# Tests
|
||||
if (UUID_BUILD_TESTS)
|
||||
enable_testing()
|
||||
|
||||
add_test(NAME "test_uuid" COMMAND "test_uuid" "-r compact")
|
||||
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()
|
||||
add_subdirectory(test)
|
||||
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
|
||||
#define GSL_GSL_H
|
||||
|
||||
#include <gsl/gsl_algorithm> // copy
|
||||
#include <gsl/gsl_assert> // Ensures/Expects
|
||||
#include <gsl/gsl_byte> // byte
|
||||
#include <gsl/gsl_util> // finally()/narrow()/narrow_cast()...
|
||||
#include <gsl/multi_span> // multi_span, strided_span...
|
||||
#include <gsl/pointers> // owner, not_null
|
||||
#include <gsl/span> // span
|
||||
#include <gsl/string_span> // zstring, string_span, zstring_builder...
|
||||
#include "gsl_algorithm" // copy
|
||||
#include "gsl_assert" // Ensures/Expects
|
||||
#include "gsl_byte" // byte
|
||||
#include "gsl_util" // finally()/narrow()/narrow_cast()...
|
||||
#include "multi_span" // multi_span, strided_span...
|
||||
#include "pointers" // owner, not_null
|
||||
#include "span" // span
|
||||
#include "string_span" // zstring, string_span, zstring_builder...
|
||||
|
||||
#endif // GSL_GSL_H
|
||||
@ -17,8 +17,8 @@
|
||||
#ifndef GSL_ALGORITHM_H
|
||||
#define GSL_ALGORITHM_H
|
||||
|
||||
#include <gsl/gsl_assert> // for Expects
|
||||
#include <gsl/span> // for dynamic_extent, span
|
||||
#include "gsl_assert" // for Expects
|
||||
#include "span" // for dynamic_extent, span
|
||||
|
||||
#include <algorithm> // for copy_n
|
||||
#include <cstddef> // for ptrdiff_t
|
||||
@ -17,7 +17,7 @@
|
||||
#ifndef GSL_UTIL_H
|
||||
#define GSL_UTIL_H
|
||||
|
||||
#include <gsl/gsl_assert> // for Expects
|
||||
#include "gsl_assert" // for Expects
|
||||
|
||||
#include <array>
|
||||
#include <cstddef> // for ptrdiff_t, size_t
|
||||
@ -17,9 +17,9 @@
|
||||
#ifndef GSL_MULTI_SPAN_H
|
||||
#define GSL_MULTI_SPAN_H
|
||||
|
||||
#include <gsl/gsl_assert> // for Expects
|
||||
#include <gsl/gsl_byte> // for byte
|
||||
#include <gsl/gsl_util> // for narrow_cast
|
||||
#include "gsl_assert" // for Expects
|
||||
#include "gsl_byte" // for byte
|
||||
#include "gsl_util" // for narrow_cast
|
||||
|
||||
#include <algorithm> // for transform, lexicographical_compare
|
||||
#include <array> // for array
|
||||
@ -17,7 +17,7 @@
|
||||
#ifndef 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 <iosfwd> // for ptrdiff_t, nullptr_t, ostream, size_t
|
||||
@ -17,9 +17,9 @@
|
||||
#ifndef GSL_SPAN_H
|
||||
#define GSL_SPAN_H
|
||||
|
||||
#include <gsl/gsl_assert> // for Expects
|
||||
#include <gsl/gsl_byte> // for byte
|
||||
#include <gsl/gsl_util> // for narrow_cast, narrow
|
||||
#include "gsl_assert" // for Expects
|
||||
#include "gsl_byte" // for byte
|
||||
#include "gsl_util" // for narrow_cast, narrow
|
||||
|
||||
#include <algorithm> // for lexicographical_compare
|
||||
#include <array> // for array
|
||||
@ -17,9 +17,9 @@
|
||||
#ifndef GSL_STRING_SPAN_H
|
||||
#define GSL_STRING_SPAN_H
|
||||
|
||||
#include <gsl/gsl_assert> // for Ensures, Expects
|
||||
#include <gsl/gsl_util> // for narrow_cast
|
||||
#include <gsl/span> // for operator!=, operator==, dynamic_extent
|
||||
#include "gsl_assert" // for Ensures, Expects
|
||||
#include "gsl_util" // for narrow_cast
|
||||
#include "span" // for operator!=, operator==, dynamic_extent
|
||||
|
||||
#include <algorithm> // for equal, lexicographical_compare
|
||||
#include <array> // for array
|
||||
@ -15,7 +15,7 @@
|
||||
#include <chrono>
|
||||
#include <numeric>
|
||||
#include <atomic>
|
||||
#include <gsl/span>
|
||||
#include <span>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
@ -50,6 +50,14 @@
|
||||
|
||||
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
|
||||
{
|
||||
template <typename TChar>
|
||||
@ -352,7 +360,7 @@ namespace uuids
|
||||
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));
|
||||
}
|
||||
@ -403,9 +411,9 @@ namespace uuids
|
||||
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>
|
||||
|
||||
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