forked from Kagami/SVT-AV1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
281 lines (247 loc) · 10.2 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
#
# Copyright(c) 2018 Intel Corporation
#
# This source code is subject to the terms of the BSD 2 Clause License and
# the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
# was not distributed with this source code in the LICENSE file, you can
# obtain it at https://www.aomedia.org/license/software-license. If the Alliance for Open
# Media Patent License 1.0 was not distributed with this source code in the
# PATENTS file, you can obtain it at https://www.aomedia.org/license/patent-license.
#
cmake_minimum_required(VERSION 3.5)
if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
message(WARNING "Building in-source is highly not recommended\n"
"Please use the Build folder or create your own.")
endif()
project(svt-av1 VERSION 0.8.6
LANGUAGES C CXX)
set(CMAKE_C_VISIBILITY_PRESET hidden)
# Default build type to release if the generator does not has its own set of build types
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release)
endif()
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
message(WARNING "32-bit is not supported")
endif()
option(COMPILE_C_ONLY "Compile only C code with no simds (autodetect, default off for x86)" OFF)
include(CheckCSourceCompiles)
check_c_source_compiles("
#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__x86_64__)
#else
#error \"Non-x86\"
#endif
int main(void) {}
" HAVE_X86_PLATFORM)
if(NOT COMPILE_C_ONLY AND HAVE_X86_PLATFORM)
find_program(YASM_EXE yasm)
option(ENABLE_NASM "Use nasm if available (Uses yasm by default if found)" OFF)
if(YASM_EXE AND NOT CMAKE_ASM_NASM_COMPILER MATCHES "yasm" AND NOT ENABLE_NASM)
set(CMAKE_ASM_NASM_COMPILER "${YASM_EXE}" CACHE FILEPATH "Path to nasm compatible compiler" FORCE)
else()
set(NASM_VERSION "0.0.0")
include(CheckLanguage)
check_language(ASM_NASM)
execute_process(COMMAND ${CMAKE_ASM_NASM_COMPILER} -v
OUTPUT_VARIABLE NASM_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "([.0-9])+" NASM_VERSION "${NASM_VERSION}")
# NASM_VERSION should now contain something like 2.14.02
# Needs to error out on a version less than 2.14
if(NASM_VERSION VERSION_LESS "2.14" AND CMAKE_ASM_NASM_COMPILER MATCHES "nasm")
message(FATAL_ERROR "Found nasm is too old (requires at least 2.14, found ${NASM_VERSION})!")
endif()
endif()
enable_language(ASM_NASM)
add_definitions(-DARCH_X86_64=1)
endif()
include(GNUInstallDirs)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
set(CMAKE_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/Bin/${CMAKE_BUILD_TYPE}/" CACHE PATH "Location to write the resulting binaries to")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY})
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
# make it prominent in the GUI.
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." ON)
message(STATUS "BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
option(BUILD_TESTING "Build SvtAv1UnitTests, SvtAv1ApiTests, and SvtAv1E2ETests unit tests")
option(COVERAGE "Generate coverage report")
option(BUILD_APPS "Build Enc and Dec Apps" ON)
option(BUILD_ENC "Build Encoder lib and app" ON)
option(BUILD_DEC "Build Decoder lib and app" ON)
if(NOT BUILD_ENC AND NOT BUILD_DEC)
message(FATAL_ERROR "Not building either the encoder and decoder doesn't make sense.")
endif()
if(WIN32)
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DWIN64")
else()
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DUNIX64")
endif()
if(UNIX)
if(APPLE)
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie -z noexecstack -z relro -z now")
endif()
endif()
# Always build with -fPIC
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(flags_to_test
-Wextra
-Wformat
-Wformat-security)
if(MSVC)
list(INSERT flags_to_test 0 /W3)
list(APPEND flags_to_test /MP)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /O2")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Od")
else()
list(INSERT flags_to_test 0 -Wall)
option(NATIVE "Build for native performance (march=native)")
if(NATIVE)
list(APPEND flags_to_test -march=native)
endif()
if(COVERAGE)
list(APPEND flags_to_test --coverage)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif()
if(MINGW)
list(APPEND flags_to_test -mxsave -fno-asynchronous-unwind-tables)
else()
list(APPEND flags_to_test -fstack-protector-strong -D_FORTIFY_SOURCE=2)
endif()
endif()
foreach(flag ${flags_to_test};${release_flags_to_test};${debug_flags_to_test})
string(REGEX REPLACE "[^A-Za-z0-9]" "_" flag_var "${flag}")
set(test_c_flag "C_FLAG${flag_var}")
set(test_cxx_flag "CXX_FLAG${flag_var}")
check_c_compiler_flag(${flag} "${test_c_flag}")
check_cxx_compiler_flag(${flag} "${test_cxx_flag}")
if(${flag} IN_LIST release_flags_to_test)
if(${test_c_flag})
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${flag}")
endif()
if(${test_cxx_flag})
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${flag}")
endif()
elseif(${flag} IN_LIST debug_flags_to_test)
if(${test_c_flag})
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${flag}")
endif()
if(${test_cxx_flag})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${flag}")
endif()
else()
if(${test_c_flag})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
endif()
if(${test_cxx_flag})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endif()
endif()
endforeach()
if(CMAKE_C_FLAGS MATCHES ".*-march=native.*")
string(APPEND CMAKE_C_FLAGS " -mno-avx")
endif()
if(CMAKE_CXX_FLAGS MATCHES ".*-march=native.*")
string(APPEND CMAKE_CXX_FLAGS " -mno-avx")
endif()
if(CMAKE_ASM_NASM_OBJECT_FORMAT MATCHES "win")
set(CMAKE_ASM_NASM_FLAGS_DEBUG "${CMAKE_ASM_NASM_FLAGS_DEBUG} -gcv8")
elseif(CMAKE_ASM_NASM_COMPILER MATCHES "nasm")
set(CMAKE_ASM_NASM_FLAGS_DEBUG "${CMAKE_ASM_NASM_FLAGS_DEBUG} -gdwarf")
elseif(CMAKE_ASM_NASM_COMPILER MATCHES "yasm")
if(CMAKE_ASM_NASM_OBJECT_FORMAT MATCHES "macho")
set(CMAKE_ASM_NASM_FLAGS_DEBUG "${CMAKE_ASM_NASM_FLAGS_DEBUG} -gnull")
else()
set(CMAKE_ASM_NASM_FLAGS_DEBUG "${CMAKE_ASM_NASM_FLAGS_DEBUG} -gdwarf2")
endif()
endif()
include(CheckSymbolExists)
check_symbol_exists("_mm512_extracti64x4_epi64" "immintrin.h" HAS_AVX512)
if(NOT HAS_AVX512)
add_definitions(-DNON_AVX512_SUPPORT)
endif()
# ASM compiler macro
macro(ASM_COMPILE_TO_TARGET target)
if(CMAKE_GENERATOR STREQUAL "Xcode")
if(CMAKE_BUILD_TYPE MATCHES Release)
set(ASM_FLAGS "${CMAKE_ASM_NASM_FLAGS_RELEASE}")
elseif(CMAKE_BUILD_TYPE MATCHES Debug)
set(ASM_FLAGS "${CMAKE_ASM_NASM_FLAGS_DEBUG}")
elseif(CMAKE_BUILD_TYPE MATCHES MinSizeRel)
set(ASM_FLAGS "${CMAKE_ASM_NASM_FLAGS_MINSIZEREL}")
elseif(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
set(ASM_FLAGS "${CMAKE_ASM_NASM_FLAGS_RELWITHDEBINFO}")
endif()
get_property(inc_dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(inc_dir ${inc_dirs})
set(ASM_FLAGS "${ASM_FLAGS} -I${inc_dir}")
endforeach()
string(REGEX REPLACE " " ";" ASM_FLAGS "${ASM_FLAGS} ${CMAKE_ASM_NASM_FLAGS}")
foreach(asm_file ${ARGN})
get_filename_component(filename "${asm_file}" NAME_WE)
set(SIMD_OBJ "${CMAKE_CURRENT_BINARY_DIR}/${filename}${CMAKE_C_OUTPUT_EXTENSION}")
message(STATUS "Pregenerating ASM_NASM file ${filename}${CMAKE_C_OUTPUT_EXTENSION}")
execute_process(COMMAND ${CMAKE_ASM_NASM_COMPILER}
-f${CMAKE_ASM_NASM_OBJECT_FORMAT}
-I${CMAKE_CURRENT_SOURCE_DIR}
-o${SIMD_OBJ}
${ASM_FLAGS}
${CMAKE_CURRENT_SOURCE_DIR}/${asm_file}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
list(APPEND SIMD_OBJS "${SIMD_OBJ}")
endforeach()
#target_sources(${target} PUBLIC ${SIMD_OBJS})
target_sources(common_lib INTERFACE ${SIMD_OBJS})
else()
# For every other generator
foreach(asm_file ${ARGN})
get_filename_component(filename "${asm_file}" ABSOLUTE)
target_sources(${target} PUBLIC ${filename})
endforeach()
endif()
endmacro()
add_subdirectory(third_party/safestringlib)
set_property(DIRECTORY .
APPEND
PROPERTY COMPILE_DEFINITIONS
$<$<BOOL:${HAVE_STRCPY_S}>:HAVE_STRCPY_S=1>
$<$<BOOL:${HAVE_STRNCPY_S}>:HAVE_STRNCPY_S=1>
$<$<BOOL:${HAVE_STRNLEN_S}>:HAVE_STRNLEN_S=1>
$<$<BOOL:${WIN32}>:_WIN32_WINNT=0x0601>)
# Find out if we have threading available
set(CMAKE_THREAD_PREFER_PTHREADS ON)
find_package(Threads)
# Add Subdirectories
add_subdirectory(Source/Lib/Common)
if(BUILD_ENC)
add_subdirectory(Source/Lib/Encoder)
endif()
if(BUILD_DEC)
add_subdirectory(Source/Lib/Decoder)
endif()
if(BUILD_APPS AND BUILD_ENC)
add_subdirectory(Source/App/EncApp)
endif()
if(BUILD_APPS AND BUILD_DEC)
add_subdirectory(Source/App/DecApp)
endif()
if(BUILD_TESTING)
include(CTest)
message(STATUS "Building UnitTests")
add_subdirectory(test)
add_subdirectory(third_party/googletest)
endif()
add_subdirectory(third_party/fastfeat)
add_subdirectory(third_party/cpuinfo)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/Source/API/ DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/svt-av1" FILES_MATCHING PATTERN "*.h")