-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
66 lines (54 loc) · 2.11 KB
/
Copy pathCMakeLists.txt
File metadata and controls
66 lines (54 loc) · 2.11 KB
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
cmake_minimum_required(VERSION 3.0)
project(error)
# Import dependencies
include(cmake/CPM.cmake)
cpmaddpackage("gh:fmtlib/fmt#10.0.0")
# Build the main library
add_library(error src/error.cpp)
target_include_directories(error PUBLIC include)
target_link_libraries(error PUBLIC fmt)
target_compile_features(error PRIVATE cxx_std_20)
# Check if this project is the main project
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
option(CHECK_FORMAT "Enable source code formatting check" OFF)
option(CHECK_WARNING "Enable static analysis warning check" OFF)
option(CHECK_COVERAGE "Enable test coverage check" OFF)
option(BUILD_DOCS "Enable documentations build" OFF)
# Import Format.cmake to format source code
if(CHECK_FORMAT)
cpmaddpackage("gh:threeal/Format.cmake#auto-install-cmake-format")
add_dependencies(error fix-format)
endif()
if(BUILD_TESTING)
enable_testing()
# Import Catch2 as the main testing framework
cpmaddpackage("gh:catchorg/Catch2@3.3.2")
include("${Catch2_SOURCE_DIR}/extras/Catch.cmake")
# Build tests for the main library
add_executable(error_test test/error_test.cpp)
target_link_libraries(error_test PRIVATE error Catch2::Catch2WithMain)
catch_discover_tests(error_test)
endif()
# Get all targets in this directory
get_property(TARGETS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS)
foreach(TARGET IN LISTS TARGETS)
# Statically analyze code by checking for warnings
if(CHECK_WARNING)
if(MSVC)
target_compile_options(${TARGET} PRIVATE /WX /permissive- /W4 /w14640 /EHsc)
else()
target_compile_options(${TARGET} PRIVATE -Werror -Wall -Wextra -Wnon-virtual-dtor -Wpedantic)
endif()
endif()
# Enable support to check for test coverage
if(BUILD_TESTING AND CHECK_COVERAGE AND NOT MSVC)
target_compile_options(${TARGET} PRIVATE --coverage -O0)
target_link_options(${TARGET} PRIVATE --coverage)
endif()
endforeach()
# Build XML documentation
if(BUILD_DOCS)
include(cmake/add_xml_docs.cmake)
add_xml_docs(docs include/error/error.hpp)
endif()
endif()