generated from threeal/cpp-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
116 lines (93 loc) · 2.79 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
cmake_minimum_required(VERSION 3.23)
project(
Errors
VERSION 1.0.0
DESCRIPTION "A C++ package that provides utilities for error handling ."
HOMEPAGE_URL https://github.com/threeal/errors-cpp
LANGUAGES CXX
)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
option(ERRORS_ENABLE_TESTS "Enable test targets.")
if(PROJECT_IS_TOP_LEVEL)
option(BUILD_DOCS "Enable documentations build" OFF)
option(BUILD_EXAMPLES "Enable examples build" OFF)
if(ERRORS_ENABLE_TESTS)
enable_testing()
endif()
endif()
# Prefer system packages over the find modules provided by this project.
if(NOT DEFINED CMAKE_FIND_PACKAGE_PREFER_CONFIG)
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
endif()
if(PROJECT_IS_TOP_LEVEL)
# Statically analyze code by checking for warnings
find_package(CheckWarning 3.2.0 REQUIRED)
add_check_warning(TREAT_WARNINGS_AS_ERRORS)
endif()
# Build the main library
add_library(errors src/error.cpp)
target_sources(
errors PUBLIC
FILE_SET HEADERS
BASE_DIRS include
FILES include/errors/error.hpp
)
if(PROJECT_IS_TOP_LEVEL AND ERRORS_ENABLE_TESTS)
# Import Catch2 as the main testing framework
find_package(Catch2 3.7.1 REQUIRED)
include(Catch)
# Append the main library properties instead of linking the library.
get_target_property(errors_SOURCES errors SOURCES)
get_target_property(errors_HEADER_DIRS errors HEADER_DIRS)
# Build tests for the main library
add_executable(errors_test test/error_test.cpp ${errors_SOURCES})
target_include_directories(errors_test PRIVATE ${errors_HEADER_DIRS})
target_link_libraries(errors_test PRIVATE Catch2::Catch2WithMain)
# Enable support to check for test coverage
include(CheckCoverage)
target_check_coverage(errors_test)
catch_discover_tests(errors_test)
endif()
if(PROJECT_IS_TOP_LEVEL AND BUILD_DOCS)
include(GenerateDocs)
target_generate_xml_docs(errors)
endif()
add_subdirectory(components)
if(PROJECT_IS_TOP_LEVEL AND BUILD_DOCS)
add_subdirectory(docs)
endif()
if(PROJECT_IS_TOP_LEVEL AND BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(PROJECT_IS_TOP_LEVEL AND ERRORS_ENABLE_TESTS)
# Enable automatic target formatting.
find_package(FixFormat 1.1.1 REQUIRED)
include(FixFormat)
add_fix_format()
endif()
install(
TARGETS errors errors_format
EXPORT errors_targets
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
FILE_SET HEADERS
)
install(
EXPORT errors_targets
FILE ErrorsTargets.cmake
NAMESPACE errors::
DESTINATION lib/cmake/Errors
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
ErrorsConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)
install(
FILES
cmake/ErrorsConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/ErrorsConfigVersion.cmake
DESTINATION lib/cmake/Errors
)