-
Notifications
You must be signed in to change notification settings - Fork 41
/
CMakeLists.txt
96 lines (78 loc) · 2.69 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
cmake_minimum_required(VERSION 3.18)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(BUILD_TESTS "Build tests" ON)
option(BUILD_DOCS "Build documentation" OFF)
option(BUILD_COVERAGE "Build code coverage" OFF)
set(
HUNTER_CACHE_SERVERS
"https://github.com/bmstu-iu8-cpp-sem-3/hunter-cache"
CACHE STRING "Default cache server"
)
include("cmake/HunterGate.cmake")
HunterGate(
URL "https://github.com/cpp-pm/hunter/archive/v0.23.314.tar.gz"
SHA1 "95c47c92f68edb091b5d6d18924baabe02a6962a"
)
# TODO: rename project and delete this comment
project(template VERSION 0.1.0)
string(APPEND CMAKE_CXX_FLAGS " -pedantic -Werror -Wall -Wextra")
string(APPEND CMAKE_CXX_FLAGS " -Wno-unused-command-line-argument")
string(APPEND CMAKE_CXX_FLAGS " -Wshadow -Wnon-virtual-dtor")
# new versions of cmake contain gtest search files
# commented out to increase the build speed.
# hunter_add_package(GTest)
find_package(GTest CONFIG REQUIRED)
add_library(${PROJECT_NAME} STATIC
# enum your files and delete this comment
${CMAKE_CURRENT_SOURCE_DIR}/sources/example.cpp
)
add_executable(demo
${CMAKE_CURRENT_SOURCE_DIR}/demo/main.cpp
)
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>"
)
target_link_libraries(demo ${PROJECT_NAME})
if(BUILD_TESTS)
add_executable(tests
# TODO: enum your files and delete this comment
${CMAKE_CURRENT_SOURCE_DIR}/tests/example.cpp
)
target_link_libraries(tests ${PROJECT_NAME} GTest::gtest_main)
enable_testing()
add_test(NAME unit_tests COMMAND tests)
endif()
if(BUILD_COVERAGE)
set(ENABLE_COVERAGE ON CACHE BOOL "Enable coverage build." FORCE)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/coverage/cmake")
find_package(codecov)
string(APPEND CMAKE_CXX_FLAGS " --coverage")
add_coverage(${PROJECT_NAME})
add_coverage(tests)
coverage_evaluate()
endif()
if(BUILD_DOCS)
set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/_docs)
set(DOXYGEN_EXAMPLE_PATH examples)
set(DOXYGEN_GENERATE_HTML NO)
set(DOXYGEN_GENERATE_MAN YES)
find_package(Doxygen)
doxygen_add_docs(docs include)
install(DIRECTORY ${DOXYGEN_OUTPUT_DIRECTORY}/man DESTINATION share)
# add_dependencies(install docs) need to call target docs before install or package
endif()
include(CPackConfig.cmake)
install(TARGETS ${PROJECT_NAME} demo
EXPORT "${PROJECT_NAME}-targets"
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
INCLUDES DESTINATION include
)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include)
install(EXPORT "${PROJECT_NAME}-targets"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "lib/cmake"
)