-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
473 lines (413 loc) · 15.1 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
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
cmake_minimum_required(VERSION 3.8)
set(APPLICATION_NAME "sviewgl")
project(${APPLICATION_NAME})
include(FindPkgConfig)
include(CheckLibraryExists)
include(cmake/clang-cxx-dev-tools.cmake)
set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# prefer new GLVND over OLD
set(OpenGL_GL_PREFERENCE GLVND)
set(APP_TITLE "Simple Viewer GL" CACHE STRING "Application name")
set(APP_VERSION_MAJOR "1" CACHE STRING "Application major version")
set(APP_VERSION_MINOR "0" CACHE STRING "Application minor version")
set(APP_VERSION_RELEASE "0" CACHE STRING "Application release version")
set(VERSION "${APP_VERSION_MAJOR}.${APP_VERSION_MINOR}.${APP_VERSION_RELEASE}")
function(pretty_fill TITLE MAXLEN FILLER ALIGN)
string(LENGTH ${TITLE} TITLE_LENGTH)
math(EXPR FILLER_COUNT "${MAXLEN} - ${TITLE_LENGTH}")
if (${FILLER_COUNT} GREATER 0)
if (${ALIGN} STREQUAL "-")
math(EXPR LEFT_COUNT "${FILLER_COUNT} / 2")
math(EXPR RIGHT_COUNT "${FILLER_COUNT} - ${LEFT_COUNT}")
string(REPEAT ${FILLER} ${LEFT_COUNT} L)
string(REPEAT ${FILLER} ${RIGHT_COUNT} R)
set(RESULT "${L}${TITLE}${R}" PARENT_SCOPE)
elseif(${ALIGN} STREQUAL ">")
string(REPEAT ${FILLER} ${FILLER_COUNT} F)
set(RESULT "${F}${TITLE}" PARENT_SCOPE)
else()
string(REPEAT ${FILLER} ${FILLER_COUNT} F)
set(RESULT "${TITLE}${F}" PARENT_SCOPE)
endif()
else()
set(RESULT "${TITLE}" PARENT_SCOPE)
endif()
endfunction()
function(pretty_print LEFT TITLE RIGHT FILLER ALIGN)
set(HEADER_SIZE 40) # max header size
string(LENGTH "${LEFT}${RIGHT}" BORDER_SIZE)
math(EXPR COUNT "${HEADER_SIZE} - ${BORDER_SIZE}")
pretty_fill("${TITLE}" ${COUNT} ${FILLER} ${ALIGN})
message("${LEFT}${RESULT}${RIGHT}")
endfunction()
pretty_print("*" "*" "*" "*" "-")
pretty_print("*" "Simple Viewer GL" "*" " " "-")
pretty_print("*" "v${VERSION}" "*" " " "-")
pretty_print("*" "*" "*" "*" "-")
if(CMAKE_BUILD_TYPE STREQUAL "Release")
pretty_print("*" "Release Build" "*" " " "-")
add_definitions("-DNDEBUG" )
add_definitions("-Wall -Wextra -pedantic -pedantic-errors -Wno-unused-function -Wno-deprecated-register -O2")
else()
pretty_print("*" "Debug Build" "*" " " "-")
add_definitions("-DDEBUG" )
add_definitions("-Wall -Wextra -pedantic -pedantic-errors -O0 -g")
endif()
pretty_print("*" "*" "*" "*" "-")
find_package(PkgConfig REQUIRED)
add_subdirectory(third-party/imgui)
add_subdirectory(third-party/lz4)
# set(VERBOSE_PATHS TRUE)
find_package(OpenGL QUIET REQUIRED)
if(OPENGL_FOUND)
pretty_print("* " "[+] OpenGL found" " *" " " "<")
if(VERBOSE_PATHS)
message(" ${OPENGL_INCLUDE_DIR}")
message(" ${OPENGL_LIBRARY}")
endif()
link_directories(${OPENGL_LIBRARY_DIRS})
include_directories(${OPENGL_INCLUDE_DIR})
else()
pretty_print("* " "[ ] OpenGL not found" " *" " " "<")
# message(FATAL_ERROR "[ ] OpenGL not found")
endif()
pkg_search_module(GLFW3 QUIET REQUIRED glfw3)
if(GLFW3_FOUND)
pretty_print("* " "[+] GLFW3 found" " *" " " "<")
if(VERBOSE_PATHS)
message(" ${GLFW3_INCLUDE_DIRS}")
message(" ${GLFW3_LIBRARIES}")
endif()
link_directories(${GLFW3_LIBRARY_DIRS})
include_directories(${GLFW3_INCLUDE_DIRS})
else()
pretty_print("* " "[ ] GLFW3 not found" " *" " " "<")
# message(FATAL_ERROR "[ ] GLFW3 not found")
endif()
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads QUIET REQUIRED)
if(Threads_FOUND)
pretty_print("* " "[+] Threads found" " *" " " "<")
else()
pretty_print("* " "[ ] Threads not found" " *" " " "<")
# message(FATAL_ERROR "[ ] Threads not found")
endif()
if(UNIX AND NOT APPLE)
find_package(X11 QUIET REQUIRED)
if(X11_FOUND)
pretty_print("* " "[+] X11 found" " *" " " "<")
if(VERBOSE_PATHS)
message(" ${X11_INCLUDE_DIR}")
message(" ${X11_LIBRARIES}")
endif()
link_directories(${X11_LIBRARY_DIRS})
include_directories(${X11_INCLUDE_DIR})
if(X11_Xinerama_FOUND)
link_directories(${X11_Xinerama_LIBRARY_DIRS})
include_directories(${X11_Xinerama_INCLUDE_PATH})
endif()
else()
pretty_print("* " "[ ] X11 not found" " *" " " "<")
# message(FATAL_ERROR "[ ] X11 not found")
endif()
endif()
find_package(ZLIB QUIET REQUIRED)
if(ZLIB_FOUND)
pretty_print("* " "[+] ZLib found" " *" " " "<")
if(VERBOSE_PATHS)
message(" ${ZLIB_INCLUDE_DIR}")
message(" ${ZLIB_LIBRARIES}")
endif()
link_directories(${ZLIB_LIBRARY_DIRS})
include_directories(${ZLIB_INCLUDE_DIR})
else()
pretty_print("* " "[ ] ZLib not found" " *" " " "<")
# message(FATAL_ERROR "[ ] ZLib not found")
endif()
find_package(PNG QUIET REQUIRED)
if(PNG_FOUND)
pretty_print("* " "[+] PNG support enabled" " *" " " "<")
if(VERBOSE_PATHS)
message(" ${PNG_INCLUDE_DIR}")
message(" ${PNG_LIBRARY}")
endif()
# add_definitions(-DPNG_SUPPORT=1)
link_directories(${PNG_LIBRARY_DIRS})
include_directories(${PNG_INCLUDE_DIR})
else()
pretty_print("* " "[ ] PNG not found" " *" " " "<")
# message(FATAL_ERROR "[ ] PNG not found")
endif()
find_package(JPEG QUIET REQUIRED)
if(JPEG_FOUND)
pretty_print("* " "[+] JPEG support enabled" " *" " " "<")
if(VERBOSE_PATHS)
message(" ${JPEG_INCLUDE_DIR}")
message(" ${JPEG_LIBRARIES}")
endif()
# add_definitions(-DJPEG_SUPPORT=1)
link_directories(${JPEG_LIBRARY_DIRS})
include_directories(${JPEG_INCLUDE_DIR})
else()
pretty_print("* " "[ ] JPEG not found" " *" " " "<")
# message(FATAL_ERROR "[ ] JPEG not found")
endif()
set(DISABLE_EXIF_SUPPORT "0" CACHE STRING "Disable EXIF support.")
if (DISABLE_EXIF_SUPPORT EQUAL 0)
pkg_check_modules(EXIF QUIET libexif)
if(EXIF_FOUND)
pretty_print("* " "[+] EXIF support enabled" " *" " " "<")
if(VERBOSE_PATHS)
message(" ${EXIF_INCLUDE_DIRS}")
message(" ${EXIF_LIBRARIES}")
endif()
add_definitions(-DEXIF_SUPPORT=1)
link_directories(${EXIF_LIBRARY_DIRS})
include_directories(${EXIF_INCLUDE_DIRS})
else()
pretty_print("* " "[ ] EXIF support dropped" " *" " " "<")
endif()
else()
pretty_print("* " "[ ] EXIF support disabled" " *" " " "<")
endif()
set(DISABLE_LCMS2_SUPPORT "0" CACHE STRING "Disable LCMS support.")
if (DISABLE_LCMS2_SUPPORT EQUAL 0)
find_package(LCMS2 QUIET)
if(LCMS2_FOUND)
pretty_print("* " "[+] LCMS2 support enabled" " *" " " "<")
if(VERBOSE_PATHS)
message(" ${LCMS2_INCLUDE_DIR}")
message(" ${LCMS2_LIBRARIES}")
endif()
add_definitions(-DLCMS2_SUPPORT=1)
link_directories(${LCMS2_LIBRARY_DIRS})
include_directories(${LCMS2_INCLUDE_DIR})
else()
pretty_print("* " "[ ] LCMS2 support dropped" " *" " " "<")
endif()
else()
pretty_print("* " "[ ] LCMS2 support disabled" " *" " " "<")
endif()
set(DISABLE_JPEG2000_SUPPORT "0" CACHE STRING "Disable OpenJPEG2 support.")
if (DISABLE_JPEG2000_SUPPORT EQUAL 0)
pkg_check_modules(JPEG2K QUIET libopenjp2)
if(JPEG2K_FOUND)
pretty_print("* " "[+] OpenJPEG2 support enabled" " *" " " "<")
if(VERBOSE_PATHS)
message(" ${JPEG2K_INCLUDE_DIRS}")
message(" ${JPEG2K_LIBRARIES}")
endif()
add_definitions(-DJPEG2000_SUPPORT=1)
link_directories(${JPEG2K_LIBRARY_DIRS})
include_directories(${JPEG2K_INCLUDE_DIRS})
else()
pretty_print("* " "[ ] OpenJPEG2 support dropped" " *" " " "<")
endif()
else()
pretty_print("* " "[ ] OpenJPEG2 support disabled" " *" " " "<")
endif()
set(DISABLE_GIF_SUPPORT "0" CACHE STRING "Disable GIF support.")
if (DISABLE_GIF_SUPPORT EQUAL 0)
find_package(GIF QUIET)
if(GIF_FOUND)
pretty_print("* " "[+] GIF support enabled" " *" " " "<")
if(VERBOSE_PATHS)
message(" ${GIF_INCLUDE_DIR}")
message(" ${GIF_LIBRARIES}")
endif()
add_definitions(-DGIF_SUPPORT=1)
link_directories(${GIF_LIBRARY_DIRS})
include_directories(${GIF_INCLUDE_DIR})
else()
pretty_print("* " "[ ] GIF support dropped" " *" " " "<")
endif()
else()
pretty_print("* " "[ ] GIF support disabled" " *" " " "<")
endif()
set(DISABLE_TIFF_SUPPORT "0" CACHE STRING "Disable TIFF support.")
if (DISABLE_TIFF_SUPPORT EQUAL 0)
find_package(TIFF QUIET)
if(TIFF_FOUND)
pretty_print("* " "[+] TIFF support enabled" " *" " " "<")
if(VERBOSE_PATHS)
message(" ${TIFF_INCLUDE_DIRS}")
message(" ${TIFF_LIBRARIES}")
endif()
add_definitions(-DTIFF_SUPPORT=1)
link_directories(${TIFF_LIBRARY_DIRS})
include_directories(${TIFF_INCLUDE_DIRS})
else()
pretty_print("* " "[ ] TIFF support dropped" " *" " " "<")
endif()
else()
pretty_print("* " "[ ] TIFF support disabled" " *" " " "<")
endif()
set(DISABLE_WEBP_SUPPORT "0" CACHE STRING "Disable WebP support.")
if (DISABLE_WEBP_SUPPORT EQUAL 0)
find_package(WebP QUIET)
if(WEBP_FOUND)
pretty_print("* " "[+] WebP support enabled" " *" " " "<")
if(VERBOSE_PATHS)
message(" ${WEBP_INCLUDE_DIRS}")
message(" ${WEBP_LIBRARIES}")
endif()
add_definitions(-DWEBP_SUPPORT=1)
link_directories(${WEBP_LIBRARY_DIRS})
include_directories(${WEBP_INCLUDE_DIRS})
else()
pretty_print("* " "[ ] WebP support dropped" " *" " " "<")
endif()
else()
pretty_print("* " "[ ] WebP support disabled" " *" " " "<")
endif()
set(DISABLE_OPENEXR_SUPPORT "0" CACHE STRING "Disable OpenEXR support.")
if (DISABLE_OPENEXR_SUPPORT EQUAL 0)
pkg_check_modules(OPENEXR QUIET OpenEXR)
if(OPENEXR_FOUND)
pkg_check_modules(ILMBASE QUIET IlmBase)
if(ILMBASE_FOUND)
pretty_print("* " "[+] OpenEXR support enabled" " *" " " "<")
if(VERBOSE_PATHS)
message(" ${ILMBASE_INCLUDE_DIRS} ${OPENEXR_INCLUDE_DIRS}")
message(" ${ILMBASE_LIBRARIES} ${OPENEXR_LIBRARIES}")
endif()
add_definitions(-DOPENEXR_SUPPORT=1)
link_directories(${ILMBASE_LIBRARY_DIRS} ${OPENEXR_LIBRARY_DIRS})
include_directories(${ILMBASE_INCLUDE_DIRS} ${OPENEXR_INCLUDE_DIRS})
else()
pretty_print("* " "[ ] ILMBase not found" " *" " " "<")
endif()
else()
pretty_print("* " "[ ] OpenEXR support dropped" " *" " " "<")
endif()
else()
pretty_print("* " "[ ] OpenEXR support disabled" " *" " " "<")
endif()
set(DISABLE_CURL_SUPPORT "0" CACHE STRING "Disable Curl support.")
if (DISABLE_CURL_SUPPORT EQUAL 0)
find_package(CURL QUIET)
if(CURL_FOUND)
pretty_print("* " "[+] Curl support enabled" " *" " " "<")
if(VERBOSE_PATHS)
message(" ${CURL_INCLUDE_DIRS}")
message(" ${CURL_LIBRARIES}")
endif()
add_definitions(-DCURL_SUPPORT=1)
link_directories(${CURL_LIBRARY_DIRS})
include_directories(${CURL_INCLUDE_DIRS})
else()
pretty_print("* " "[ ] Curl support dropped" " *" " " "<")
endif()
else()
pretty_print("* " "[ ] Curl support disabled" " *" " " "<")
endif()
set(DISABLE_IMLIB2_SUPPORT "0" CACHE STRING "Disable Imlib2 support.")
if (DISABLE_IMLIB2_SUPPORT EQUAL 0)
find_package(Imlib2 QUIET)
if(IMLIB2_FOUND)
pretty_print("* " "[+] Imlib2 support enabled" " *" " " "<")
if(VERBOSE_PATHS)
message(" ${IMLIB2_INCLUDE_DIR}")
message(" ${IMLIB2_LIBRARY}")
endif()
add_definitions(-DIMLIB2_SUPPORT=1)
link_directories(${IMLIB2_LIBRARY_DIRS})
include_directories(${IMLIB2_INCLUDE_DIR})
else()
pretty_print("* " "[ ] Imlib2 support dropped" " *" " " "<")
endif()
else()
pretty_print("* " "[ ] Imlib2 support disabled" " *" " " "<")
endif()
check_library_exists(rt clock_gettime "" RT_FOUND)
if(RT_FOUND)
set(RT_LIBRARY "rt")
endif()
pretty_print("*" "*" "*" "*" "-")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp.in"
"${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp"
)
include_directories("src")
file(GLOB_RECURSE SVIEW_SOURCES "src/*.cpp")
if(APPLE)
add_definitions("-DGL_SILENCE_DEPRECATION")
execute_process(
COMMAND makeicns -in res/Icon-1024.png -32 res/Icon-32.png -16 res/Icon-16.png -out res/macos/Icon.icns
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_QUIET ERROR_QUIET
)
set(SVIEW_ICON ${CMAKE_CURRENT_SOURCE_DIR}/res/macos/Icon.icns)
set_source_files_properties(${SVIEW_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
file(GLOB_RECURSE SVIEW_SOURCES_M "src/*.m")
add_executable(${APPLICATION_NAME} MACOSX_BUNDLE ${SVIEW_ICON} ${SVIEW_SOURCES} ${SVIEW_SOURCES_M})
set_target_properties(${APPLICATION_NAME} PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/res/macos/Info.plist.in
MACOSX_BUNDLE_LONG_VERSION_STRING ${VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${VERSION}
MACOSX_BUNDLE_BUNDLE_VERSION ${VERSION}
)
target_link_libraries(${APPLICATION_NAME} "-framework AppKit")
else()
add_executable(${APPLICATION_NAME} ${SVIEW_SOURCES})
endif()
add_dependencies(${APPLICATION_NAME} ImGui LZ4)
target_link_libraries(${APPLICATION_NAME} ImGui LZ4)
if(OPENGL_FOUND)
target_link_libraries(${APPLICATION_NAME} ${OPENGL_LIBRARY})
endif()
if(GLFW3_FOUND)
target_link_libraries(${APPLICATION_NAME} ${GLFW3_LIBRARIES})
endif()
if(Threads_FOUND)
target_link_libraries(${APPLICATION_NAME} ${CMAKE_THREAD_LIBS_INIT})
endif()
if(LCMS2_FOUND)
target_link_libraries(${APPLICATION_NAME} ${LCMS2_LIBRARIES})
endif()
if(ZLIB_FOUND)
target_link_libraries(${APPLICATION_NAME} ${ZLIB_LIBRARIES})
endif()
if(X11_FOUND)
target_link_libraries(${APPLICATION_NAME} ${X11_LIBRARIES})
if(X11_Xinerama_FOUND)
target_link_libraries(${APPLICATION_NAME} ${X11_Xinerama_LIB})
endif()
endif()
if(PNG_FOUND)
target_link_libraries(${APPLICATION_NAME} ${PNG_LIBRARY})
endif()
if(JPEG_FOUND)
target_link_libraries(${APPLICATION_NAME} ${JPEG_LIBRARIES})
endif()
if(EXIF_FOUND)
target_link_libraries(${APPLICATION_NAME} ${EXIF_LIBRARIES})
endif()
if(JPEG2K_FOUND)
target_link_libraries(${APPLICATION_NAME} ${JPEG2K_LIBRARIES})
endif()
if(GIF_FOUND)
target_link_libraries(${APPLICATION_NAME} ${GIF_LIBRARIES})
endif()
if(TIFF_FOUND)
target_link_libraries(${APPLICATION_NAME} ${TIFF_LIBRARIES})
endif()
if(WEBP_FOUND)
target_link_libraries(${APPLICATION_NAME} ${WEBP_LIBRARIES})
endif()
if(OPENEXR_FOUND AND ILMBASE_FOUND)
target_link_libraries(${APPLICATION_NAME} ${ILMBASE_LIBRARIES} ${OPENEXR_LIBRARIES})
endif()
if(CURL_FOUND)
target_link_libraries(${APPLICATION_NAME} ${CURL_LIBRARIES})
endif()
if(IMLIB2_FOUND)
target_link_libraries(${APPLICATION_NAME} ${IMLIB2_LIBRARY})
endif()
if(RT_FOUND)
target_link_libraries(${APPLICATION_NAME} ${RT_LIBRARY})
endif()