-
Notifications
You must be signed in to change notification settings - Fork 36
/
CMakeLists.txt
357 lines (318 loc) · 11.6 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
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
# Should really specify a range of tested versions.
cmake_minimum_required(VERSION 3.24)
cmake_policy(SET CMP0091 NEW)
# Set default build-type (AKA the configuration in other IDEs).
set(CMAKE_BUILD_TYPE_INIT Release)
# Setup Release and Debug build-types (only).
# No reason to set CMAKE_CONFIGURATION_TYPES if it's not a multiconfig generator
# Also no reason mess with CMAKE_BUILD_TYPE if it's a multiconfig generator.
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if (isMultiConfig)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
else()
if (NOT DEFINED CMAKE_BUILD_TYPE)
message(STATUS "Viewer -- Default to Release build.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose Build Type" FORCE)
endif()
message(STATUS "Viewer -- Build type set to: ${CMAKE_BUILD_TYPE}")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY HELPSTRING "Choose Build Type")
# Set the valid options for cmake-gui drop-down list. CMake tools for vscode does not (but should) respect this.
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif()
# This include specifies the project and version.
include("Src/Version.cmake.h")
project(tacentview VERSION "${VIEWER_VERSION}" LANGUAGES C CXX)
message(STATUS "Viewer -- Name ${PROJECT_NAME} Version ${PROJECT_VERSION}")
message(STATUS "Viewer -- Major:${PROJECT_VERSION_MAJOR} Minor:${PROJECT_VERSION_MINOR} Revision:${PROJECT_VERSION_PATCH}")
message(STATUS "Viewer -- CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
# Find Git module.
find_package(Git)
if (Git_FOUND)
message(STATUS "Viewer -- Git found: ${GIT_EXECUTABLE}")
endif()
# We want a better default for install prefix. It is bad form to be modifying
# system files from a cmake build of anything. Really quite surprised someone
# thinks the cmake defaults are good.
# message(STATUS "init=${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}")
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "..." FORCE)
endif()
message(STATUS "Viewer -- InstallPrefix ${CMAKE_INSTALL_PREFIX}")
include(FetchContent)
# Grab the Tacent library from github at configure time. Set desired options here first.
if (CMAKE_SYSTEM_NAME MATCHES Windows)
option(TACENT_UTF16_API_CALLS "Build Tacent With UTF16 API Calls" On)
endif()
# See https://cmake.org/cmake/help/latest/guide/using-dependencies/index.html#fetchcontent-and-find-package-integration
# for how FIND_PACKAGE_ARGS allows FetchContent_MakeAvailable to try find_package() first.
FetchContent_Declare(
tacent
GIT_REPOSITORY https://github.com/bluescan/tacent.git
# GIT_TAG 4941d5455d16768652aea0cd67381b71cb23ea64
# GIT_TAG v0.8.18
FIND_PACKAGE_ARGS NAMES tacent
)
FetchContent_MakeAvailable(tacent)
# After this call you can use variables tacent_POPULATED (a bool), tacent_BINARY_DIR, and tacent_SOURCE_DIR
FetchContent_GetProperties(tacent)
message(STATUS "Viewer -- tacent_POPULATED: ${tacent_POPULATED}")
message(STATUS "Viewer -- tacent_BINARY_DIR: ${tacent_BINARY_DIR}")
message(STATUS "Viewer -- tacent_SOURCE_DIR: ${tacent_SOURCE_DIR}")
# Files needed to create executable.
add_executable(
${PROJECT_NAME}
Src/ColourDialogs.cpp
Src/ColourDialogs.h
Src/Command.cpp
Src/Command.h
Src/CommandHelp.cpp
Src/CommandHelp.h
Src/CommandOps.cpp
Src/CommandOps.h
Src/Config.cpp
Src/Config.h
Src/ContactSheet.cpp
Src/ContactSheet.h
Src/Crop.cpp
Src/Crop.h
Src/Details.cpp
Src/Details.h
Src/Dialogs.cpp
Src/Dialogs.h
Src/FileDialog.cpp
Src/FileDialog.h
Src/GuiUtil.cpp
Src/GuiUtil.h
Src/Image.cpp
Src/Image.h
Src/ImportRaw.cpp
Src/ImportRaw.h
Src/InputBindings.cpp
Src/InputBindings.h
Src/MultiFrame.cpp
Src/MultiFrame.h
Src/OpenSaveDialogs.cpp
Src/OpenSaveDialogs.h
Src/Preferences.cpp
Src/Preferences.h
Src/Profile.cpp
Src/Profile.h
Src/Properties.cpp
Src/Properties.h
Src/Quantize.cpp
Src/Quantize.h
Src/Resize.cpp
Src/Resize.h
Src/Rotate.cpp
Src/Rotate.h
Src/TacentView.cpp
Src/TacentView.h
Src/ThumbnailView.cpp
Src/ThumbnailView.h
Src/Undo.cpp
Src/Undo.h
Src/Version.cmake.h
Src/Version.cpp
$<$<PLATFORM_ID:Windows>:${CMAKE_CURRENT_SOURCE_DIR}/Windows/TacentView.rc>
Contrib/imgui/imgui.cpp
Contrib/imgui/imgui_demo.cpp
Contrib/imgui/imgui_draw.cpp
Contrib/imgui/imgui_tables.cpp
Contrib/imgui/imgui_widgets.cpp
Contrib/imgui/misc/cpp/imgui_stdlib.cpp
Contrib/imgui/backends/imgui_impl_glfw.cpp
Contrib/imgui/backends/imgui_impl_opengl2.cpp
Contrib/glad/src/glad.c
Contrib/clip/clip.cpp
$<$<PLATFORM_ID:Windows>:Contrib/clip/clip_win.cpp>
$<$<PLATFORM_ID:Windows>:Contrib/clip/clip_win_bmp.cpp>
$<$<PLATFORM_ID:Windows>:Contrib/clip/clip_win_wic.cpp>
$<$<PLATFORM_ID:Linux>:Contrib/clip/clip_x11.cpp>
Contrib/clip/image.cpp
)
# Include directories needed to build.
target_include_directories(
"${PROJECT_NAME}"
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/Src
${CMAKE_CURRENT_SOURCE_DIR}/Contrib/imgui
${CMAKE_CURRENT_SOURCE_DIR}/Contrib/imgui/misc/cpp
${CMAKE_CURRENT_SOURCE_DIR}/Contrib/imgui/backends
${CMAKE_CURRENT_SOURCE_DIR}/Contrib/glad/include
${CMAKE_CURRENT_SOURCE_DIR}/Contrib/glfw/include
${CMAKE_CURRENT_SOURCE_DIR}/Contrib/clip
)
target_compile_definitions(
${PROJECT_NAME}
PRIVATE
ARCHITECTURE_X64
GLFW_INCLUDE_NONE
CLIP_ENABLE_IMAGE
$<$<PLATFORM_ID:Linux>:HAVE_PNG_H>
$<$<CONFIG:Debug>:CONFIG_DEBUG>
$<$<CONFIG:Release>:CONFIG_RELEASE>
$<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_DEPRECATE>
$<$<PLATFORM_ID:Windows>:PLATFORM_WINDOWS>
$<$<PLATFORM_ID:Linux>:PLATFORM_LINUX>
$<$<BOOL:${PACKAGE_PORTABLE}>:PACKAGE_PORTABLE>
$<$<BOOL:${PACKAGE_DEV}>:PACKAGE_DEV>
$<$<AND:$<PLATFORM_ID:Linux>,$<BOOL:${PACKAGE_SNAP}>>:PACKAGE_SNAP>
$<$<AND:$<PLATFORM_ID:Linux>,$<BOOL:${PACKAGE_DEB}>>:PACKAGE_DEB>
$<$<AND:$<PLATFORM_ID:Linux>,$<BOOL:${PACKAGE_NIX}>>:PACKAGE_NIX>
# These shouldn't actually be necessary as there are no direct Windows API calls
# in TacentView (they are abstracted away by the Tacent libraries). But just in case
# anything in the viewer were to call an OS-level function, these enable the UTF-16
# versions if the TACENT_UTF16_API_CALLS option is set.
$<$<AND:$<PLATFORM_ID:Windows>,$<BOOL:${TACENT_UTF16_API_CALLS}>>:UNICODE> # C++ UFF-16
$<$<AND:$<PLATFORM_ID:Windows>,$<BOOL:${TACENT_UTF16_API_CALLS}>>:_UNICODE> # C UTF-16
$<$<AND:$<PLATFORM_ID:Windows>,$<BOOL:${TACENT_UTF16_API_CALLS}>>:TACENT_UTF16_API_CALLS>
)
# Set compiler option flags based on specific compiler and configuration.
target_compile_options(
${PROJECT_NAME}
PRIVATE
# MSVC compiler. Warning /utf-8 is needed for MSVC to support UTF-8 source files. Basically u8 string literals won't work without it.
$<$<CXX_COMPILER_ID:MSVC>:/utf-8 /W2 /GS /Gy /Zc:wchar_t /Gm- /Zc:inline /fp:precise /WX- /Zc:forScope /Gd /FC>
# Clang compiler.
$<$<CXX_COMPILER_ID:Clang>:-Wno-switch>
# GNU compiler.
$<$<CXX_COMPILER_ID:GNU>:-Wno-unused-result>
$<$<CXX_COMPILER_ID:GNU>:-Wno-multichar>
# Clang and GNU.
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wno-format-security>
$<$<AND:$<CONFIG:Debug>,$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>>:-O0>
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:MSVC>>:/Od>
$<$<AND:$<CONFIG:Release>,$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>>:-O2>
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:MSVC>>:/O2>
)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
# This is how you set things like CMAKE_DEBUG_POSTFIX for a target.
if (MSVC)
set_target_properties(
${PROJECT_NAME}
PROPERTIES
# DEBUG_POSTFIX "d" # Add a 'd' before the extension for debug builds.
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" # Use multithreaded or multithreaded-debug runtime on windows.
WIN32_EXECUTABLE TRUE
# More prop-value pairs here.
)
endif()
# Dependencies.
target_link_libraries(
${PROJECT_NAME}
PRIVATE
Foundation Math System Image
# $<$<PLATFORM_ID:Windows>:kernel32.lib>
# $<$<PLATFORM_ID:Windows>:user32.lib>
# $<$<PLATFORM_ID:Windows>:gdi32.lib>
# $<$<PLATFORM_ID:Windows>:winspool.lib>
# $<$<PLATFORM_ID:Windows>:shell32.lib>
# $<$<PLATFORM_ID:Windows>:ole32.lib>
# $<$<PLATFORM_ID:Windows>:oleaut32.lib>
# $<$<PLATFORM_ID:Windows>:uuid.lib>
# $<$<PLATFORM_ID:Windows>:comdlg32.lib>
# $<$<PLATFORM_ID:Windows>:advapi32.lib>
$<$<PLATFORM_ID:Windows>:Dbghelp.lib>
$<$<PLATFORM_ID:Windows>:opengl32.lib>
$<$<PLATFORM_ID:Windows>:uxtheme.lib>
$<$<PLATFORM_ID:Windows>:dwmapi.lib>
$<$<PLATFORM_ID:Windows>:${CMAKE_CURRENT_SOURCE_DIR}/Contrib/glfw/glfw3.lib>
$<$<PLATFORM_ID:Linux>:${CMAKE_CURRENT_SOURCE_DIR}/Contrib/glfw/libglfw3.a>
$<$<PLATFORM_ID:Linux>:dl>
$<$<PLATFORM_ID:Linux>:X11>
$<$<PLATFORM_ID:Linux>:xcb> # For clipboard support.
)
if (MSVC)
target_link_options(
${PROJECT_NAME}
PRIVATE
$<IF:$<BOOL:${TACENT_UTF16_API_CALLS}>,/ENTRY:wmainCRTStartup,/ENTRY:mainCRTStartup>
#"/SUBSYSTEM:CONSOLE"
#"/SUBSYSTEM:WINDOWS"
)
if (CMAKE_BUILD_TYPE MATCHES Debug)
target_link_options(
${PROJECT_NAME}
PRIVATE
"/NODEFAULTLIB:LIBCMT.lib"
)
endif()
endif()
# Install
set(VIEWER_INSTALL_DIR "${CMAKE_BINARY_DIR}/ViewerInstall")
message(STATUS "Viewer -- ${PROJECT_NAME} will be installed to ${VIEWER_INSTALL_DIR}")
set(VIEWER_PACKAGE_DIR "${VIEWER_INSTALL_DIR}/Package")
message(STATUS "Viewer -- ${PROJECT_NAME} will be packaged to ${VIEWER_PACKAGE_DIR}")
# Installation.
# if (CMAKE_SYSTEM_NAME MATCHES Linux)
# include(GNUInstallDirs)
# message(STATUS "Viewer -- CMAKE_INSTALL_BINDIR has value ${CMAKE_INSTALL_BINDIR}")
# message(STATUS "Viewer -- CMAKE_INSTALL_DATADIR has value ${CMAKE_INSTALL_DATADIR}")
# install(DIRECTORY Assets/ DESTINATION ${CMAKE_INSTALL_DATADIR}/tacentview/Assets)
# endif()
install(
TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION "${VIEWER_INSTALL_DIR}"
)
install(DIRECTORY Assets/ DESTINATION "${VIEWER_INSTALL_DIR}/Assets")
# Packaging.
if (CMAKE_SYSTEM_NAME MATCHES Linux)
if (PACKAGE_DEB)
install(DIRECTORY Linux/ DESTINATION "${VIEWER_PACKAGE_DIR}")
configure_file("Linux/create_deb.sh.in" "${VIEWER_PACKAGE_DIR}/create_deb.sh" @ONLY)
install(CODE
"
execute_process(COMMAND \"chmod\" \"a+x\" \"ViewerInstall/Package/create_deb.sh\")
execute_process(
COMMAND \"ViewerInstall/Package/create_deb.sh\"
RESULT_VARIABLE package_result
)
if (NOT package_result EQUAL \"0\")
message(FATAL_ERROR \"Viewer -- Deb package creation failed.\")
else()
message(STATUS \"Viewer -- Deb package creation succeeded.\")
endif()
"
)
endif()
endif()
if (CMAKE_SYSTEM_NAME MATCHES Windows)
# The portable package for Windows generates a zip.
if (PACKAGE_PORTABLE)
install(DIRECTORY Windows/ DESTINATION "${VIEWER_PACKAGE_DIR}")
configure_file("Windows/create_zip.ps1.in" "${VIEWER_PACKAGE_DIR}/create_zip.ps1" @ONLY)
install(CODE
"
execute_process(
COMMAND powershell -ExecutionPolicy Bypass -File \"ViewerInstall/Package/create_zip.ps1\"
RESULT_VARIABLE package_result
)
if (NOT package_result EQUAL \"0\")
message(FATAL_ERROR \"Viewer -- ZIP package creation failed.\")
else()
message(STATUS \"Viewer -- ZIP package creation succeeded.\")
endif()
"
)
endif()
endif()
if (CMAKE_SYSTEM_NAME MATCHES Linux)
# The portable package for Linux generates a tgz.
if (PACKAGE_PORTABLE)
install(DIRECTORY Linux/ DESTINATION "${VIEWER_PACKAGE_DIR}")
configure_file("Linux/create_tgz.sh.in" "${VIEWER_PACKAGE_DIR}/create_tgz.sh" @ONLY)
install(CODE
"
execute_process(
COMMAND bash \"ViewerInstall/Package/create_tgz.sh\"
RESULT_VARIABLE package_result
)
if (NOT package_result EQUAL \"0\")
message(FATAL_ERROR \"Viewer -- TGZ package creation failed.\")
else()
message(STATUS \"Viewer -- TGZ package creation succeeded.\")
endif()
"
)
endif()
endif()