-
Notifications
You must be signed in to change notification settings - Fork 68
/
CMakeLists.txt
150 lines (120 loc) · 5.25 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
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
# Cross Compile
# cmake -DCMAKE_TOOLCHAIN_FILE=cmake/aarch64-toolchain.cmake
project(BMF CXX C)
### options
if (NOT APPLE)
set(BMF_PYENV 3.7 CACHE STRING "Python version, ie. 3.6, 3.7, 3.8")
else ()
set(BMF_PYENV)
endif ()
set(BMF_ASSEMBLE_ROOT ${CMAKE_BINARY_DIR}/output CACHE STRING "Directory to assymble BMF package")
set(BMF_BUILD_VERSION "" CACHE STRING "BMF version")
set(BMF_BUILD_COMMIT "" CACHE STRING "BMF commit")
option(BMF_LOCAL_DEPENDENCIES "Build dependencies locally" ON)
option(BMF_ENABLE_BREAKPAD "Enable build with breakpad support" OFF)
option(BMF_ENABLE_CUDA "Enable CUDA support" ON)
option(BMF_ENABLE_TORCH "Enable CUDA support" OFF)
option(BMF_ENABLE_PYTHON "Enable build with python support" ON)
option(BMF_ENABLE_GLOG "Enable build with glog support" OFF)
option(BMF_ENABLE_JNI "Enable build with JNI support" OFF)
option(BMF_ENABLE_FFMPEG "Enable build with ffmpeg support" ON)
option(BMF_ENABLE_MOBILE "Enable build for mobile platform" OFF)
option(BMF_ENABLE_TEST "Compile examples and tests" ON)
option(CMAKE_EXPORT_COMPILE_COMMANDS "Export compile commands" OFF)
if (BMF_ENABLE_CUDA)
# For FindCUDAToolkit support
cmake_minimum_required(VERSION 3.17 FATAL_ERROR)
endif()
if(ENABLE_BITCODE)
set(CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE "bitcode")
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
else()
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO")
endif()
### VERSION
string(REPLACE "." ";" VERSION_LIST ${BMF_BUILD_VERSION})
list(GET VERSION_LIST 0 BMF_VERSION_MAJOR)
list(GET VERSION_LIST 1 BMF_VERSION_MINOR)
list(GET VERSION_LIST 2 BMF_VERSION_PATCH)
### general settings
if(WIN32)
set(CMAKE_CXX_STANDARD 20)
else()
set(CMAKE_CXX_STANDARD 17)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (${COVERAGE})
set(CMAKE_COVERAGE_FLAGS "-fprofile-arcs -ftest-coverage -O -g3")
else ()
set(CMAKE_COVERAGE_FLAGS " ")
endif()
if (SANITIZE STREQUAL "asan")
set(CMAKE_SANITIZER_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-sanitize-recover=all")
elseif (SANITIZE STREQUAL "ubsan")
set(CMAKE_SANITIZER_FLAGS "-fsanitize=undefined -fno-sanitize-recover=all")
else ()
set(CMAKE_SANITIZER_FLAGS " ")
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if ($ENV{SCRIPT_EXEC_MODE} MATCHES "x86")
# runpath for bmf libs
set(CMAKE_CXX_FLAGS "-D__STDC_FORMAT_MACROS -Wno-deprecated-declarations -Wl,-z,defs,-rpath,'$ORIGIN',--enable-new-dtags ${CMAKE_COVERAGE_FLAGS} ${CMAKE_SANITIZER_FLAGS} ${CMAKE_CXX_FLAGS}") # For python dist
else()
set(CMAKE_CXX_FLAGS "-D__STDC_FORMAT_MACROS -Wno-deprecated-declarations -Wl,-z,defs ${CMAKE_COVERAGE_FLAGS} ${CMAKE_SANITIZER_FLAGS} ${CMAKE_CXX_FLAGS}") #report unresolved symbols
endif()
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# C4068: unknown pragma
# C4576: a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax
# Used in FFmpeg macros which assumes C.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:preprocessor /wd4068 /wd4576")
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
if (BMF_ENABLE_CUDA)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=/Zc:preprocessor")
endif()
endif()
if(ANDROID)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Oz") # -O2 + -Oz
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
endif()
if(WIN32)
# archive
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BMF_ASSEMBLE_ROOT}/bmf/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${BMF_ASSEMBLE_ROOT}/bmf/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${BMF_ASSEMBLE_ROOT}/bmf/lib)
# library
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BMF_ASSEMBLE_ROOT}/bmf/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${BMF_ASSEMBLE_ROOT}/bmf/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${BMF_ASSEMBLE_ROOT}/bmf/lib)
# binary
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BMF_ASSEMBLE_ROOT}/bmf/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${BMF_ASSEMBLE_ROOT}/bmf/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${BMF_ASSEMBLE_ROOT}/bmf/bin)
else()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BMF_ASSEMBLE_ROOT}/bmf/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BMF_ASSEMBLE_ROOT}/bmf/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BMF_ASSEMBLE_ROOT}/bmf/bin)
endif()
if (EMSCRIPTEN)
# Add some flags for wasm
# -fPIC , USE_PTHREADS, SHARED_MEMORY for dynamic linking
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fPIC -s USE_PTHREADS=1 -s SHARED_MEMORY=1")
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
endif()
### dependencies
if(NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS TRUE) #build shared sdk by default
endif()
include(cmake/dependencies.cmake)
if(BMF_USE_MEDIACODEC)
add_definitions("-DBMF_USE_MEDIACODEC")
endif()
###
add_subdirectory(bmf)
## set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGSa} -Wl,--export-dynamic")
### print build configurations
include(cmake/summary.cmake)