-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathCMakeLists.txt
163 lines (137 loc) · 4.31 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
cmake_minimum_required(VERSION 3.22)
project(
"CppTemplate"
VERSION 1.0.0
LANGUAGES C CXX)
# Global CMake variables are set here
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Options
option(USE_CONAN "Whether to use Conan." OFF)
option(USE_VCPKG "Whether to use VCPKG." OFF)
option(USE_CPM "Whether to use CPM." ON)
option(ENABLE_WARNINGS "Enable to add warnings to a target." ON)
option(ENABLE_WARNINGS_AS_ERRORS "Enable to treat warnings as errors." OFF)
option(ENABLE_TESTING "Enable a Unit Testing build." ON)
option(ENABLE_COVERAGE "Enable a Code Coverage build." OFF)
option(ENABLE_CLANG_TIDY "Enable to add clang tidy." OFF)
option(ENABLE_SANITIZE_ADDR "Enable address sanitize." OFF)
option(ENABLE_SANITIZE_UNDEF "Enable undefined sanitize." OFF)
option(ENABLE_SANITIZE_LEAK "Enable leak sanitize (Gcc/Clang only)." OFF)
option(ENABLE_SANITIZE_THREAD "Enable thread sanitize (Gcc/Clang only)." OFF)
option(ENABLE_CLANG_FORMAT "Enable to add clang-format." OFF)
option(ENABLE_CMAKE_FORMAT "Enable to add cmake-format." OFF)
option(ENABLE_LTO "Enable to add Link Time Optimization." ON)
# Project/Library Names
set(EXECUTABLE_NAME "main")
# CMAKE MODULES
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
include(ConfigSafeGuards)
include(AddGitSubmodule)
include(Docs)
include(Tools)
if(ENABLE_WARNINGS)
include(Warnings)
endif()
add_cmake_format_target()
add_clang_format_target()
if(ENABLE_SANITIZE_ADDR
OR ENABLE_SANITIZE_UNDEF
OR ENABLE_SANITIZE_LEAK
OR ENABLE_SANITIZE_THREAD)
include(Sanitizer)
add_sanitizer_flags()
endif()
if(ENABLE_TESTING AND ENABLE_COVERAGE)
include(CodeCoverage)
append_coverage_compiler_flags()
endif()
if(ENABLE_LTO)
include(LTO)
endif()
# EXTERNAL LIBRARIES
if(USE_CPM)
message(STATUS "Using CPM")
include(CPM)
cpmaddpackage("gh:nlohmann/json#v3.11.3")
cpmaddpackage("gh:fmtlib/fmt#9.1.0")
cpmaddpackage("gh:gabime/spdlog#v1.13.0")
cpmaddpackage("gh:jarro2783/cxxopts#v3.1.1")
if(ENABLE_TESTING)
cpmaddpackage("gh:catchorg/Catch2#v3.5.3")
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)
endif()
elseif(USE_CONAN OR USE_VCPKG)
if(USE_CONAN)
message(STATUS "Using Conan")
include(${CMAKE_BINARY_DIR}/conan_toolchain.cmake)
elseif(USE_VCPKG)
message(STATUS "Using VCPKG")
include(
${CMAKE_SOURCE_DIR}/external/vcpkg/scripts/buildsystems/vcpkg.cmake)
endif()
find_package(nlohmann_json REQUIRED)
find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
find_package(cxxopts REQUIRED)
if(ENABLE_TESTING)
find_package(Catch2 REQUIRED)
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)
endif()
else()
message(STATUS "Using FetchContent")
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json
GIT_TAG v3.11.3
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(nlohmann_json)
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt
GIT_TAG 10.0.0
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(fmt)
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog
GIT_TAG v1.13.0
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(spdlog)
FetchContent_Declare(
cxxopts
GIT_REPOSITORY https://github.com/jarro2783/cxxopts
GIT_TAG v3.1.1
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(cxxopts)
if(ENABLE_TESTING)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG v3.5.3
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
endif()
endif()
add_subdirectory(configured)
add_subdirectory(external)
add_subdirectory(src)
add_subdirectory(app)
if(ENABLE_TESTING)
include(CTest)
enable_testing()
add_subdirectory(tests)
endif()
# INSTALL TARGETS
install(
TARGETS ${EXECUTABLE_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
install(
TARGETS "LibFoo" "LibBar"
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)