forked from leeter/WinMTR-refresh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
176 lines (157 loc) · 4.89 KB
/
Copy pathCMakeLists.txt
File metadata and controls
176 lines (157 loc) · 4.89 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
cmake_minimum_required(VERSION 3.28)
project(
WinMTR
VERSION 1.0.0.0
DESCRIPTION "WinMTR v1.00 (Hyper Network Technology LTD)"
LANGUAGES CXX RC
)
option(WINMTR_ENABLE_ASAN "Enable AddressSanitizer for the pure core tests" OFF)
if(NOT WIN32 OR NOT MSVC)
message(FATAL_ERROR "WinMTR 只能使用 Microsoft C++ 工具鏈建置 Windows 版本。")
endif()
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
message(FATAL_ERROR "WinMTR v1.00 僅支援 x64;請使用 -A x64 重新設定。")
endif()
if(CMAKE_GENERATOR_PLATFORM AND NOT CMAKE_GENERATOR_PLATFORM STREQUAL "x64")
message(FATAL_ERROR "WinMTR v1.00 僅支援 x64;目前平台為 ${CMAKE_GENERATOR_PLATFORM}。")
endif()
# The source currently uses C++23 library facilities such as std::expected and
# std::out_ptr in addition to named C++ module interface units.
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
# 1 selects the static MFC library. Release builds also use the static CRT so
# end users do not need to install an additional redistributable package.
set(CMAKE_MFC_FLAG 1)
file(GLOB WINMTR_CPP_SOURCES CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
)
file(GLOB WINMTR_MODULE_INTERFACES CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/*.ixx"
)
file(GLOB WINMTR_HEADERS CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
)
file(GLOB WINMTR_RESOURCES CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/*.rc"
)
add_executable(WinMTR WIN32)
target_sources(WinMTR
PRIVATE
${WINMTR_CPP_SOURCES}
${WINMTR_HEADERS}
${WINMTR_RESOURCES}
"${CMAKE_CURRENT_SOURCE_DIR}/app.manifest"
PRIVATE
FILE_SET cxx_modules TYPE CXX_MODULES FILES
${WINMTR_MODULE_INTERFACES}
)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/WinMTRConfig.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/WinMTRConfig.h"
@ONLY
)
target_include_directories(WinMTR PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}"
)
target_compile_definitions(WinMTR PRIVATE
UNICODE
_UNICODE
WIN32_LEAN_AND_MEAN
WINVER=0x0601
_WIN32_WINNT=0x0601
)
target_compile_options(WinMTR PRIVATE
/utf-8
/W4
/WX
/sdl
/permissive-
/Zc:__cplusplus
/translateInclude
)
set_property(TARGET WinMTR PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)
set_property(TARGET WinMTR PROPERTY CXX_SCAN_FOR_MODULES ON)
target_link_options(WinMTR PRIVATE
"/MANIFEST:EMBED"
"/MANIFESTINPUT:${CMAKE_CURRENT_SOURCE_DIR}/app.manifest"
)
# Use the desktop libraries available on Windows 7. Do not replace this list
# with onecore.lib: doing so adds Windows Runtime API-set imports unavailable on
# Windows 7.
target_link_libraries(WinMTR PRIVATE
advapi32
comctl32
dnsapi
gdi32
gdiplus
iphlpapi
msimg32
normaliz
ole32
oleaut32
shell32
shlwapi
user32
version
winhttp
winmm
winspool
ws2_32
)
include(CTest)
if(BUILD_TESTING)
add_executable(WinMTRCoreTests
"${CMAKE_CURRENT_SOURCE_DIR}/tests/ProbeSchedulerTests.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/WinMTRProbeScheduler.h"
)
target_include_directories(WinMTRCoreTests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}"
)
target_compile_features(WinMTRCoreTests PRIVATE cxx_std_23)
target_compile_options(WinMTRCoreTests PRIVATE
/utf-8
/W4
/WX
/sdl
/permissive-
/Zc:__cplusplus
)
set_property(TARGET WinMTRCoreTests PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)
if(WINMTR_ENABLE_ASAN)
target_compile_options(WinMTRCoreTests PRIVATE /fsanitize=address)
target_link_options(WinMTRCoreTests PRIVATE /fsanitize=address)
endif()
add_test(NAME probe_scheduler COMMAND WinMTRCoreTests)
# The scheduled ASAN job intentionally builds only the pure core target.
# Normal Debug/Release CI also exercises the real unprivileged Windows
# ICMP API against loopback without depending on public network access.
if(NOT WINMTR_ENABLE_ASAN)
add_executable(WinMTRIcmpLoopbackTests
"${CMAKE_CURRENT_SOURCE_DIR}/tests/WindowsIcmpLoopbackTests.cpp"
)
target_include_directories(WinMTRIcmpLoopbackTests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}"
)
target_compile_features(WinMTRIcmpLoopbackTests PRIVATE cxx_std_23)
target_compile_options(WinMTRIcmpLoopbackTests PRIVATE
/utf-8
/W4
/WX
/sdl
/permissive-
/Zc:__cplusplus
)
set_property(TARGET WinMTRIcmpLoopbackTests PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)
target_link_libraries(WinMTRIcmpLoopbackTests PRIVATE iphlpapi ws2_32)
add_test(NAME icmp_loopback COMMAND WinMTRIcmpLoopbackTests)
endif()
endif()