-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
127 lines (101 loc) · 2.52 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
cmake_minimum_required(VERSION 3.22)
set(CMAKE_MESSAGE_LOG_LEVEL STATUS)
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
)
include(vcpkg-init)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_COLOR_DIAGNOSTICS ON)
set(CMAKE_DIRECTORY_LABELS ON)
project(myprogram
LANGUAGES
C CXX
VERSION
0.0.1
)
option(
AUTOFORMAT_SRC_ON_CONFIGURE
"If enabled, clang-format will be used to format all sources in src/ during configuration"
OFF # ON
)
string(TOLOWER "${CMAKE_SYSTEM_NAME}" host_os)
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type)
string(TOLOWER "${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" architecture)
set(CMAKE_DEBUG_POSTFIX ".${build_type}.${architecture}")
set(compiler_is_msvc "$<CXX_COMPILER_ID:MSVC>")
set(compiler_is_gnu "$<CXX_COMPILER_ID:GNU>")
set(compiler_is_clang "$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:Clang>>")
find_package(fmt CONFIG REQUIRED)
find_package(OpenSSL REQUIRED)
file(GLOB_RECURSE
project_sources
CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.[hc]"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.[hc]pp"
)
add_executable(${PROJECT_NAME}
${project_sources}
)
include(compiler-warnings)
target_compile_features(${PROJECT_NAME} PRIVATE
PRIVATE
cxx_std_23
)
target_compile_definitions(${PROJECT_NAME} PRIVATE
NOMINMAX
$<${compiler_is_msvc}:
WIN32_LEAN_AND_MEAN
VC_EXTRALEAN
$<$<CONFIG:Debug>:
# debug only msvc defs
>
>
$<${compiler_is_gnu}:
# gcc defs here
>
$<${compiler_is_clang}:
# clang defs here
>
)
target_compile_options(${PROJECT_NAME} PRIVATE
$<${compiler_is_msvc}:
/std:c++latest
/Zc:preprocessor
/utf-8
/EHsc
/nologo
/UNICODE
>
$<$<CONFIG:Release>:
/Ox
/MD
>
$<$<CONFIG:Debug>:
/MDd
>
)
target_include_directories(${PROJECT_NAME}
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src"
)
target_link_libraries(${PROJECT_NAME}
PRIVATE fmt::fmt
PRIVATE OpenSSL::SSL
PRIVATE OpenSSL::Crypto
)
if (AUTOFORMAT_SRC_ON_CONFIGURE MATCHES ON)
# Formatting rules defined by .clangformat
# Scoped to src/*.[h]pp and src/*.[c]pp
include(clang-format)
endif()
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
PROPERTY VS_STARTUP_PROJECT
${PROJECT_NAME}
)
set_property(TARGET ${PROJECT_NAME}
PROPERTY VS_DEBUGGER_ENVIRONMENT
"PATH=${CMAKE_CURRENT_INSTALL_DIR}/${PROJECT_NAME}${CMAKE_EXECUTABLE_SUFFIX}"
)
include(cmake-utils)