-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
387 lines (364 loc) · 13.8 KB
/
CMakeLists.txt
File metadata and controls
387 lines (364 loc) · 13.8 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
cmake_minimum_required(VERSION 3.26)
project(greenflame VERSION 0.6.0 LANGUAGES CXX)
# So the IDE (and clangd) can find includes for all targets, including tests.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(GREENFLAME_ENABLE_TIME_TRACE
"Emit Clang -ftime-trace JSON files during compilation"
OFF
)
# cmake-scripts (pulled by Catch2/CPM) sets CMAKE_COMPILE_WARNING_AS_ERROR=ON
# which adds /WX globally, breaking builds on warnings in third-party headers.
# We control warnings per-target already, so disable it.
set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)
# Keep the app as a GUI subsystem executable on Windows.
set(CMAKE_WIN32_EXECUTABLE ON)
# -----------------------------
# Version and metadata (single source of truth)
# -----------------------------
set(GREENFLAME_VERSION_TWEAK 0 CACHE STRING "Fourth version component for Windows resources")
set(GREENFLAME_FILE_VERSION_COMMA
"${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},${GREENFLAME_VERSION_TWEAK}"
)
set(GREENFLAME_FILE_VERSION_DOTTED
"${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${GREENFLAME_VERSION_TWEAK}"
)
set(GREENFLAME_COMPANY_NAME "Jocelyn Legault" CACHE STRING "Company name in VERSIONINFO")
set(GREENFLAME_PRODUCT_NAME "Greenflame" CACHE STRING "Product name in VERSIONINFO")
set(GREENFLAME_FILE_DESCRIPTION "Greenflame Screenshot Tool" CACHE STRING "File description in VERSIONINFO")
set(GREENFLAME_COPYRIGHT "Copyright (C) 2026 Jocelyn Legault" CACHE STRING "Copyright in VERSIONINFO")
set(GREENFLAME_INTERNAL_NAME "greenflame.exe" CACHE STRING "InternalName in VERSIONINFO")
set(GREENFLAME_ORIGINAL_FILENAME "greenflame.exe" CACHE STRING "OriginalFilename in VERSIONINFO")
set(GREENFLAME_MANIFEST_NAME "greenflame" CACHE STRING "Manifest assemblyIdentity name")
set(GREENFLAME_ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/resources/greenflame.ico")
file(TO_CMAKE_PATH "${GREENFLAME_ICON_PATH}" GREENFLAME_ICON_PATH)
set(GREENFLAME_FREEHAND_CURSOR_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/resources/small-crosshair.cur"
)
file(TO_CMAKE_PATH "${GREENFLAME_FREEHAND_CURSOR_PATH}"
GREENFLAME_FREEHAND_CURSOR_PATH)
set(GREENFLAME_BRUSH_TOOL_GLYPH_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/resources/brush-mask.png"
)
file(TO_CMAKE_PATH "${GREENFLAME_BRUSH_TOOL_GLYPH_PATH}"
GREENFLAME_BRUSH_TOOL_GLYPH_PATH)
set(GREENFLAME_HIGHLIGHTER_TOOL_GLYPH_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/resources/highlighter-mask.png"
)
file(TO_CMAKE_PATH "${GREENFLAME_HIGHLIGHTER_TOOL_GLYPH_PATH}"
GREENFLAME_HIGHLIGHTER_TOOL_GLYPH_PATH)
set(GREENFLAME_LINE_TOOL_GLYPH_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/resources/line-mask.png"
)
file(TO_CMAKE_PATH "${GREENFLAME_LINE_TOOL_GLYPH_PATH}"
GREENFLAME_LINE_TOOL_GLYPH_PATH)
set(GREENFLAME_ARROW_TOOL_GLYPH_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/resources/arrow-mask.png"
)
file(TO_CMAKE_PATH "${GREENFLAME_ARROW_TOOL_GLYPH_PATH}"
GREENFLAME_ARROW_TOOL_GLYPH_PATH)
set(GREENFLAME_RECTANGLE_TOOL_GLYPH_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/resources/rectangle-mask.png"
)
file(TO_CMAKE_PATH "${GREENFLAME_RECTANGLE_TOOL_GLYPH_PATH}"
GREENFLAME_RECTANGLE_TOOL_GLYPH_PATH)
set(GREENFLAME_FILLED_RECTANGLE_TOOL_GLYPH_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/resources/filled_rectangle-mask.png"
)
file(TO_CMAKE_PATH "${GREENFLAME_FILLED_RECTANGLE_TOOL_GLYPH_PATH}"
GREENFLAME_FILLED_RECTANGLE_TOOL_GLYPH_PATH)
set(GREENFLAME_TEXT_TOOL_GLYPH_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/resources/text-mask.png"
)
file(TO_CMAKE_PATH "${GREENFLAME_TEXT_TOOL_GLYPH_PATH}"
GREENFLAME_TEXT_TOOL_GLYPH_PATH)
set(GREENFLAME_HELP_TOOL_GLYPH_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/resources/help-mask.png"
)
file(TO_CMAKE_PATH "${GREENFLAME_HELP_TOOL_GLYPH_PATH}"
GREENFLAME_HELP_TOOL_GLYPH_PATH)
set(GREENFLAME_BUBBLE_TOOL_GLYPH_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/resources/bubble-mask.png"
)
file(TO_CMAKE_PATH "${GREENFLAME_BUBBLE_TOOL_GLYPH_PATH}"
GREENFLAME_BUBBLE_TOOL_GLYPH_PATH)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/app.manifest.in"
"${CMAKE_CURRENT_BINARY_DIR}/app.manifest"
@ONLY
)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/resources/greenflame.rc.in"
"${CMAKE_CURRENT_BINARY_DIR}/greenflame.rc"
@ONLY
)
# -----------------------------
# greenflame_core (testable library)
# -----------------------------
add_library(greenflame_core STATIC
src/greenflame_core/rect_px.cpp
src/greenflame_core/rect_px.h
src/greenflame_core/cli_options.cpp
src/greenflame_core/cli_options.h
src/greenflame_core/app_controller.cpp
src/greenflame_core/app_controller.h
src/greenflame_core/app_config.cpp
src/greenflame_core/app_config.h
src/greenflame_core/app_services.h
src/greenflame_core/process_exit_code.h
src/greenflame_core/monitor_rules.cpp
src/greenflame_core/monitor_rules.h
src/greenflame_core/pixel_ops.cpp
src/greenflame_core/pixel_ops.h
src/greenflame_core/bmp.cpp
src/greenflame_core/bmp.h
src/greenflame_core/selection_handles.cpp
src/greenflame_core/selection_handles.h
src/greenflame_core/snap_to_edges.cpp
src/greenflame_core/snap_to_edges.h
src/greenflame_core/snap_edge_builder.cpp
src/greenflame_core/snap_edge_builder.h
src/greenflame_core/save_image_policy.cpp
src/greenflame_core/save_image_policy.h
src/greenflame_core/string_utils.cpp
src/greenflame_core/string_utils.h
src/greenflame_core/window_filter.cpp
src/greenflame_core/window_filter.h
src/greenflame_core/window_query.h
src/greenflame_core/output_path.cpp
src/greenflame_core/output_path.h
src/greenflame_core/annotation_commands.cpp
src/greenflame_core/annotation_commands.h
src/greenflame_core/annotation_controller.cpp
src/greenflame_core/annotation_controller.h
src/greenflame_core/annotation_edit_interaction.cpp
src/greenflame_core/annotation_edit_interaction.h
src/greenflame_core/annotation_hit_test.cpp
src/greenflame_core/annotation_hit_test.h
src/greenflame_core/annotation_types.h
src/greenflame_core/annotation_tool.h
src/greenflame_core/text_annotation_types.h
src/greenflame_core/text_layout_engine.h
src/greenflame_core/text_edit_controller.cpp
src/greenflame_core/text_edit_controller.h
src/greenflame_core/text_annotation_tool.cpp
src/greenflame_core/text_annotation_tool.h
src/greenflame_core/bubble_annotation_types.cpp
src/greenflame_core/bubble_annotation_types.h
src/greenflame_core/bubble_annotation_tool.cpp
src/greenflame_core/bubble_annotation_tool.h
src/greenflame_core/freehand_annotation_tool.cpp
src/greenflame_core/freehand_annotation_tool.h
src/greenflame_core/line_annotation_tool.cpp
src/greenflame_core/line_annotation_tool.h
src/greenflame_core/rectangle_annotation_tool.cpp
src/greenflame_core/rectangle_annotation_tool.h
src/greenflame_core/annotation_tool_registry.cpp
src/greenflame_core/annotation_tool_registry.h
src/greenflame_core/color_wheel.cpp
src/greenflame_core/color_wheel.h
src/greenflame_core/overlay_controller.cpp
src/greenflame_core/overlay_controller.h
src/greenflame_core/overlay_help_content.h
src/greenflame_core/command.h
src/greenflame_core/undo_stack.cpp
src/greenflame_core/undo_stack.h
src/greenflame_core/modification_command.h
src/greenflame_core/toolbar_placement.h
src/greenflame_core/toolbar_placement.cpp
)
# Allow includes like: #include "greenflame_core/rect_px.h"
target_include_directories(greenflame_core PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
target_compile_definitions(greenflame_core PRIVATE
NOMINMAX
WIN32_LEAN_AND_MEAN
UNICODE
_UNICODE
$<$<CONFIG:Debug>:DEBUG>
)
target_precompile_headers(greenflame_core PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/src/greenflame_core/pch.h>"
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(greenflame_core PRIVATE
-Wall
-Wextra
-Wpedantic
-Werror
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-pre-c++14-compat
-Wno-pre-c++17-compat
-Wno-pre-c++20-compat
-Wno-implicit-int-float-conversion
-Wno-switch-default
-Wno-language-extension-token
)
if(GREENFLAME_ENABLE_TIME_TRACE)
target_compile_options(greenflame_core PRIVATE -ftime-trace)
endif()
elseif(MSVC)
target_compile_options(greenflame_core PRIVATE
/Wall
/WX
/wd4355 # 'this': used in base member initializer list
/wd4514 # 'function' : unreferenced inline function has been removed
/wd4710 # 'function' : function not inlined
/wd4711 # 'function' : function selected for automatic inline expansion
/wd4820 # 'bytes' bytes padding added after construct 'member_name'
/wd5045 # Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
/external:W0
/external:anglebrackets
/permissive-
/Zc:__cplusplus
)
else()
target_compile_options(greenflame_core PRIVATE -Wall -Wextra -Wpedantic -Werror)
endif()
# -----------------------------
# Tests
# -----------------------------
include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
# -----------------------------
# easyjson (header-only JSON)
# -----------------------------
include(FetchContent)
FetchContent_Declare(
easyjson
GIT_REPOSITORY https://github.com/jahan-addison/easyjson.git
GIT_TAG v1.2.1
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(easyjson)
# -----------------------------
# greenflame (Win32 GUI app)
# -----------------------------
add_executable(greenflame WIN32
src/greenflame/main.cpp
src/greenflame/console_output.cpp
src/greenflame/console_output.h
src/greenflame/greenflame_app.cpp
src/greenflame/greenflame_app.h
src/greenflame/app_config_store.cpp
src/greenflame/app_config_store.h
src/greenflame/win/display_queries.cpp
src/greenflame/win/display_queries.h
src/greenflame/win/gdi_capture.cpp
src/greenflame/win/gdi_capture.h
src/greenflame/win/save_image.cpp
src/greenflame/win/overlay_help_overlay.cpp
src/greenflame/win/overlay_help_overlay.h
src/greenflame/win/overlay_window.cpp
src/greenflame/win/overlay_window.h
src/greenflame/win/about_dialog.cpp
src/greenflame/win/about_dialog.h
src/greenflame/win/startup_launch.cpp
src/greenflame/win/startup_launch.h
src/greenflame/win/tray_window.cpp
src/greenflame/win/tray_window.h
src/greenflame/win/window_query.cpp
src/greenflame/win/window_query.h
src/greenflame/win/win32_services.cpp
src/greenflame/win/win32_services.h
src/greenflame/win/overlay_button.h
src/greenflame/win/overlay_button.cpp
src/greenflame/win/d2d_overlay_resources.h
src/greenflame/win/d2d_overlay_resources.cpp
src/greenflame/win/d2d_text_layout_engine.h
src/greenflame/win/d2d_text_layout_engine.cpp
src/greenflame/win/d2d_paint.h
src/greenflame/win/d2d_paint.cpp
${CMAKE_CURRENT_BINARY_DIR}/app.manifest
${CMAKE_CURRENT_BINARY_DIR}/greenflame.rc
)
target_include_directories(greenflame PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/greenflame
)
target_compile_definitions(greenflame PRIVATE
NOMINMAX
WIN32_LEAN_AND_MEAN
UNICODE
_UNICODE
GREENFLAME_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
GREENFLAME_VERSION_MINOR=${PROJECT_VERSION_MINOR}
GREENFLAME_VERSION_PATCH=${PROJECT_VERSION_PATCH}
$<$<CONFIG:Debug>:DEBUG>
)
target_precompile_headers(greenflame PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/src/greenflame/pch.h>"
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(greenflame PRIVATE
-Wall
-Wextra
-Wpedantic
-Werror
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-pre-c++14-compat
-Wno-pre-c++17-compat
-Wno-pre-c++20-compat
-Wno-implicit-int-float-conversion
-Wno-switch-default
-Wno-language-extension-token
)
if(GREENFLAME_ENABLE_TIME_TRACE)
target_compile_options(greenflame PRIVATE -ftime-trace)
endif()
elseif(MSVC)
target_compile_options(greenflame PRIVATE
/Wall
/WX
/wd4355 # 'this': used in base member initializer list
/wd4514 # 'function' : unreferenced inline function has been removed
/wd4710 # 'function' : function not inlined
/wd4711 # 'function' : function selected for automatic inline expansion
/wd4820 # 'bytes' bytes padding added after construct 'member_name'
/wd5045 # Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
/external:W0
/external:anglebrackets
/permissive-
/Zc:__cplusplus
)
else()
target_compile_options(greenflame PRIVATE -Wall -Wextra -Wpedantic -Werror)
endif()
target_link_libraries(greenflame PRIVATE
greenflame_core
easyjson
# Win32 basics
user32
gdi32
shcore
shell32
advapi32
dwmapi
comdlg32
Windowscodecs
ole32
gdiplus
d2d1
dwrite
dxguid # CLSID_D2D1ArithmeticComposite and other D2D effect GUIDs
)
# -----------------------------
# Link-Time Optimization (release builds only)
# -----------------------------
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Full LTO: TUs emit LLVM bitcode; lld-link merges and optimizes at link time.
foreach(_lto_tgt greenflame_core greenflame)
target_compile_options(${_lto_tgt} PRIVATE $<$<CONFIG:Release>:-flto=full>)
endforeach()
target_link_options(greenflame PRIVATE $<$<CONFIG:Release>:-flto=full>)
elseif(MSVC)
# Whole Program Optimisation: /GL at compile time, /LTCG at link time.
set_property(TARGET greenflame_core PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
set_property(TARGET greenflame PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
endif()