-
Notifications
You must be signed in to change notification settings - Fork 8
/
audio_codec_common.cmake
176 lines (155 loc) · 6.58 KB
/
audio_codec_common.cmake
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
# If platform is Emscripten
if(${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
set(EMSCRIPTEN 1)
endif()
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
# Warning flags macros
macro(ac_add_c_warning_flag WARNINGFLAG WARNING_VAR)
check_c_compiler_flag("-W${WARNINGFLAG}" HAVE_CW_${WARNING_VAR})
if(HAVE_CW_${WARNING_VAR})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W${WARNINGFLAG}")
endif()
endmacro()
macro(ac_add_cxx_warning_flag WARNINGFLAG WARNING_VAR)
check_cxx_compiler_flag("-W${WARNINGFLAG}" HAVE_CXXW_${WARNING_VAR})
if(HAVE_CXXW_${WARNING_VAR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W${WARNINGFLAG}")
endif()
endmacro()
macro(ac_disable_c_warning_flag WARNINGFLAG WARNING_VAR)
check_c_compiler_flag("-W${WARNINGFLAG}" HAVE_CW_${WARNING_VAR})
if(HAVE_CW_${WARNING_VAR})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-${WARNINGFLAG}")
endif()
endmacro()
macro(ac_disable_cxx_warning_flag WARNINGFLAG WARNING_VAR)
check_cxx_compiler_flag("-W${WARNINGFLAG}" HAVE_CXXW_${WARNING_VAR})
if(HAVE_CXXW_${WARNING_VAR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-${WARNINGFLAG}")
endif()
endmacro()
# Add compiler argument(s)
macro(ac_add_opt_flag COMPILERFLAG COMPILERFLAG_VAR)
check_c_compiler_flag("${COMPILERFLAG}" HAVE_C_${COMPILERFLAG_VAR})
if(HAVE_C_${COMPILERFLAG_VAR})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILERFLAG}")
endif()
check_cxx_compiler_flag("${COMPILERFLAG}" HAVE_CXX_${COMPILERFLAG_VAR})
if(HAVE_CXX_${COMPILERFLAG_VAR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILERFLAG}")
endif()
endmacro()
macro(ac_add_c_compiler_flag COMPILERFLAG COMPILERFLAG_VAR)
check_c_compiler_flag("${COMPILERFLAG}" HAVE_C_${COMPILERFLAG_VAR})
if(HAVE_C_${COMPILERFLAG_VAR})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILERFLAG}")
endif()
endmacro()
macro(ac_add_cxx_compiler_flag COMPILERFLAG COMPILERFLAG_VAR)
check_cxx_compiler_flag("${COMPILERFLAG}" HAVE_CXX_${COMPILERFLAG_VAR})
if(HAVE_CXX_${COMPILERFLAG_VAR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILERFLAG}")
endif()
endmacro()
# Strip garbage
if(APPLE)
string(REGEX REPLACE "-O3" ""
CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REGEX REPLACE "-O3" ""
CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
set(LINK_FLAGS_RELEASE "${LINK_FLAGS_RELEASE} -dead_strip")
# Unify visibility to meet llvm's default (C++-only)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG)
if(SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden")
endif()
elseif(NOT MSVC)
if(EMSCRIPTEN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_SDL=0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_SDL=0")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Os -fdata-sections -ffunction-sections")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os -fdata-sections -ffunction-sections")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(LINK_FLAGS_RELEASE "${LINK_FLAGS_RELEASE} -dead_strip")
else()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wl,--gc-sections -Wl,-s")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wl,--gc-sections -Wl,-s")
set(LINK_FLAGS_RELEASE "${LINK_FLAGS_RELEASE} -Wl,--gc-sections -Wl,-s")
endif()
else()
string(REGEX REPLACE "-O3" ""
CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REGEX REPLACE "-O3" ""
CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -fdata-sections -ffunction-sections")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fdata-sections -ffunction-sections")
if(ANDROID)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -funwind-tables")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -funwind-tables")
elseif(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s -Wl,--gc-sections -Wl,-s")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s -Wl,--gc-sections -Wl,-s")
set(LINK_FLAGS_RELEASE "${LINK_FLAGS_RELEASE} -Wl,--gc-sections -Wl,-s")
else()
set(LINK_FLAGS_RELEASE "${LINK_FLAGS_RELEASE} -dead_strip")
endif()
endif()
endif()
# Global optimization flags
if(NOT MSVC)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-omit-frame-pointer")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
if(MSVC)
# Force to always compile with W4
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
endif()
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
if(NOT NOPEDANTIC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic")
endif()
endif()
# Disable bogus MSVC warnings
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
# -fPIC thing
if(ENABLE_FPIC AND NOT WIN32 AND NOT VITA)
message("== -fPIC enabled")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
# Prevent shared libraries has "lib" prefix on Windows DLL files
if(WIN32)
set(CMAKE_SHARED_LIBRARY_PREFIX "")
endif()
if(DISABLE_SIMD)
if(NOT AUDIO_CODECS_KEEP_SSE)
ac_add_opt_flag("-mno-sse" NO_SSE)
endif()
ac_add_opt_flag("-mno-sse2" NO_SSE2)
ac_add_opt_flag("-mno-sse3" NO_SSE3)
ac_add_opt_flag("-mno-ssse3" NO_SSSE3)
ac_add_opt_flag("-mno-sse4.1" NO_SSE41)
ac_add_opt_flag("-mno-sse4.2" NO_SSE42)
ac_add_opt_flag("-mno-avx" NO_AVX)
ac_add_opt_flag("-mno-avx2" NO_AVX2)
ac_add_opt_flag("-mno-avx512f" NO_AVX512F)
endif()