forked from fraunhoferhhi/vvdec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
339 lines (279 loc) · 13.4 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
# Top level CMakeLists.txt
#
# minimum required cmake version
cmake_minimum_required( VERSION 3.12.0 FATAL_ERROR )
# set cmake policy
if( NOT CMAKE_VERSION VERSION_LESS 3.12.0 )
# Use latest policy
cmake_policy( VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} )
endif()
# project name
project( vvdec VERSION 1.0.1.0 )
set( VVDEC_ENABLE_X86_SIMD TRUE )
set( VVDEC_ENABLE_ARM_SIMD FALSE )
if( APPLE )
if( DEFINED CMAKE_OSX_ARCHITECTURES )
if( CMAKE_OSX_ARCHITECTURES STREQUAL "" )
if( CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64" )
set( VVDEC_ENABLE_X86_SIMD FALSE )
set( VVDEC_ENABLE_ARM_SIMD TRUE )
endif()
elseif( CMAKE_OSX_ARCHITECTURES STREQUAL "arm64" )
set( VVDEC_ENABLE_X86_SIMD FALSE )
set( VVDEC_ENABLE_ARM_SIMD TRUE )
endif()
else()
if( CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64" )
set( VVDEC_ENABLE_X86_SIMD FALSE )
set( VVDEC_ENABLE_ARM_SIMD TRUE )
endif()
endif()
endif()
# enable sse4.1 build for all source files for gcc and clang
if( VVDEC_ENABLE_X86_SIMD )
if( UNIX OR MINGW )
add_compile_options( "-msse4.1" )
endif()
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTARGET_SIMD_X86" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTARGET_SIMD_X86" )
endif()
if( VVDEC_ENABLE_ARM_SIMD )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTARGET_SIMD_ARM" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTARGET_SIMD_ARM" )
endif()
list( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" )
message( STATUS "CMAKE_MODULE_PATH: updating module path to: ${CMAKE_MODULE_PATH}" )
if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
# set exception handling
if( MSVC )
add_compile_options( "/EHsc" )
endif()
# vvdec embedded by superproject, always include source/Lib/vvdec as first component
list( PREPEND ${PROJECT_NAME}_ADD_SUBDIRECTORIES "source/Lib/vvdec" )
list( REMOVE_DUPLICATES ${PROJECT_NAME}_ADD_SUBDIRECTORIES )
message( STATUS "${CMAKE_CURRENT_SOURCE_DIR}: ${PROJECT_NAME} embedded, subdirectories to be added: ${${PROJECT_NAME}_ADD_SUBDIRECTORIES}" )
# add subdirectories the superproject asked for
foreach( subdir IN LISTS ${PROJECT_NAME}_ADD_SUBDIRECTORIES )
add_subdirectory( ${subdir} )
endforeach()
return()
endif()
# enable or disable bitstream download
set( VVDEC_ENABLE_BITSTREAM_DOWNLOAD OFF CACHE BOOL "Enable or disable bitstream download" )
# enable local bitstream download
set( VVDEC_ENABLE_LOCAL_BITSTREAM_DOWNLOAD OFF CACHE BOOL "Enable or disable local bitstream download" )
# enable install target
set( VVDEC_ENABLE_INSTALL ON CACHE BOOL "Enable or disable install target" )
# enable postfix
set( VVDEC_ENABLE_BUILD_TYPE_POSTFIX OFF CACHE BOOL "Enable or disable build type postfix for apps and libs" )
set( VVDEC_ENABLE_LINK_TIME_OPT ON CACHE BOOL "Enable link time optimization for release and profile builds" )
if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
# enable address sanitizer
set( VVDEC_USE_ADDRESS_SANITIZER OFF CACHE BOOL "Enable or disable address sanitizer" )
# add -march=native
set( VVDEC_OPT_TARGET_ARCH "" CACHE STRING "Enable or disable building with architecture specific optimization" )
endif()
if( VVDEC_ENABLE_BUILD_TYPE_POSTFIX )
if( BUILD_SHARED_LIBS )
# set postfixes for shared libraries
set( CMAKE_RELEASE_POSTFIX "-s" CACHE STRING "Set release library postfix" )
set( CMAKE_DEBUG_POSTFIX "-ds" CACHE STRING "Set debug library postfix" )
set( CMAKE_RELWITHDEBINFO_POSTFIX "-rds" CACHE STRING "Set relwithdebinfo library postfix" )
set( CMAKE_MINSIZEREL_POSTFIX "-mrs" CACHE STRING "Set minsizerel library postfix" )
else()
# set postfixes for static libraries
set( CMAKE_RELEASE_POSTFIX "" CACHE STRING "Set release library postfix" )
set( CMAKE_DEBUG_POSTFIX "-d" CACHE STRING "Set debug library postfix" )
set( CMAKE_RELWITHDEBINFO_POSTFIX "-rd" CACHE STRING "Set relwithdebinfo library postfix" )
set( CMAKE_MINSIZEREL_POSTFIX "-mr" CACHE STRING "Set minsizerel library postfix" )
endif()
endif()
# set VVDEC_OUTPUT_DIR_POSTFIX
if( BUILD_SHARED_LIBS )
set( VVDEC_OUTPUT_DIR_POSTFIX shared )
else()
set( VVDEC_OUTPUT_DIR_POSTFIX static )
endif()
# Using CMake's default library name convention which is the same for all configurations.
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/lib/debug-${VVDEC_OUTPUT_DIR_POSTFIX}" )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/lib/release-${VVDEC_OUTPUT_DIR_POSTFIX}" )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_SOURCE_DIR}/lib/relwithdebinfo-${VVDEC_OUTPUT_DIR_POSTFIX}" )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_SOURCE_DIR}/lib/minsizerel-${VVDEC_OUTPUT_DIR_POSTFIX}" )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG}" )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE}" )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO}" )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL}" )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/bin/debug-${VVDEC_OUTPUT_DIR_POSTFIX}" )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/bin/release-${VVDEC_OUTPUT_DIR_POSTFIX}" )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_SOURCE_DIR}/bin/relwithdebinfo-${VVDEC_OUTPUT_DIR_POSTFIX}" )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_SOURCE_DIR}/bin/minsizerel-${VVDEC_OUTPUT_DIR_POSTFIX}" )
# enable or disable Intel Vtune ITT Tracing
#if( CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
# set( VVDEC_ENABLE_ITT ON CACHE BOOL "Enable Intel Runtime Support for Profiling" )
#else()
# set( VVDEC_ENABLE_ITT OFF CACHE BOOL "Enable Intel Runtime Support for Profiling" )
#endif()
# set default CMAKE_BUILD_TYPE to Release if not set
if( NOT CMAKE_BUILD_TYPE )
set( CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE )
endif()
#set( SET_ENABLE_TRACING OFF CACHE BOOL "Set ENABLE_TRACING as a compiler flag" )
#set( ENABLE_TRACING OFF CACHE BOOL "If SET_ENABLE_TRACING is on, it will be set to this value" )
# set c++14
set( CMAKE_CXX_STANDARD 14 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
# compile everything position independent (even static libraries)
set( CMAKE_POSITION_INDEPENDENT_CODE TRUE )
# set verbose compile options
#set( CMAKE_VERBOSE_MAKEFILE ON )
# use folders in IDEs for projects (e.g. lib sample app test)
set_property( GLOBAL PROPERTY USE_FOLDERS ON )
# Enable multithreading
find_package( Threads REQUIRED )
# set _WIN32_WINNT
if( WIN32 )
# set _WIN32_WINT version global
add_definitions( -D_WIN32_WINNT=0x0600 )
endif()
# enable parallel build for Visual Studio
if( MSVC )
# add compile options
add_compile_options( "/MP" )
add_compile_options( "/EHsc" )
endif()
# set address sanitizer compiler arguments
if( VVDEC_USE_ADDRESS_SANITIZER )
# add compile options
add_compile_options( "-fsanitize=address" )
add_link_options( "-fsanitize=address" )
endif()
if( VVDEC_ENABLE_X86_SIMD )
if( ( UNIX OR MINGW ) AND NOT VVDEC_OPT_TARGET_ARCH STREQUAL "" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=${VVDEC_OPT_TARGET_ARCH} -mtune=${VVDEC_OPT_TARGET_ARCH}" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${VVDEC_OPT_TARGET_ARCH} -mtune=${VVDEC_OPT_TARGET_ARCH}" )
endif()
endif()
if( VVDEC_ENABLE_LINK_TIME_OPT )
set( CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON )
set( CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON )
set( CMAKE_INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL ON )
endif()
# use ccache
find_program( CCACHE_FOUND ccache )
if( CCACHE_FOUND )
message( STATUS "ccache found. using it." )
set_property( GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache )
set_property( GLOBAL PROPERTY RULE_LAUNCH_LINK ccache )
endif()
if( VVDEC_ENABLE_ITT )
if( MSVC )
set( ITT_PATH "c:/Program Files (x86)/IntelSWTools/VTune Amplifier/" CACHE STRING "Path to the installation directory of Intel VTunes" )
elseif( APPLE )
message( WARNING "Not yet supported on Mac OS X" )
elseif( UNIX OR MINGW )
if( EXISTS "/opt/intel/vtune_profiler" )
set( ITT_PATH "/opt/intel/vtune_profiler" CACHE STRING "Path to the installation directory of Intel VTunes" )
else()
set( ITT_PATH "/opt/intel/vtune_amplifier" CACHE STRING "Path to the installation directory of Intel VTunes" )
endif()
endif()
if( EXISTS ${ITT_PATH} )
set( LIB_NAME INTEL_ITT )
add_library( ${LIB_NAME} STATIC IMPORTED GLOBAL )
if( MSVC )
set_target_properties( ${LIB_NAME} PROPERTIES IMPORTED_LOCATION ${ITT_PATH}/lib64/libittnotify.lib )
elseif( APPLE )
# not supported
elseif( UNIX OR MINGW )
set_target_properties( ${LIB_NAME} PROPERTIES IMPORTED_LOCATION ${ITT_PATH}/lib64/libittnotify.a )
set_target_properties( ${LIB_NAME} PROPERTIES INTERFACE_LINK_LIBRARIES dl )
endif()
# set include directory. relative paths do not work.
set_target_properties( ${LIB_NAME} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${ITT_PATH}/include )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTRACE_ENABLE_ITT" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTRACE_ENABLE_ITT" )
else()
message( WARNING "ITT_PATH ${ITT_PATH} not found, ignoring option VVCLib_ENABLE_ITT" )
endif()
endif()
# handle rpath correctly
if( VVDEC_ENABLE_INSTALL )
if( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
set( CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install" CACHE PATH "Standard install prefix" FORCE )
endif()
# use GNU install dirs
include( GNUInstallDirs )
if( BUILD_SHARED_LIBS AND NOT WIN32 )
set( CMAKE_SKIP_INSTALL_RPATH OFF CACHE BOOL "skip rpath" )
if( APPLE )
set( RPATH_BASE @loader_path )
elseif( UNIX )
set( RPATH_BASE $ORIGIN )
endif()
file( RELATIVE_PATH RPATH_REL_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} )
set( CMAKE_INSTALL_RPATH ${RPATH_BASE} ${RPATH_BASE}/${RPATH_REL_DIR} )
message( STATUS "CMAKE_INSTALL_RPATH=${CMAKE_INSTALL_RPATH}" )
endif()
endif()
add_subdirectory( "source/Lib/vvdec" )
add_subdirectory( "source/App/vvdecapp" )
# create a list of all test bitstreams in variable BITSTREAM_FILES
# also defines BITSTREAM_URL_BASE
include( define_bitstream_files )
# set directory global
set( BITSTREAM_INSTALL_DIR_BASE "${CMAKE_SOURCE_DIR}/ext/bitstreams" )
if( VVDEC_ENABLE_BITSTREAM_DOWNLOAD )
# enable FetchContent
include( FetchContent )
# download and uncompress
set( COUNTER 1 )
foreach( BITSTREAM_ZIP IN LISTS BITSTREAM_FILES BITSTREAM_FAULTY_FILES )
string( REGEX REPLACE ".*/(.*)\\..*" "\\1" SUB_DIR "${BITSTREAM_URL_BASE}/${BITSTREAM_ZIP}" )
set( BITSTREAM_INSTALL_DIR "${BITSTREAM_INSTALL_DIR_BASE}/${SUB_DIR}" )
string( REGEX REPLACE "(.*).zip" "\\1" BITSTREAM_SHORT "${BITSTREAM_ZIP}" )
if( NOT EXISTS "${BITSTREAM_INSTALL_DIR}/${BITSTREAM_SHORT}.bit" )
message( STATUS "Downloading ${BITSTREAM_URL_BASE}/${BITSTREAM_ZIP}" )
FetchContent_Populate( download_${COUNTER} QUIET SOURCE_DIR ${BITSTREAM_INSTALL_DIR} URL "${BITSTREAM_URL_BASE}/${BITSTREAM_ZIP}" )
endif()
math( EXPR COUNTER "${COUNTER}+1" )
endforeach()
endif()
# enable testing with ctest
enable_testing()
# add tests for bitstreams
foreach( BITSTREAM IN LISTS BITSTREAM_FILES )
string( REGEX REPLACE "(.*).zip" "\\1" BITSTREAM_SHORT "${BITSTREAM}" )
set( BITSTREAM_FILE "${BITSTREAM_INSTALL_DIR_BASE}/${BITSTREAM_SHORT}/${BITSTREAM_SHORT}.bit" )
if( EXISTS ${BITSTREAM_FILE} )
add_test( NAME Test:${BITSTREAM_SHORT}.bit COMMAND vvdecapp -b ${BITSTREAM_FILE} -dph )
set_tests_properties( Test:${BITSTREAM_SHORT}.bit PROPERTIES TIMEOUT 120 )
else()
add_test( NAME MISSING:${BITSTREAM_SHORT}.bit COMMAND vvdecapp -b ${BITSTREAM_FILE} -dph )
set_tests_properties( MISSING:${BITSTREAM_SHORT}.bit PROPERTIES TIMEOUT 120 )
set( MISSING_BITSTREAM_FILES TRUE )
endif()
endforeach()
foreach( BITSTREAM IN LISTS BITSTREAM_FAULTY_FILES )
string( REGEX REPLACE "(.*).zip" "\\1" BITSTREAM_SHORT "${BITSTREAM}" )
set( BITSTREAM_FILE "${BITSTREAM_INSTALL_DIR_BASE}/${BITSTREAM_SHORT}/${BITSTREAM_SHORT}.bit" )
if( EXISTS ${BITSTREAM_FILE} )
add_test( NAME Faulty:${BITSTREAM_SHORT}.bit COMMAND vvdecapp -b ${BITSTREAM_FILE} -dph )
set_tests_properties( Faulty:${BITSTREAM_SHORT}.bit PROPERTIES TIMEOUT 120 )
else()
add_test( NAME MISSING:${BITSTREAM_SHORT}.bit COMMAND vvdecapp -b ${BITSTREAM_FILE} -dph )
set_tests_properties( MISSING:${BITSTREAM_SHORT}.bit PROPERTIES TIMEOUT 120 )
set( MISSING_BITSTREAM_FILES TRUE )
endif()
endforeach()
add_custom_target( test-ok USES_TERMINAL COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIG> -R "\"^(Test|MISSING)\"" )
add_custom_target( test-all USES_TERMINAL COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIG> -R "\"^(Test|MISSING|Faulty)\"" )
if( MISSING_BITSTREAM_FILES )
message( STATUS "Some bitstream files are missing." )
message( STATUS " If you want to run tests, reconfigure with -DVVDEC_ENABLE_BITSTREAM_DOWNLOAD=ON" )
message( STATUS " (or using top level Makefile: make test enable-bitstream-download=1)" )
endif()
if( VVDEC_ENABLE_INSTALL )
# include installer
include( cmake/modules/vvdecInstall.cmake )
endif()