-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
217 lines (193 loc) · 7.71 KB
/
Copy pathCMakeLists.txt
File metadata and controls
217 lines (193 loc) · 7.71 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
cmake_minimum_required(VERSION 3.20)
project(Clew VERSION 0.7.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# ============================================================
# Version: derived from `git describe --tags --always --dirty`.
# Examples:
# Clean release tag: v0.7.1 -> 0.7.1
# Commits past a tag: v0.7.1-3-gab -> 0.7.1-3-gab
# Dirty working tree: ...dirty -> ...dirty
# No git / no tag: fallback -> 0.7.0-unknown
# Re-run `cmake --preset ...` after tagging or switching branches to refresh.
# ============================================================
find_package(Git QUIET)
set(CLEW_VERSION_RAW "")
if(Git_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE CLEW_VERSION_RAW
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif()
if(NOT CLEW_VERSION_RAW)
set(CLEW_VERSION_RAW "${PROJECT_VERSION}-unknown")
endif()
# Strip leading "v" so "v0.7.1" becomes "0.7.1"
string(REGEX REPLACE "^v" "" CLEW_VERSION "${CLEW_VERSION_RAW}")
message(STATUS "Clew version (from git): ${CLEW_VERSION}")
# Generate C++ header and frontend TS constant.
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/generated/core")
file(WRITE "${CMAKE_BINARY_DIR}/generated/core/version.hpp"
"// Auto-generated by CMake from git describe. Do not edit.\n"
"#pragma once\n"
"#define CLEW_VERSION \"${CLEW_VERSION}\"\n"
)
file(WRITE "${CMAKE_SOURCE_DIR}/frontend/src/version.ts"
"// Auto-generated by CMake from git describe. Do not edit.\n"
"export const CLEW_VERSION = '${CLEW_VERSION}'\n"
)
# Windows-specific settings
if(WIN32)
add_definitions(-DWIN32_LEAN_AND_MEAN -DNOMINMAX -D_WIN32_WINNT=0x0A00)
endif()
# MSVC-specific settings
if(MSVC)
add_compile_options(/utf-8)
endif()
# Option to enable WebView2 GUI support
option(CLEW_ENABLE_WEBVIEW2 "Enable WebView2 GUI support" OFF)
# Optional 100ms refresh-coalesce window in process_projection.
# Default OFF — the strand cost of refresh-per-event at typical loads
# (a few hundred to a few thousand processes, low ETW churn) is
# negligible, and instant pushes feel snappier. Enable only if you
# have a real workload where ETW bursts (e.g. parallel build kicks
# off thousands of children at once) saturate the strand.
option(CLEW_PROJECTION_COALESCE "Enable projection coalesce window (100ms)" OFF)
# ============================================================
# Dependencies (vcpkg)
# ============================================================
find_package(quill CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(httplib CONFIG REQUIRED)
find_package(asio CONFIG REQUIRED)
# ============================================================
# Clew main executable
# ============================================================
# Include directories
include_directories(
${CMAKE_SOURCE_DIR}/src
${CMAKE_BINARY_DIR}/generated
${CMAKE_SOURCE_DIR}/WinDivert-2.2.2-A/include
)
# Link directories
link_directories(
${CMAKE_SOURCE_DIR}/WinDivert-2.2.2-A/x64
)
# Source files. Historically header-only, but the three-layer refactor
# (see refactor_docs/DESIGN.md) progressively introduces hpp/cpp-split
# translation units. The legacy http_api_server.cpp remains until Stage 4
# retires it in favour of src/transport/*.
set(CLEW_SOURCES
src/main.cpp
src/app.cpp
src/common/api_exception.cpp
src/config/config_store.cpp
src/domain/process_tree_manager.cpp
src/services/autostart_service.cpp
src/services/config_service.cpp
src/services/connection_service.cpp
src/services/group_service.cpp
src/services/icon_service.cpp
src/services/process_tree_service.cpp
src/services/rule_service.cpp
src/services/shell_service.cpp
src/services/stats_service.cpp
src/projection/process_projection.cpp
src/projection/config_sse_bridge.cpp
src/transport/response_utils.cpp
src/transport/middleware.cpp
src/transport/route_registry.cpp
src/transport/http_api_server.cpp
src/transport/handlers/autostart_handlers.cpp
src/transport/handlers/config_handlers.cpp
src/transport/handlers/connection_handlers.cpp
src/transport/handlers/group_handlers.cpp
src/transport/handlers/icon_handlers.cpp
src/transport/handlers/process_handlers.cpp
src/transport/handlers/rule_handlers.cpp
src/transport/handlers/shell_handlers.cpp
src/transport/handlers/stats_handlers.cpp
)
# Embed the Clew icon via a Win32 resource file.
if(WIN32)
list(APPEND CLEW_SOURCES ${CMAKE_SOURCE_DIR}/assets/clew.rc)
endif()
# Executable
if(CLEW_ENABLE_WEBVIEW2)
add_executable(clew WIN32 ${CLEW_SOURCES})
target_compile_definitions(clew PRIVATE CLEW_HAS_WEBVIEW2)
else()
add_executable(clew ${CLEW_SOURCES})
endif()
if(CLEW_PROJECTION_COALESCE)
target_compile_definitions(clew PRIVATE CLEW_PROJECTION_COALESCE)
message(STATUS "CLEW_PROJECTION_COALESCE=ON — projection arms a 100ms refresh-coalesce timer for batched events")
endif()
# UAC elevation: embed manifest requesting administrator privileges
# (WinDivert and SetInterfaceDnsSettings both require elevation)
if(MSVC)
target_link_options(clew PRIVATE
"/MANIFESTUAC:level='requireAdministrator' uiAccess='false'")
# Parallel compilation: the Visual Studio generator parallelizes across
# projects by default but serializes .cpp files inside a single project.
# /MP tells cl.exe to span all cores for this target's TUs (~30 after
# the three-layer refactor). No-op on Ninja / MSBuild batch mode.
target_compile_options(clew PRIVATE /MP)
endif()
# Base libraries
set(CLEW_LIBRARIES
ws2_32
iphlpapi
WinDivert
quill::quill
nlohmann_json::nlohmann_json
httplib::httplib
asio::asio
)
# WebView2 configuration
if(CLEW_ENABLE_WEBVIEW2)
set(WEBVIEW2_PATH "${CMAKE_SOURCE_DIR}/src/ui/third_party/WebView2" CACHE PATH "Path to WebView2 SDK")
if(EXISTS "${WEBVIEW2_PATH}/build/native/include/WebView2.h")
message(STATUS "Found WebView2 SDK at ${WEBVIEW2_PATH}")
include_directories("${WEBVIEW2_PATH}/build/native/include")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(WEBVIEW2_ARCH "x64")
else()
set(WEBVIEW2_ARCH "x86")
endif()
if(EXISTS "${WEBVIEW2_PATH}/build/native/${WEBVIEW2_ARCH}/WebView2LoaderStatic.lib")
list(APPEND CLEW_LIBRARIES
"${WEBVIEW2_PATH}/build/native/${WEBVIEW2_ARCH}/WebView2LoaderStatic.lib"
)
message(STATUS "Using WebView2LoaderStatic.lib")
elseif(EXISTS "${WEBVIEW2_PATH}/build/native/${WEBVIEW2_ARCH}/WebView2Loader.dll.lib")
list(APPEND CLEW_LIBRARIES
"${WEBVIEW2_PATH}/build/native/${WEBVIEW2_ARCH}/WebView2Loader.dll.lib"
)
add_custom_command(TARGET clew POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${WEBVIEW2_PATH}/build/native/${WEBVIEW2_ARCH}/WebView2Loader.dll"
"$<TARGET_FILE_DIR:clew>"
)
message(STATUS "Using WebView2Loader.dll")
else()
message(WARNING "WebView2Loader library not found")
endif()
else()
message(WARNING "WebView2 SDK not found at ${WEBVIEW2_PATH}")
endif()
endif()
# Link libraries
target_link_libraries(clew ${CLEW_LIBRARIES})
# Copy WinDivert DLL to output directory
add_custom_command(TARGET clew POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/WinDivert-2.2.2-A/x64/WinDivert.dll"
"$<TARGET_FILE_DIR:clew>"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/WinDivert-2.2.2-A/x64/WinDivert64.sys"
"$<TARGET_FILE_DIR:clew>"
)