modern cmake project struct
Added ability to add as a dependency to another cmake project via add_subdirectory
This commit is contained in:
parent
efc6744581
commit
6ac13af81a
@ -1,83 +1,32 @@
|
|||||||
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" ON)
|
||||||
|
|
||||||
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 ${CMAKE_SOURCE_DIR}/include)
|
||||||
if(BUILD_TESTS)
|
|
||||||
include(CTest)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
# Using system uuid generator
|
||||||
if (UUID_SYSTEM_GENERATOR)
|
if (UUID_SYSTEM_GENERATOR)
|
||||||
add_definitions(-DUUID_SYSTEM_GENERATOR)
|
target_compile_definitions(${PROJECT_NAME} INTERFACE UUID_SYSTEM_GENERATOR)
|
||||||
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()
|
|
||||||
|
|
||||||
add_executable(test_uuid ${SOURCES} ${headers})
|
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
elseif (APPLE)
|
elseif (APPLE)
|
||||||
find_library(CFLIB CoreFoundation)
|
find_library(CFLIB CoreFoundation REQUIRED)
|
||||||
target_link_libraries(test_uuid ${CFLIB})
|
target_link_libraries(${PROJECT_NAME} INTERFACE ${CFLIB})
|
||||||
else ()
|
else ()
|
||||||
FIND_PATH(LIBUUID_INCLUDE_DIRS uuid/uuid.h)
|
find_package(Libuuid REQUIRED)
|
||||||
FIND_LIBRARY(LIBUUID_LIBRARIES uuid)
|
if (Libuuid_FOUND)
|
||||||
|
target_include_directories(${PROJECT_NAME} INTERFACE ${Libuuid_INCLUDE_DIRS})
|
||||||
IF (LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
|
target_link_libraries(${PROJECT_NAME} INTERFACE ${Libuuid_LIBRARIES})
|
||||||
SET(LIBUUID_FOUND 1)
|
endif ()
|
||||||
IF (NOT LibUuid_FIND_QUIETLY)
|
endif ()
|
||||||
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 ()
|
endif ()
|
||||||
|
|
||||||
message(status "** CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
# Tests
|
||||||
|
if (UUID_BUILD_TESTS)
|
||||||
if(BUILD_TESTS)
|
add_subdirectory(test)
|
||||||
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 ()
|
endif ()
|
||||||
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 ()
|
||||||
29
test/CMakeLists.txt
Normal file
29
test/CMakeLists.txt
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
enable_testing()
|
||||||
|
|
||||||
|
# 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})
|
||||||
|
set_target_properties(test_${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
|
||||||
|
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