forked from franneck94/CppProjectTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
146 lines (118 loc) · 3.63 KB
/
Copy pathCMakeLists.txt
File metadata and controls
146 lines (118 loc) · 3.63 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
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
cmake_minimum_required(VERSION 3.16)
project(
"CppTemplate"
VERSION 1.0.0
LANGUAGES C CXX)
# Global CMake variables are set here
set(CMAKE_CXX_STANDARD 17)
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(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_INCLUDE_WHAT_YOU_USE "Enable to add iwyu." OFF)
option(ENABLE_CLANG_TIDY "Enable to add clang tidy." ON)
option(ENABLE_CPPCHECK "Enable to add cppcheck." OFF)
option(ENABLE_SANITIZE_ADDR "Enable to sanitize address (Unix only)." OFF)
option(ENABLE_SANITIZE_UNDEF "Enable to sanitize undefined (Unix only)." OFF)
option(ENABLE_CLANG_FORMAT "Enable to add clang-format." ON)
option(ENABLE_CMAKE_FORMAT "Enable to add cmake-format." ON)
option(ENABLE_LTO "Enable to add Link Time Optimization." ON)
# Project/Library Names
set(LIBRARY_NAME "lib")
set(UNIT_TEST_NAME "unit_tests")
set(EXECUTABLE_NAME "main")
# CMAKE MODULES
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/)
include(FetchContent)
include(AddGitSubmodule)
include(Docs)
include(Warnings)
include(Tools)
include(LTO)
include(ConfigSafeGuards)
add_cmake_format_target()
add_clang_format_target()
if(ENABLE_SANITIZE_ADDR OR ENABLE_SANITIZE_UNDEF)
include(Sanitizer)
add_sanitizer_flags()
endif()
if(ENABLE_COVERAGE)
include(CodeCoverage)
append_coverage_compiler_flags()
endif()
if(ENABLE_LTO)
find_lto(CXX)
endif()
# EXTERNAL LIBRARIES
if(USE_CONAN)
message("==> Using Conan")
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
find_package(nlohmann_json)
find_package(fmt)
find_package(spdlog)
find_package(Catch2)
find_package(cxxopts)
elseif(USE_VCPKG)
message("==> Using VCPKG")
include(${CMAKE_SOURCE_DIR}/external/vcpkg/scripts/buildsystems/vcpkg.cmake)
find_package(nlohmann_json)
find_package(fmt)
find_package(spdlog)
find_package(Catch2)
find_package(cxxopts)
else() # Use FetchContent
message("==> Using FetchContent")
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.2
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(nlohmann_json)
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 9.1.0
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(fmt)
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.11.0
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(spdlog)
FetchContent_Declare(
cxxopts
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
GIT_TAG v3.0.0
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(cxxopts)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.9
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(Catch2)
endif()
# SUB DIRECTORIES
add_subdirectory(configured)
add_subdirectory(external)
add_subdirectory(src)
add_subdirectory(app)
add_subdirectory(tests)
# INSTALL TARGETS
install(
TARGETS ${EXECUTABLE_NAME}
EXPORT ${LIBRARY_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
install(
TARGETS ${LIBRARY_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)