-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
336 lines (280 loc) · 8.07 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
cmake_minimum_required(VERSION 3.19.1)
cmake_policy(SET CMP0002 NEW)
cmake_policy(SET CMP0077 NEW)
include(ExternalProject)
project(DStream)
option(BUILD_DSTREAM_BENCHMARK "Build the benchmark that compares different depth encoding algorithms" ON)
option(BUILD_DSTREAM_CMD "Build the command line executable that encodes or decodes depthmaps" ON)
option(ENABLE_PNG "Build the project with libpng support. When enabled, zlib will also be linked. When disabled, \
stb_image will be used to handle PNGs instead and zlib won't be linked" OFF)
option(ENABLE_WEBP "Build the project with libwebp support. When enabled, libpng will also be linked" ON)
option(ENABLE_TIFF "Build the project with libtiff support" ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_DEBUG_POSTFIX d)
set (EXTERNAL_DEPS ${CMAKE_BINARY_DIR}/../ext)
# General dependency configuration
set(BUILD_EXAMPLES OFF CACHE INTERNAL "" FORCE)
set(ENABLED_SHARED OFF CACHE INTERNAL "" FORCE)
set(SKIP_INSTALL_ALL ON CACHE INTERNAL "" FORCE)
if(MSVC)
# Build libjpeg
ExternalProject_Add(libjpeg-turbo
PREFIX libjpeg-turbo
BINARY_DIR ${EXTERNAL_DEPS}/libjpeg-turbo
URL https://github.com/libjpeg-turbo/libjpeg-turbo/archive/refs/tags/2.1.90.tar.gz
URL_HASH SHA256=426d097a29bd67ab7ef8584673ba2e0da5fe65dcddd0c8daa123bdcb7a5e871f
)
if (${ENABLE_WEBP} OR ${ENABLE_PNG} OR ${ENABLE_TIFF})
add_subdirectory(lib/vendor/zlib)
configure_file("${PROJECT_SOURCE_DIR}/lib/vendor/zlib/zconf.h.in" "${PROJECT_SOURCE_DIR}/lib/vendor/zlib/zconf.h")
endif()
# Build libpng
if (${ENABLE_WEBP} OR ${ENABLE_PNG})
set(PNG_BUILD_ZLIB ON CACHE INTERNAL "" FORCE)
set(PNG_SHARED OFF CACHE INTERNAL "" FORCE)
set(PNG_EXECUTABLES OFF CACHE INTERNAL "" FORCE)
set(PNG_TESTS OFF CACHE INTERNAL "" FORCE)
add_subdirectory(lib/vendor/libpng)
target_include_directories(png_static PRIVATE lib/vendor/zlib)
target_link_libraries(png_static PRIVATE zlibstatic)
configure_file("${PROJECT_SOURCE_DIR}/lib/vendor/libpng/scripts/pnglibconf.h.prebuilt" "${PROJECT_SOURCE_DIR}/lib/vendor/libpng/pnglibconf.h")
endif()
# Build libwebp
if (${ENABLE_WEBP})
set(WEBP_BUILD_CWEBP OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_DWEBP OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_GIF2WEBP OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_IMG2WEBP OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_VWEBP OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_WEBPINFO OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_LIBWEBPMUX OFF CACHE INTERNAL "" FORCE)
set(WEBP_BUILD_EXTRAS OFF CACHE INTERNAL "" FORCE)
add_subdirectory(lib/vendor/libwebp)
endif()
# Build libtiff
if (${ENABLE_TIFF})
set(tiff-tools OFF CACHE INTERNAL "" FORCE)
set(tiff-tests OFF CACHE INTERNAL "" FORCE)
set(tiff-docs OFF CACHE INTERNAL "" FORCE)
set(tiff-install OFF CACHE INTERNAL "" FORCE)
add_subdirectory(lib/vendor/libtiff)
target_link_libraries(tiff PRIVATE zlibstatic)
endif()
else()
find_package (JPEG REQUIRED)
if (${ENABLE_WEBP} OR ${ENABLE_PNG} OR ${ENABLE_TIFF})
find_package (ZLIB REQUIRED)
endif()
if (${ENABLE_WEBP} OR ${ENABLE_PNG})
find_package (PNG REQUIRED)
endif()
if (${ENABLE_WEBP})
find_package (WEBP REQUIRED)
endif()
if (${ENABLE_TIFF})
find_package (TIFF REQUIRED)
endif()
endif()
# LIB SOURCE
set (DSTREAM_LIB_SRC
lib/StreamCoder.cpp
lib/Coder.cpp
lib/DepthProcessing.cpp
lib/Implementations/Packed2.cpp
lib/Implementations/Packed3.cpp
lib/Implementations/Hilbert.cpp
lib/Implementations/Morton.cpp
lib/Implementations/Hue.cpp
lib/Implementations/Split2.cpp
lib/Implementations/Split3.cpp
lib/Implementations/Triangle.cpp
lib/Implementations/Phase.cpp
lib/StreamCoder.h
lib/DataStructs/Vec3.h
lib/DataStructs/Table.h
lib/DepthProcessing.h
lib/Coder.h
lib/Implementations/Packed2.h
lib/Implementations/Packed3.h
lib/Implementations/Hilbert.h
lib/Implementations/Morton.h
lib/Implementations/Hue.h
lib/Implementations/Split2.h
lib/Implementations/Split3.h
lib/Implementations/Triangle.h
lib/Implementations/Phase.h
)
# Add library
link_directories(
${EXTERNAL_DEPS}/libjpeg-turbo
)
# Compile defs
if (${ENABLE_WEBP} OR ${ENABLE_PNG} OR ${ENABLE_TIFF})
add_compile_definitions(
DSTREAM_ENABLE_ZIP
)
endif()
if (${ENABLE_WEBP} OR ${ENABLE_PNG})
add_compile_definitions(
DSTREAM_ENABLE_PNG
)
endif()
if (${ENABLE_TIFF})
add_compile_definitions(DSTREAM_ENABLE_TIFF)
endif()
if (${ENABLE_WEBP})
add_compile_definitions(DSTREAM_ENABLE_WEBP)
endif()
add_library(dstream-static STATIC ${DSTREAM_LIB_SRC})
if(MSVC)
target_link_libraries(dstream-static
PUBLIC turbojpeg-static
)
if (${ENABLE_WEBP} OR ${ENABLE_PNG} OR ${ENABLE_TIFF})
target_link_libraries(dstream-static
PUBLIC zlibstatic
)
endif()
if (${ENABLE_WEBP} OR ${ENABLE_PNG})
target_link_libraries(dstream-static
PUBLIC png_static
)
endif()
if (${ENABLE_WEBP})
target_link_libraries(dstream-static PUBLIC webp)
endif()
if (${ENABLE_TIFF})
target_link_libraries(dstream-static PUBLIC tiff)
endif()
# TODO: selectively add include directories, do the same for Unix
target_include_directories (dstream-static
PUBLIC lib
)
if (${ENABLE_WEBP} OR ${ENABLE_PNG} OR ${ENABLE_TIFF})
target_include_directories(dstream-static
PUBLIC lib/vendor/zlib
)
endif()
if (${ENABLE_WEBP} OR ${ENABLE_PNG})
target_include_directories(dstream-static
PUBLIC lib/vendor/libpng
)
endif()
if (${ENABLE_TIFF})
target_include_directories(dstream-static
PUBLIC lib/vendor/libtiff
)
endif()
if (${ENABLE_WEBP})
target_include_directories(dstream-static
PUBLIC lib/vendor/libwebp
)
endif()
target_include_directories(dstream-static
PUBLIC ${CMAKE_BINARY_DIR}/libjpeg-turbo/src/libjpeg-turbo
PUBLIC ${EXTERNAL_DEPS}/libjpeg-turbo
)
else()
target_link_libraries(dstream-static
PUBLIC ${JPEG_LIBRARIES}
)
if (${ENABLE_PNG} OR ${ENABLE_WEBP} OR ${ENABLE_TIFF})
target_link_libraries(dstream-static
PUBLIC ${ZLIB_LIBRARIES}
)
endif()
if (${ENABLE_PNG} OR ${ENABLE_WEBP})
target_link_libraries(dstream-static
PUBLIC ${PNG_LIBRARIES}
)
endif()
if (${ENABLE_WEBP})
target_link_libraries(dstream-static
PUBLIC ${WEBP_LIBRARIES}
)
endif()
if (${ENABLE_TIFF})
target_link_libraries(dstream-static
PUBLIC ${TIFF_LIBRARIES}
)
endif()
target_include_directories (dstream-static
PUBLIC lib
${JPEG_INCLUDE_DIR}
)
if (${ENABLE_PNG} OR ${ENABLE_WEBP} OR ${ENABLE_TIFF})
target_include_directories(dstream-static
PUBLIC ${ZLIB_INCLUDE_DIR}
)
endif()
if (${ENABLE_PNG} OR ${ENABLE_WEBP})
target_include_directories(dstream-static
PUBLIC ${PNG_INCLUDE_DIR}
)
endif()
if (${ENABLE_WEBP})
target_include_directories(dstream-static
PUBLIC ${WEBP_INCLUDE_DIR}
)
endif()
if (${ENABLE_WEBP})
target_include_directories(dstream-static
PUBLIC ${TIFF_INCLUDE_DIR}
)
endif()
endif()
# Add benchmark
if (BUILD_DSTREAM_BENCHMARK)
set (DSTREAM_BENCHMARK_SRC
benchmark/DepthmapReader.cpp
benchmark/ImageReader.cpp
benchmark/ImageWriter.cpp
benchmark/Main.cpp
benchmark/Timer.cpp
benchmark/JpegEncoder.cpp
benchmark/JpegDecoder.cpp
benchmark/DepthmapReader.h
benchmark/ImageWriter.h
benchmark/ImageReader.h
benchmark/Timer.h
benchmark/JpegEncoder.h
benchmark/JpegDecoder.h
benchmark/stb_image.h
benchmark/stb_image_write.h
)
add_executable(dstream-benchmark ${DSTREAM_BENCHMARK_SRC})
target_include_directories (dstream-benchmark
PRIVATE benchmark
PRIVATE lib
)
target_link_libraries(dstream-benchmark
PUBLIC dstream-static
)
endif()
# Add CMD executable
if (BUILD_DSTREAM_CMD)
set (DSTREAM_CMD_SRC
cmd/Main.cpp
benchmark/DepthmapReader.cpp
benchmark/ImageReader.cpp
benchmark/ImageWriter.cpp
benchmark/JpegDecoder.cpp
benchmark/JpegEncoder.cpp
benchmark/DepthmapReader.h
benchmark/ImageWriter.h
benchmark/ImageReader.h
benchmark/JpegEncoder.h
benchmark/JpegDecoder.h
benchmark/stb_image.h
benchmark/stb_image_write.h
)
add_executable(dstream-cmd ${DSTREAM_CMD_SRC})
target_include_directories (dstream-cmd
PRIVATE lib
PRIVATE cmd
PRIVATE benchmark
)
target_link_libraries(dstream-cmd
PUBLIC dstream-static
)
endif()