-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
389 lines (328 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
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
cmake_minimum_required (VERSION 3.10.2)
# Use vcpkg if available
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
file(TO_CMAKE_PATH "$ENV{VCPKG_ROOT}" ENV_VCPKG_ROOT)
set(CMAKE_TOOLCHAIN_FILE "${ENV_VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
endif()
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
project(FfFrameReader
VERSION 0.1
DESCRIPTION "FFmpeg based library for reading frames from a video source"
LANGUAGES CXX
)
# Shared/Dynamic or Static library?
option(FFFR_BUILD_SHARED_LIBS "Build libraries as shared as opposed to static" ON)
# Build test related programs?
option(FFFR_BUILD_TESTING "Create test programs" OFF)
# Build with cuda
option(FFFR_BUILD_CUDA "Build using NVIDIA cuda support" ON)
if(FFFR_BUILD_CUDA)
# Build with nppi library? This requires cuda 10.1 or better
option(FFFR_BUILD_NPPI "Build using NVIDIA libnnpi format conversion" ON)
endif()
# Build benchmarking programs?
option(FFFR_BUILD_BENCHMARKING "Create benchmark programs" OFF)
# Build python bindings?
option(FFFR_BUILD_PYTHON_BINDING "Create python bindings" OFF)
# Default to a release build if desired configuration is not specified.
if(NOT CMAKE_CONFIGURATION_TYPES)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE "Release")
endif()
endif()
# Add project source files
set(FFFR_SOURCES_CUDA
source/FFFRFormatConvert.cu
)
set(FFFR_PTX_EMBEDDED
${PROJECT_BINARY_DIR}/FFFREmbeddedPTX.cpp
)
set(FFFR_SOURCES_CONFIG
${PROJECT_BINARY_DIR}/FFFRConfig.h
)
set(FFFR_SOURCES_EXPORT
${PROJECT_BINARY_DIR}/FFFRExports.h
)
set(FFFR_SOURCES
source/FFFR.cpp
source/FFFRStream.cpp
source/FFFRDecoderContext.cpp
source/FFFRFilter.cpp
source/FFFRFrame.cpp
source/FFFREncoder.cpp
source/FFFRUtility.cpp
source/FFFRTypes.cpp
source/FFFRStreamUtils.cpp
include/FFFRDecoderContext.h
include/FFFRFilter.h
include/FFFRUtility.h
include/FFFRStreamUtils.h
${FFFR_PTX_EMBEDDED}
${FFFR_SOURCES_CONFIG}
${FFFR_SOURCES_EXPORT}
)
set(FFFR_HEADERS
include/FFFrameReader.h
include/FFFRStream.h
include/FFFRFrame.h
include/FFFREncoder.h
include/FFFRTypes.h
)
if(FFFR_BUILD_CUDA)
enable_language(CUDA)
find_package(CUDA QUIET REQUIRED)
# Add cuda ptx generation
add_library(FFFRPTX OBJECT ${FFFR_SOURCES_CUDA})
set_target_properties(FFFRPTX PROPERTIES
CUDA_PTX_COMPILATION ON
LINKER_LANGUAGE CUDA
)
# Use bin2c found in cuda toolkit to embed ptx into final executable
get_filename_component(CUDA_COMPILER_DIR "${CMAKE_CUDA_COMPILER}" DIRECTORY)
find_program(BIN_2_C
NAMES bin2c
PATHS ${CUDA_COMPILER_DIR}
)
if(NOT BIN_2_C)
message(FATAL_ERROR
"bin2c not found:\n"
" CMAKE_CUDA_COMPILER='${CMAKE_CUDA_COMPILER}'\n"
" CUDA_COMPILER_DIR='${CUDA_COMPILER_DIR}'\n"
)
endif()
add_custom_command(
OUTPUT "${FFFR_PTX_EMBEDDED}"
COMMAND ${CMAKE_COMMAND}
"-DBIN_TO_C_COMMAND=${BIN_2_C}"
"-DOBJECTS=$<TARGET_OBJECTS:FFFRPTX>"
"-DOUTPUT=${FFFR_PTX_EMBEDDED}"
-P ${PROJECT_SOURCE_DIR}/cmake/bin2c_wrapper.cmake
VERBATIM
DEPENDS $<TARGET_OBJECTS:FFFRPTX>
COMMENT "Converting PTX files to a C header"
)
else()
# Just make a nothing file
configure_file(include/FFFRConfig.h.in ${FFFR_PTX_EMBEDDED} @ONLY)
endif()
configure_file(include/FFFRConfig.h.in ${FFFR_SOURCES_CONFIG} @ONLY)
# Add source to this project's executable.
if(FFFR_BUILD_SHARED_LIBS)
add_library(FfFrameReader
SHARED
${FFFR_SOURCES}
${FFFR_HEADERS}
)
else()
add_library(FfFrameReader
STATIC
${FFFR_SOURCES}
${FFFR_HEADERS}
)
endif()
target_compile_features(FfFrameReader
PUBLIC cxx_std_17
)
include(GNUInstallDirs)
set_target_properties(FfFrameReader PROPERTIES
FRAMEWORK ON
SOVERSION 0
VERSION ${PROJECT_VERSION}
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}"
)
# Detect IPO support
include(CheckIPOSupported)
check_ipo_supported(RESULT BUILD_IPO OUTPUT IPO_ERROR)
if(BUILD_IPO)
set_target_properties(FfFrameReader PROPERTIES
INTERPROCEDURAL_OPTIMIZATION TRUE
)
endif()
# Setup export symbol properties
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
include(GenerateExportHeader)
generate_export_header(FfFrameReader
EXPORT_FILE_NAME ${FFFR_SOURCES_EXPORT}
)
if(FFFR_BUILD_CUDA)
add_dependencies(FfFrameReader FFFRPTX)
endif()
# Find the required FFmpeg libraries
find_path(AVCODEC_INCLUDE_DIR NAMES libavcodec/avcodec.h)
find_library(AVCODEC_LIBRARY NAMES avcodec)
find_path(AVFORMAT_INCLUDE_DIR NAMES libavformat/avformat.h)
find_library(AVFORMAT_LIBRARY NAMES avformat)
find_path(AVFILTER_INCLUDE_DIR NAMES libavfilter/avfilter.h)
find_library(AVFILTER_LIBRARY NAMES avfilter)
find_path(AVUTIL_INCLUDE_DIR NAMES libavutil/avutil.h)
find_library(AVUTIL_LIBRARY NAMES avutil)
target_include_directories(FfFrameReader
PUBLIC ${PROJECT_SOURCE_DIR}/include
PRIVATE ${AVCODEC_INCLUDE_DIR}
PRIVATE ${AVFORMAT_INCLUDE_DIR}
PRIVATE ${AVFILTER_INCLUDE_DIR}
PRIVATE ${AVUTIL_INCLUDE_DIR}
PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
PUBLIC ${PROJECT_BINARY_DIR}
)
target_link_libraries(FfFrameReader
PRIVATE ${AVCODEC_LIBRARY}
PRIVATE ${AVFORMAT_LIBRARY}
PRIVATE ${AVFILTER_LIBRARY}
PRIVATE ${AVUTIL_LIBRARY}
PRIVATE ${SWSCALE_LIBRARY}
PRIVATE ${POSTPROC_LIBRARY}
PRIVATE ${SWRESAMPLE_LIBRARY}
PRIVATE ${CUDA_CUDA_LIBRARY}
PRIVATE ${CUDA_nppicc_LIBRARY}
)
if("${CMAKE_INSTALL_PREFIX}" STREQUAL "")
message("Installing into source folder")
# Temp set the install location to the source location
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install CACHE PATH "..." FORCE)
endif()
# Install targets.
install(TARGETS FfFrameReader
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# Add tests
if(FFFR_BUILD_TESTING)
enable_testing()
find_package(GTest REQUIRED)
include(GoogleTest)
add_executable(FFFRTest
test/FFFRTestStream.cpp
test/FFFRTestSeek.cpp
test/FFFRTestDecode.cpp
test/FFFRTestFrame.cpp
test/FFFRTestFilter.cpp
test/FFFRTestEncode.cpp
test/FFFRTestConvert.cpp
test/FFFRTestShared.cpp
test/FFFRTestData.h
)
target_include_directories(FFFRTest PRIVATE
${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
)
target_link_libraries(FFFRTest
PRIVATE FfFrameReader
PRIVATE GTest::GTest
PRIVATE GTest::Main
PRIVATE ${CUDA_CUDA_LIBRARY}
PRIVATE ${AVUTIL_LIBRARY}
)
set_target_properties(FFFRTest PROPERTIES
EXCLUDE_FROM_ALL true
VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/test"
VERSION ${PROJECT_VERSION}
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}"
)
# Enable all compile warnings
if(MSVC)
target_compile_options(FfFrameReader PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/W4 /WX /experimental:external /external:anglebrackets /external:W3>)
else()
target_compile_options(FfFrameReader PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Wall -Wextra -pedantic -Werror>)
endif()
add_dependencies(FFFRTest FfFrameReader)
gtest_discover_tests(FFFRTest
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/test"
)
endif()
# Add benchmarks
if(FFFR_BUILD_BENCHMARKING)
find_package(benchmark REQUIRED)
add_executable(FFFRBenchmark
benchmark/FFFRBenchmarkStream.cpp
benchmark/FFFRBenchmarkConvert.cpp
benchmark/FFFRBenchmarkRead.cpp
)
target_include_directories(FFFRBenchmark PRIVATE
PRIVATE ${benchmark_INCLUDE_DIRS}
)
target_link_libraries(FFFRBenchmark
PRIVATE FfFrameReader
PRIVATE benchmark::benchmark
PRIVATE benchmark::benchmark_main
)
set_target_properties(FFFRBenchmark PROPERTIES
EXCLUDE_FROM_ALL true
VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/test"
VERSION ${PROJECT_VERSION}
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}"
)
if(BUILD_IPO)
set_target_properties(FFFRBenchmark PROPERTIES
INTERPROCEDURAL_OPTIMIZATION TRUE
)
endif()
add_dependencies(FFFRBenchmark FfFrameReader)
endif()
# Download video files used for testing and benchmarking
if(FFFR_BUILD_TESTING OR FFFR_BUILD_BENCHMARKING)
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/test/data/bbb_sunflower_1080p_30fps_normal.mp4")
file(DOWNLOAD http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_30fps_normal.mp4
"${PROJECT_SOURCE_DIR}/test/data/bbb_sunflower_1080p_30fps_normal.mp4"
INACTIVITY_TIMEOUT 15
SHOW_PROGRESS
)
endif()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/test/data/tvl_missing_pts.avi")
file(DOWNLOAD https://cloudstor.aarnet.edu.au/plus/s/MFGSPUiEyHMi8cB/download
"${PROJECT_SOURCE_DIR}/test/data/tvl_missing_pts.avi"
INACTIVITY_TIMEOUT 15
SHOW_PROGRESS
TLS_VERIFY ON
)
endif()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/test/data/board_game-h264.mkv")
file(DOWNLOAD https://github.com/anibali/tvl/raw/master/data/board_game-h264.mkv
"${PROJECT_SOURCE_DIR}/test/data/board_game-h264.mkv"
INACTIVITY_TIMEOUT 15
SHOW_PROGRESS
TLS_VERIFY ON
)
endif()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/test/data/board_game-h264-cropped.mkv")
file(DOWNLOAD https://github.com/anibali/tvl/raw/master/data/board_game-h264-cropped.mkv
"${PROJECT_SOURCE_DIR}/test/data/board_game-h264-cropped.mkv"
INACTIVITY_TIMEOUT 15
SHOW_PROGRESS
TLS_VERIFY ON
)
endif()
endif()
# Add python bindings
if(FFFR_BUILD_PYTHON_BINDING)
find_package(pybind11 REQUIRED)
pybind11_add_module(pyFrameReader python/FFFRPybind11.cpp)
configure_file(python/__init__.py.in "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/pyFrameReader/__init__.py")
configure_file(python/setup.py.in "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/setup.py")
set_target_properties(pyFrameReader PROPERTIES
FRAMEWORK ON
SOVERSION 0
VERSION ${PROJECT_VERSION}
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/pyFrameReader"
)
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
set_target_properties(pyFrameReader PROPERTIES
LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/pyFrameReader")
endforeach()
target_link_libraries(pyFrameReader
PRIVATE FfFrameReader
)
add_dependencies(pyFrameReader FfFrameReader)
endif()