forked from franneck94/CProjectTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
94 lines (72 loc) · 2.03 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
cmake_minimum_required(VERSION 3.16)
project(
"CTemplate"
VERSION 1.0.0
LANGUAGES C)
# Global CMake variables are set here
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Options
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." ON)
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_COVERAGE)
include(CodeCoverage)
append_coverage_compiler_flags()
endif()
if(ENABLE_LTO)
find_lto(C)
endif()
# EXTERNAL LIBRARIES
add_git_submodule(external/log)
FetchContent_Declare(
unity
GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
GIT_TAG v2.5.2
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(unity)
FetchContent_Declare(
argparse
GIT_REPOSITORY https://github.com/cofyc/argparse.git
GIT_TAG v1.1.0
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(argparse)
# 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)