-
Notifications
You must be signed in to change notification settings - Fork 72
/
CMakeLists.txt
367 lines (330 loc) · 13.8 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
# ----------------------------------------------------------------------------
# Root CMake file for Rockchip Media Process Platform (MPP)
#
# - 10:34 2015/7/27: Initial version <[email protected]>
#
# ----------------------------------------------------------------------------
# vim: syntax=cmake
if(NOT CMAKE_BUILD_TYPE)
# default to Release build for GCC builds
set(CMAKE_BUILD_TYPE Debug CACHE STRING
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
message(STATUS "cmake version ${CMAKE_VERSION}")
# Search packages for host system instead of packages for target system
# in case of cross compilation these macro should be defined by toolchain file
if(NOT COMMAND find_host_package)
macro(find_host_package)
find_package(${ARGN})
endmacro()
endif()
if(NOT COMMAND find_host_program)
macro(find_host_program)
find_program(${ARGN})
endmacro()
endif()
project (rk_mpp)
cmake_minimum_required (VERSION 2.8.8) # OBJECT libraries require 2.8.8
include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckCXXCompilerFlag)
# setup output library name
# Linux default name - rockchip_mpp and rockchip_vpu
# Android default name - mpp and vpu
# For historical reason libraries on Android is named as mpp and vpu. But for
# better naming rule on Linux it should add vendor prefix.
# So we use this ugly method to avoid massive maintain issue.
if (NOT MPP_PROJECT_NAME)
set(MPP_PROJECT_NAME rockchip_mpp)
endif()
set(MPP_STATIC ${MPP_PROJECT_NAME}_static)
set(MPP_SHARED ${MPP_PROJECT_NAME})
if (NOT VPU_PROJECT_NAME)
set(VPU_PROJECT_NAME rockchip_vpu)
endif()
set(VPU_STATIC ${VPU_PROJECT_NAME}_static)
set(VPU_SHARED ${VPU_PROJECT_NAME})
# ----------------------------------------------------------------------------
# set property to classify library kinds
# ----------------------------------------------------------------------------
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets")
# ----------------------------------------------------------------------------
# enable test in this project
# ----------------------------------------------------------------------------
option(BUILD_TEST "enable test binary building)" ON)
# ----------------------------------------------------------------------------
# export json compile commands
# ----------------------------------------------------------------------------
set(CMAKE_EXPORT_COMPILE_COMMANDS true)
# ----------------------------------------------------------------------------
# System architecture detection
# ----------------------------------------------------------------------------
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" SYSPROC)
set(X86_ALIASES x86 i386 i686 x86_64 amd64)
list(FIND X86_ALIASES "${SYSPROC}" X86MATCH)
if("${CMAKE_C_COMPILER}" MATCHES "-buildroot-[^/]+$")
message(STATUS "Detected Buildroot toolchain")
# Use buildroot toolchain's default architecture settings
elseif("${SYSPROC}" STREQUAL "" OR X86MATCH GREATER "-1")
message(STATUS "Detected x86 system processor")
set(X86 true)
add_definitions(-DARCH_X86=1)
if("${CMAKE_SIZEOF_VOID_P}" MATCHES 8)
set(X64 true)
add_definitions(-DARCH_X64=1)
message(STATUS "Define X86_64 to 1")
endif()
elseif(${SYSPROC} STREQUAL "armv6l")
message(STATUS "Detected ARMv6 system processor")
set(ARM true)
set(ARMEABI_V6 true)
elseif(${SYSPROC} STREQUAL "armv7-a")
message(STATUS "Detected ARMv7 system processor")
set(ARM true)
set(ARMEABI_V7A true)
elseif(${SYSPROC} STREQUAL "armv7-a_hardfp" OR ${SYSPROC} STREQUAL "armv7l")
message(STATUS "Detected ARMv7 system processor")
set(ARM true)
set(ARMEABI_V7A_HARDFP true)
elseif(${SYSPROC} STREQUAL "aarch64" OR ${SYSPROC} STREQUAL "armv8-a")
message(STATUS "Detected ARMv8 system processor")
set(ARM true)
set(ARMEABI_V8 true)
else()
message(STATUS "CMAKE_SYSTEM_PROCESSOR value `${CMAKE_SYSTEM_PROCESSOR}` is unknown")
message(STATUS "Please add this value near ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE}")
endif()
if(UNIX)
SET(PLATFORM_LIBS pthread)
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
SET(PLATFORM_LIBS ${PLATFORM_LIBS} rt)
endif()
endif(UNIX)
# ----------------------------------------------------------------------------
# Compiler detection
# ----------------------------------------------------------------------------
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CLANG true)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(INTEL_CXX true)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(GCC true)
endif()
if(INTEL_CXX AND UNIX)
# treat icpc roughly like gcc
set(GCC true)
add_definitions(-Wall -Wextra -Wshadow)
elseif(CLANG)
# treat clang roughly like gcc
set(GCC true)
add_definitions(-Wall -Wextra -Wshadow -ffast-math)
elseif(CMAKE_COMPILER_IS_GNUCXX)
add_definitions(-Wall -Wextra -Wshadow -ffast-math)
check_cxx_compiler_flag(-Wno-narrowing GCC_HAS_NO_NARROWING)
check_cxx_compiler_flag(-mstackrealign GCC_HAS_STACK_REALIGN)
if (GCC_HAS_STACK_REALIGN)
add_definitions(-mstackrealign)
endif()
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
endif()
if(GCC)
if(ARM)
if(ARMEABI_V6)
add_definitions(-march=armv6 -mfloat-abi=hard -mfpu=vfp)
elseif(ARMEABI_V7A)
add_definitions(-march=armv7-a -mfloat-abi=softfp -mfpu=neon)
elseif(ARMEABI_V7A_HARDFP)
add_definitions(-march=armv7-a -mfloat-abi=hard -mfpu=neon)
elseif(ARMEABI_V8)
add_definitions(-march=armv8-a)
endif()
else()
if(X86 AND NOT X64)
add_definitions(-march=i686)
endif()
endif()
if(NOT ${CMAKE_BUILD_TYPE} MATCHES "Release")
add_definitions(-g)
endif()
# disable multichar warning
add_definitions(-Wno-multichar)
# add PIC flag
add_definitions(-fPIC)
# disable exception for C++
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
# save intermediate files
# add_definitions(-save-temps)
# for libary linking
set(BEGIN_WHOLE_ARCHIVE -Wl,--whole-archive)
set(END_WHOLE_ARCHIVE -Wl,--no-whole-archive)
option(ASAN_CHECK "enable Address Sanitizer (Asan)" OFF)
if(ASAN_CHECK)
add_definitions(-fsanitize=address -static-libasan -g)
set(ASAN_LIB libasan.a dl rt m)
set(ASAN_BIN dl rt m)
endif(ASAN_CHECK)
endif(GCC)
# ----------------------------------------------------------------------------
# Create git version information
# ----------------------------------------------------------------------------
set(VERSION_CNT 0)
set(VERSION_MAX_CNT 9)
set(VERSION_INFO "\"unknown mpp version for missing VCS info\"")
foreach (CNT RANGE ${VERSION_MAX_CNT})
set(VERSION_HISTORY_${CNT} "NULL")
endforeach(CNT)
if(EXISTS "${PROJECT_SOURCE_DIR}/.git")
find_host_package(Git)
if(GIT_FOUND)
# get current version info
set(GIT_LOG_FORMAT "%h author: %<|(30)%an %cd %s")
execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --oneline --date=short --pretty=format:${GIT_LOG_FORMAT}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE EXEC_OUT
ERROR_VARIABLE EXEC_ERROR
RESULT_VARIABLE EXEC_RET
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE)
if (NOT EXEC_RET)
set(VERSION_INFO ${EXEC_OUT})
message(STATUS "current version:")
message(STATUS "${VERSION_INFO}")
string(REPLACE "\"" "\\\"" VERSION_INFO ${VERSION_INFO})
set(VERSION_INFO "\"${VERSION_INFO}\"")
else()
message(STATUS "git ret ${EXEC_RET}")
message(STATUS "${EXEC_ERROR}")
endif()
set(GIT_LOG_FORMAT "%h author: %<|(30)%an %cd %s %d")
# get history version information
# setup logs
message(STATUS "git version history:")
foreach (CNT RANGE ${VERSION_MAX_CNT})
execute_process(COMMAND ${GIT_EXECUTABLE} log HEAD~${CNT} -1 --oneline --date=short --pretty=format:${GIT_LOG_FORMAT}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE EXEC_OUT
ERROR_VARIABLE EXEC_ERROR
RESULT_VARIABLE EXEC_RET
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE)
if (NOT EXEC_RET)
set(VERSION_LOG ${EXEC_OUT})
string(REPLACE "\"" "\\\"" VERSION_LOG ${VERSION_LOG})
message(STATUS ${VERSION_LOG})
set(VERSION_HISTORY_${CNT} "\"${VERSION_LOG}\"")
math(EXPR VERSION_CNT "${VERSION_CNT}+1")
endif()
endforeach(CNT)
message(STATUS "total ${VERSION_CNT} git version recorded")
endif()
# add git hooks
if (EXISTS "${PROJECT_SOURCE_DIR}/tools/hooks/")
set(GIT_HOOK_SRC "${PROJECT_SOURCE_DIR}/tools/hooks/")
if(EXISTS "${PROJECT_SOURCE_DIR}/.git/hooks")
set(GIT_HOOK_DST "${PROJECT_SOURCE_DIR}/.git/hooks/")
file(COPY ${GIT_HOOK_SRC} DESTINATION ${GIT_HOOK_DST})
message(STATUS "Install git hooks done")
endif(EXISTS "${PROJECT_SOURCE_DIR}/.git/hooks")
endif(EXISTS "${PROJECT_SOURCE_DIR}/tools/hooks/")
endif(EXISTS "${PROJECT_SOURCE_DIR}/.git")
configure_file(
"${PROJECT_SOURCE_DIR}/build/cmake/version.in"
"${PROJECT_SOURCE_DIR}/mpp/version.h"
)
# ----------------------------------------------------------------------------
# Build options
# ----------------------------------------------------------------------------
find_package(PkgConfig)
INCLUDE(GNUInstallDirs)
pkg_search_module(PTHREAD pthread)
# ----------------------------------------------------------------------------
# Set Warning as Error
# ----------------------------------------------------------------------------
option(WARNINGS_AS_ERRORS "Stop compiles on first warning" OFF)
if(WARNINGS_AS_ERRORS)
if(GCC)
add_definitions(-Werror)
elseif(MSVC)
add_definitions(/WX)
endif()
endif(WARNINGS_AS_ERRORS)
# ----------------------------------------------------------------------------
# look for stdint.h
# ----------------------------------------------------------------------------
if(MSVC)
check_include_files(stdint.h HAVE_STDINT_H)
if(NOT HAVE_STDINT_H)
include_directories(osal/windows)
endif(NOT HAVE_STDINT_H)
endif(MSVC)
# ----------------------------------------------------------------------------
# Share library option
# ----------------------------------------------------------------------------
option(BUILD_SHARED_LIBS "Build shared library" ON)
# ----------------------------------------------------------------------------
# scan all LOG_TAG for log information and generate module header file
# ----------------------------------------------------------------------------
set( module_list "" )
file ( GLOB_RECURSE ALL_SRC . *.c;*.cpp )
foreach( files ${ALL_SRC} )
file( STRINGS ${files} module_tag_line REGEX "MODULE_TAG( )+\".+\"" )
if(module_tag_line)
string( REGEX REPLACE "^(.)* MODULE_TAG( )+\"(.*)\"" \\3 module_tag ${module_tag_line} )
list( APPEND module_list ${module_tag} )
endif()
endforeach()
list( SORT module_list )
list( LENGTH module_list module_size )
#message(STATUS "module_list: ${module_list}")
#message(STATUS "module_size: ${module_size}")
# ----------------------------------------------------------------------------
# Start module definition
# ----------------------------------------------------------------------------
# project overall include file
include_directories(inc)
# small utile functions for test case
include_directories(utils)
# ----------------------------------------------------------------------------
# osal library
# ----------------------------------------------------------------------------
# Operation System Abstract Layer (OSAL) include
include_directories(osal/inc)
# OSAL is needed on all platform, do not need option
add_subdirectory(osal)
# ----------------------------------------------------------------------------
# utils for test case
# ----------------------------------------------------------------------------
add_subdirectory(utils)
# ----------------------------------------------------------------------------
# Media Process Platform library
# ----------------------------------------------------------------------------
# Media Process Platform include
include_directories(mpp/inc)
add_subdirectory(mpp)
# ----------------------------------------------------------------------------
# test / demo
# ----------------------------------------------------------------------------
add_subdirectory(test)
# ----------------------------------------------------------------------------
# install headers
# ----------------------------------------------------------------------------
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/inc/
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/rockchip"
FILES_MATCHING PATTERN "*.h"
)
# ----------------------------------------------------------------------------
# pkgconfig
# ----------------------------------------------------------------------------
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/rockchip_mpp.pc.cmake"
"${CMAKE_BINARY_DIR}/rockchip_mpp.pc" @ONLY)
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/rockchip_vpu.pc.cmake"
"${CMAKE_BINARY_DIR}/rockchip_vpu.pc" @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/rockchip_mpp.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
install(FILES "${CMAKE_BINARY_DIR}/rockchip_vpu.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")