blob: a28f441c0dc8aee44cf5c02ad37094f07a70ed64 [file] [log] [blame]
Marcus Asteborgf9d3d432018-11-15 19:48:38 -08001cmake_minimum_required(VERSION 3.1)
Marcus Asteborga0e14e72020-04-13 15:51:48 -07002list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Marcus Asteborgf9d3d432018-11-15 19:48:38 -08003
Marcus Asteborg8ad827c2020-06-24 21:25:57 -07004include(OpusPackageVersion)
5get_package_version(PACKAGE_VERSION PROJECT_VERSION)
Marcus Asteborgf9d3d432018-11-15 19:48:38 -08006
7project(Opus LANGUAGES C VERSION ${PROJECT_VERSION})
Marcus Asteborg87cdaae2020-06-04 17:35:13 -07008
Marcus Asteborg8ad827c2020-06-24 21:25:57 -07009include(OpusFunctions)
Marcus Asteborg48055cc2020-04-22 22:06:11 -070010include(OpusBuildtype)
Marcus Asteborg48055cc2020-04-22 22:06:11 -070011include(OpusConfig)
12include(OpusSources)
Marcus Asteborgf9d3d432018-11-15 19:48:38 -080013include(GNUInstallDirs)
14include(CMakeDependentOption)
15include(FeatureSummary)
16
Marcus Asteborg87cdaae2020-06-04 17:35:13 -070017set(OPUS_BUILD_SHARED_LIBRARY_HELP_STR "build shared library.")
18option(OPUS_BUILD_SHARED_LIBRARY ${OPUS_BUILD_SHARED_LIBRARY_HELP_STR} OFF)
Simon Jacksonb2547012020-04-15 17:58:55 +010019if(OPUS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS OR OPUS_BUILD_FRAMEWORK)
Davide Beatricic487f532019-10-01 06:08:04 +020020 # Global flag to cause add_library() to create shared libraries if on.
21 set(BUILD_SHARED_LIBS ON)
Marcus Asteborg965a72e2019-12-17 10:21:21 -080022 set(OPUS_BUILD_SHARED_LIBRARY ON)
Davide Beatricic487f532019-10-01 06:08:04 +020023endif()
Marcus Asteborg87cdaae2020-06-04 17:35:13 -070024add_feature_info(OPUS_BUILD_SHARED_LIBRARY OPUS_BUILD_SHARED_LIBRARY ${OPUS_BUILD_SHARED_LIBRARY_HELP_STR})
Davide Beatricic487f532019-10-01 06:08:04 +020025
Marcus Asteborg87cdaae2020-06-04 17:35:13 -070026set(OPUS_BUILD_TESTING_HELP_STR "build tests.")
27option(OPUS_BUILD_TESTING ${OPUS_BUILD_TESTING_HELP_STR} OFF)
Marcus Asteborgc401f212020-03-13 15:51:10 -070028if(OPUS_BUILD_TESTING OR BUILD_TESTING)
29 set(OPUS_BUILD_TESTING ON)
30 set(BUILD_TESTING ON)
31endif()
Marcus Asteborg87cdaae2020-06-04 17:35:13 -070032add_feature_info(OPUS_BUILD_TESTING OPUS_BUILD_TESTING ${OPUS_BUILD_TESTING_HELP_STR})
33
34set(OPUS_CUSTOM_MODES_HELP_STR "enable non-Opus modes, e.g. 44.1 kHz & 2^n frames.")
35option(OPUS_CUSTOM_MODES ${OPUS_CUSTOM_MODES_HELP_STR} OFF)
36add_feature_info(OPUS_CUSTOM_MODES OPUS_CUSTOM_MODES ${OPUS_CUSTOM_MODES_HELP_STR})
37
38set(OPUS_BUILD_PROGRAMS_HELP_STR "build programs.")
39option(OPUS_BUILD_PROGRAMS ${OPUS_BUILD_PROGRAMS_HELP_STR} OFF)
40add_feature_info(OPUS_BUILD_PROGRAMS OPUS_BUILD_PROGRAMS ${OPUS_BUILD_PROGRAMS_HELP_STR})
41
42set(OPUS_DISABLE_INTRINSICS_HELP_STR "disable all intrinsics optimizations.")
43option(OPUS_DISABLE_INTRINSICS ${OPUS_DISABLE_INTRINSICS_HELP_STR} OFF)
44add_feature_info(OPUS_DISABLE_INTRINSICS OPUS_DISABLE_INTRINSICS ${OPUS_DISABLE_INTRINSICS_HELP_STR})
45
46set(OPUS_FIXED_POINT_HELP_STR "compile as fixed-point (for machines without a fast enough FPU).")
47option(OPUS_FIXED_POINT ${OPUS_FIXED_POINT_HELP_STR} OFF)
48add_feature_info(OPUS_FIXED_POINT OPUS_FIXED_POINT ${OPUS_FIXED_POINT_HELP_STR})
49
50set(OPUS_ENABLE_FLOAT_API_HELP_STR "compile with the floating point API (for machines with float library).")
51option(OPUS_ENABLE_FLOAT_API ${OPUS_ENABLE_FLOAT_API_HELP_STR} ON)
Marcus Asteborg5edb5aa2020-07-12 21:03:34 -070052add_feature_info(OPUS_ENABLE_FLOAT_API OPUS_ENABLE_FLOAT_API ${OPUS_ENABLE_FLOAT_API_HELP_STR})
Marcus Asteborg87cdaae2020-06-04 17:35:13 -070053
54set(OPUS_FLOAT_APPROX_HELP_STR "enable floating point approximations (Ensure your platform supports IEEE 754 before enabling).")
55option(OPUS_FLOAT_APPROX ${OPUS_FLOAT_APPROX_HELP_STR} OFF)
56add_feature_info(OPUS_FLOAT_APPROX OPUS_FLOAT_APPROX ${OPUS_FLOAT_APPROX_HELP_STR})
57
Marcus Asteborg1d5c8152020-11-20 21:12:56 -080058set(OPUS_ASSERTIONS_HELP_STR "additional software error checking.")
59option(OPUS_ASSERTIONS ${OPUS_ASSERTIONS_HELP_STR} OFF)
60add_feature_info(OPUS_ASSERTIONS OPUS_ASSERTIONS ${OPUS_ASSERTIONS_HELP_STR})
61
Marcus Asteborgb459e4c2020-11-20 21:22:48 -080062set(OPUS_HARDENING_HELP_STR "run-time checks that are cheap and safe for use in production.")
63option(OPUS_HARDENING ${OPUS_HARDENING_HELP_STR} ON)
64add_feature_info(OPUS_HARDENING OPUS_HARDENING ${OPUS_HARDENING_HELP_STR})
65
Marcus Asteborg2f37feb2020-11-20 21:28:56 -080066set(OPUS_FUZZING_HELP_STR "causes the encoder to make random decisions (do not use in production).")
67option(OPUS_FUZZING ${OPUS_FUZZING_HELP_STR} OFF)
68add_feature_info(OPUS_FUZZING OPUS_FUZZING ${OPUS_FUZZING_HELP_STR})
69
Marcus Asteborg5bdb3a52020-11-20 21:38:21 -080070set(OPUS_CHECK_ASM_HELP_STR "enable bit-exactness checks between optimized and c implementations.")
71option(OPUS_CHECK_ASM ${OPUS_CHECK_ASM_HELP_STR} OFF)
72add_feature_info(OPUS_CHECK_ASM OPUS_CHECK_ASM ${OPUS_CHECK_ASM_HELP_STR})
73
Marcus Asteborg87cdaae2020-06-04 17:35:13 -070074set(OPUS_INSTALL_PKG_CONFIG_MODULE_HELP_STR "install pkg-config module.")
75option(OPUS_INSTALL_PKG_CONFIG_MODULE ${OPUS_INSTALL_PKG_CONFIG_MODULE_HELP_STR} ON)
76add_feature_info(OPUS_INSTALL_PKG_CONFIG_MODULE OPUS_INSTALL_PKG_CONFIG_MODULE ${OPUS_INSTALL_PKG_CONFIG_MODULE_HELP_STR})
77
78set(OPUS_INSTALL_CMAKE_CONFIG_MODULE_HELP_STR "install CMake package config module.")
79option(OPUS_INSTALL_CMAKE_CONFIG_MODULE ${OPUS_INSTALL_CMAKE_CONFIG_MODULE_HELP_STR} ON)
80add_feature_info(OPUS_INSTALL_CMAKE_CONFIG_MODULE OPUS_INSTALL_CMAKE_CONFIG_MODULE ${OPUS_INSTALL_CMAKE_CONFIG_MODULE_HELP_STR})
81
82if(APPLE)
83 set(OPUS_BUILD_FRAMEWORK_HELP_STR "build Framework bundle for Apple systems.")
84 option(OPUS_BUILD_FRAMEWORK ${OPUS_BUILD_FRAMEWORK_HELP_STR} OFF)
85 add_feature_info(OPUS_BUILD_FRAMEWORK OPUS_BUILD_FRAMEWORK ${OPUS_BUILD_FRAMEWORK_HELP_STR})
86endif()
87
Marcus Asteborg841d57b2020-07-31 22:17:49 -070088set(OPUS_FIXED_POINT_DEBUG_HELP_STR "debug fixed-point implementation.")
89cmake_dependent_option(OPUS_FIXED_POINT_DEBUG
90 ${OPUS_FIXED_POINT_DEBUG_HELP_STR}
91 ON
92 "OPUS_FIXED_POINT; OPUS_FIXED_POINT_DEBUG"
93 OFF)
94add_feature_info(OPUS_FIXED_POINT_DEBUG OPUS_FIXED_POINT_DEBUG ${OPUS_FIXED_POINT_DEBUG_HELP_STR})
95
Marcus Asteborg87cdaae2020-06-04 17:35:13 -070096set(OPUS_VAR_ARRAYS_HELP_STR "use variable length arrays for stack arrays.")
97cmake_dependent_option(OPUS_VAR_ARRAYS
98 ${OPUS_VAR_ARRAYS_HELP_STR}
99 ON
100 "VLA_SUPPORTED; NOT OPUS_USE_ALLOCA; NOT OPUS_NONTHREADSAFE_PSEUDOSTACK"
101 OFF)
102add_feature_info(OPUS_VAR_ARRAYS OPUS_VAR_ARRAYS ${OPUS_VAR_ARRAYS_HELP_STR})
103
104set(OPUS_USE_ALLOCA_HELP_STR "use alloca for stack arrays (on non-C99 compilers).")
105cmake_dependent_option(OPUS_USE_ALLOCA
106 ${OPUS_USE_ALLOCA_HELP_STR}
107 ON
108 "USE_ALLOCA_SUPPORTED; NOT OPUS_VAR_ARRAYS; NOT OPUS_NONTHREADSAFE_PSEUDOSTACK"
109 OFF)
110add_feature_info(OPUS_USE_ALLOCA OPUS_USE_ALLOCA ${OPUS_USE_ALLOCA_HELP_STR})
111
112set(OPUS_NONTHREADSAFE_PSEUDOSTACK_HELP_STR "use a non threadsafe pseudostack when neither variable length arrays or alloca is supported.")
113cmake_dependent_option(OPUS_NONTHREADSAFE_PSEUDOSTACK
114 ${OPUS_NONTHREADSAFE_PSEUDOSTACK_HELP_STR}
115 ON
116 "NOT OPUS_VAR_ARRAYS; NOT OPUS_USE_ALLOCA"
117 OFF)
118add_feature_info(OPUS_NONTHREADSAFE_PSEUDOSTACK OPUS_NONTHREADSAFE_PSEUDOSTACK ${OPUS_NONTHREADSAFE_PSEUDOSTACK_HELP_STR})
119
120set(OPUS_FAST_MATH_HELP_STR "enable fast math (unsupported and discouraged use, as code is not well tested with this build option).")
121cmake_dependent_option(OPUS_FAST_MATH
122 ${OPUS_FAST_MATH_HELP_STR}
123 ON
124 "OPUS_FLOAT_APPROX; OPUS_FAST_MATH; FAST_MATH_SUPPORTED"
125 OFF)
126add_feature_info(OPUS_FAST_MATH OPUS_FAST_MATH ${OPUS_FAST_MATH_HELP_STR})
127
128set(OPUS_STACK_PROTECTOR_HELP_STR "use stack protection.")
129cmake_dependent_option(OPUS_STACK_PROTECTOR
130 ${OPUS_STACK_PROTECTOR_HELP_STR}
131 ON
132 "STACK_PROTECTOR_SUPPORTED"
133 OFF)
134add_feature_info(OPUS_STACK_PROTECTOR OPUS_STACK_PROTECTOR ${OPUS_STACK_PROTECTOR_HELP_STR})
Marcus Asteborgc401f212020-03-13 15:51:10 -0700135
Marcus Asteborgb83dd522020-07-16 22:40:08 -0700136if(NOT MSVC)
137 set(OPUS_FORTIFY_SOURCE_HELP_STR "add protection against buffer overflows.")
138 cmake_dependent_option(OPUS_FORTIFY_SOURCE
139 ${OPUS_FORTIFY_SOURCE_HELP_STR}
140 ON
141 "FORTIFY_SOURCE_SUPPORTED"
142 OFF)
143 add_feature_info(OPUS_FORTIFY_SOURCE OPUS_FORTIFY_SOURCE ${OPUS_FORTIFY_SOURCE_HELP_STR})
144endif()
145
146if(MINGW AND (OPUS_FORTIFY_SOURCE OR OPUS_STACK_PROTECTOR))
147 # ssp lib is needed for security features for MINGW
148 list(APPEND OPUS_REQUIRED_LIBRARIES ssp)
Zeno Endemannd4b87072020-07-15 21:45:42 +0200149endif()
150
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800151if(OPUS_CPU_X86 OR OPUS_CPU_X64)
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700152 set(OPUS_X86_MAY_HAVE_SSE_HELP_STR "does runtime check for SSE1 support.")
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800153 cmake_dependent_option(OPUS_X86_MAY_HAVE_SSE
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700154 ${OPUS_X86_MAY_HAVE_SSE_HELP_STR}
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800155 ON
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700156 "SSE1_SUPPORTED; NOT OPUS_DISABLE_INTRINSICS"
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800157 OFF)
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700158 add_feature_info(OPUS_X86_MAY_HAVE_SSE OPUS_X86_MAY_HAVE_SSE ${OPUS_X86_MAY_HAVE_SSE_HELP_STR})
159
160 set(OPUS_X86_MAY_HAVE_SSE2_HELP_STR "does runtime check for SSE2 support.")
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800161 cmake_dependent_option(OPUS_X86_MAY_HAVE_SSE2
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700162 ${OPUS_X86_MAY_HAVE_SSE2_HELP_STR}
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800163 ON
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700164 "SSE2_SUPPORTED; NOT OPUS_DISABLE_INTRINSICS"
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800165 OFF)
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700166 add_feature_info(OPUS_X86_MAY_HAVE_SSE2 OPUS_X86_MAY_HAVE_SSE2 ${OPUS_X86_MAY_HAVE_SSE2_HELP_STR})
167
168 set(OPUS_X86_MAY_HAVE_SSE4_1_HELP_STR "does runtime check for SSE4.1 support.")
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800169 cmake_dependent_option(OPUS_X86_MAY_HAVE_SSE4_1
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700170 ${OPUS_X86_MAY_HAVE_SSE4_1_HELP_STR}
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800171 ON
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700172 "SSE4_1_SUPPORTED; NOT OPUS_DISABLE_INTRINSICS"
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800173 OFF)
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700174 add_feature_info(OPUS_X86_MAY_HAVE_SSE4_1 OPUS_X86_MAY_HAVE_SSE4_1 ${OPUS_X86_MAY_HAVE_SSE4_1_HELP_STR})
175
176 set(OPUS_X86_MAY_HAVE_AVX_HELP_STR "does runtime check for AVX support.")
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800177 cmake_dependent_option(OPUS_X86_MAY_HAVE_AVX
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700178 ${OPUS_X86_MAY_HAVE_AVX_HELP_STR}
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800179 ON
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700180 "AVX_SUPPORTED; NOT OPUS_DISABLE_INTRINSICS"
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800181 OFF)
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700182 add_feature_info(OPUS_X86_MAY_HAVE_AVX OPUS_X86_MAY_HAVE_AVX ${OPUS_X86_MAY_HAVE_AVX_HELP_STR})
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800183
Marcus Asteborg927de842020-03-13 13:31:29 -0700184 # PRESUME depends on MAY HAVE, but PRESUME will override runtime detection
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700185 set(OPUS_X86_PRESUME_SSE_HELP_STR "assume target CPU has SSE1 support (override runtime check).")
186 set(OPUS_X86_PRESUME_SSE2_HELP_STR "assume target CPU has SSE2 support (override runtime check).")
187 if(OPUS_CPU_X64) # Assume x86_64 has up to SSE2 support
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800188 cmake_dependent_option(OPUS_X86_PRESUME_SSE
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700189 ${OPUS_X86_PRESUME_SSE_HELP_STR}
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800190 ON
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700191 "OPUS_X86_MAY_HAVE_SSE; NOT OPUS_DISABLE_INTRINSICS"
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800192 OFF)
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700193
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800194 cmake_dependent_option(OPUS_X86_PRESUME_SSE2
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700195 ${OPUS_X86_PRESUME_SSE2_HELP_STR}
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800196 ON
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700197 "OPUS_X86_MAY_HAVE_SSE2; NOT OPUS_DISABLE_INTRINSICS"
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800198 OFF)
199 else()
200 cmake_dependent_option(OPUS_X86_PRESUME_SSE
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700201 ${OPUS_X86_PRESUME_SSE_HELP_STR}
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800202 OFF
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700203 "OPUS_X86_MAY_HAVE_SSE; NOT OPUS_DISABLE_INTRINSICS"
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800204 OFF)
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700205
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800206 cmake_dependent_option(OPUS_X86_PRESUME_SSE2
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700207 ${OPUS_X86_PRESUME_SSE2_HELP_STR}
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800208 OFF
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700209 "OPUS_X86_MAY_HAVE_SSE2; NOT OPUS_DISABLE_INTRINSICS"
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800210 OFF)
211 endif()
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700212 add_feature_info(OPUS_X86_PRESUME_SSE OPUS_X86_PRESUME_SSE ${OPUS_X86_PRESUME_SSE_HELP_STR})
213 add_feature_info(OPUS_X86_PRESUME_SSE2 OPUS_X86_PRESUME_SSE2 ${OPUS_X86_PRESUME_SSE2_HELP_STR})
214
215 set(OPUS_X86_PRESUME_SSE4_1_HELP_STR "assume target CPU has SSE4.1 support (override runtime check).")
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800216 cmake_dependent_option(OPUS_X86_PRESUME_SSE4_1
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700217 ${OPUS_X86_PRESUME_SSE4_1_HELP_STR}
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800218 OFF
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700219 "OPUS_X86_MAY_HAVE_SSE4_1; NOT OPUS_DISABLE_INTRINSICS"
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800220 OFF)
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700221 add_feature_info(OPUS_X86_PRESUME_SSE4_1 OPUS_X86_PRESUME_SSE4_1 ${OPUS_X86_PRESUME_SSE4_1_HELP_STR})
222
223 set(OPUS_X86_PRESUME_AVX_HELP_STR "assume target CPU has AVX support (override runtime check).")
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800224 cmake_dependent_option(OPUS_X86_PRESUME_AVX
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700225 ${OPUS_X86_PRESUME_AVX_HELP_STR}
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800226 OFF
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700227 "OPUS_X86_MAY_HAVE_AVX; NOT OPUS_DISABLE_INTRINSICS"
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800228 OFF)
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700229 add_feature_info(OPUS_X86_PRESUME_AVX OPUS_X86_PRESUME_AVX ${OPUS_X86_PRESUME_AVX_HELP_STR})
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800230endif()
231
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700232feature_summary(WHAT ALL)
233
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800234set_package_properties(Git
235 PROPERTIES
236 TYPE
237 REQUIRED
238 DESCRIPTION
239 "fast, scalable, distributed revision control system"
240 URL
241 "https://git-scm.com/"
242 PURPOSE
243 "required to set up package version")
244
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800245set(Opus_PUBLIC_HEADER
246 ${CMAKE_CURRENT_SOURCE_DIR}/include/opus.h
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800247 ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_defines.h
248 ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_multistream.h
249 ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_projection.h
250 ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_types.h)
251
Marcus Asteborgf2f8f332020-04-22 20:29:37 -0700252if(OPUS_CUSTOM_MODES)
253 list(APPEND Opus_PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_custom.h)
254endif()
255
Marcus Asteborg7f011832020-04-22 20:17:57 -0700256add_library(opus ${opus_headers} ${opus_sources} ${opus_sources_float} ${Opus_PUBLIC_HEADER})
Simon Jacksonb2547012020-04-15 17:58:55 +0100257add_library(Opus::opus ALIAS opus)
258
Marcus Asteborg8ad827c2020-06-24 21:25:57 -0700259get_library_version(OPUS_LIBRARY_VERSION OPUS_LIBRARY_VERSION_MAJOR)
Marcus Asteborg93fe3452020-08-28 16:17:50 -0700260message(DEBUG "Opus library version: ${OPUS_LIBRARY_VERSION}")
Marcus Asteborg8ad827c2020-06-24 21:25:57 -0700261
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800262set_target_properties(opus
263 PROPERTIES SOVERSION
264 ${OPUS_LIBRARY_VERSION_MAJOR}
265 VERSION
266 ${OPUS_LIBRARY_VERSION}
267 PUBLIC_HEADER
268 "${Opus_PUBLIC_HEADER}")
269
270target_include_directories(
271 opus
272 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
273 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
evpobrd637b902020-01-26 18:11:01 +0500274 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/opus>
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800275 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
276 ${CMAKE_CURRENT_SOURCE_DIR}
277 celt
278 silk)
279
280target_link_libraries(opus PRIVATE ${OPUS_REQUIRED_LIBRARIES})
Marcus Asteborgb459e4c2020-11-20 21:22:48 -0800281target_compile_definitions(opus PRIVATE OPUS_BUILD)
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800282
Marcus Asteborg841d57b2020-07-31 22:17:49 -0700283if(OPUS_FIXED_POINT_DEBUG)
284 target_compile_definitions(opus PRIVATE FIXED_DEBUG)
285endif()
286
Marcus Asteborgb83dd522020-07-16 22:40:08 -0700287if(OPUS_FORTIFY_SOURCE AND NOT MSVC)
288 target_compile_definitions(opus PRIVATE
289 $<$<NOT:$<CONFIG:debug>>:_FORTIFY_SOURCE=2>)
Marcus Asteborg268780f2019-04-10 16:34:01 -0700290endif()
291
Marcus Asteborgc5c986a2020-04-13 15:59:50 -0700292if(OPUS_FLOAT_APPROX)
293 target_compile_definitions(opus PRIVATE FLOAT_APPROX)
294endif()
295
Marcus Asteborg1d5c8152020-11-20 21:12:56 -0800296if(OPUS_ASSERTIONS)
297 target_compile_definitions(opus PRIVATE ENABLE_ASSERTIONS)
298endif()
299
Marcus Asteborgb459e4c2020-11-20 21:22:48 -0800300if(OPUS_HARDENING)
301 target_compile_definitions(opus PRIVATE ENABLE_HARDENING)
302endif()
303
Marcus Asteborg2f37feb2020-11-20 21:28:56 -0800304if(OPUS_FUZZING)
305 target_compile_definitions(opus PRIVATE FUZZING)
306endif()
307
Marcus Asteborg5bdb3a52020-11-20 21:38:21 -0800308if(OPUS_CHECK_ASM)
309 target_compile_definitions(opus PRIVATE OPUS_CHECK_ASM)
310endif()
311
Marcus Asteborga0e14e72020-04-13 15:51:48 -0700312if(OPUS_VAR_ARRAYS)
Marcus Asteborg268780f2019-04-10 16:34:01 -0700313 target_compile_definitions(opus PRIVATE VAR_ARRAYS)
Marcus Asteborga0e14e72020-04-13 15:51:48 -0700314elseif(OPUS_USE_ALLOCA)
315 target_compile_definitions(opus PRIVATE USE_ALLOCA)
316elseif(OPUS_NONTHREADSAFE_PSEUDOSTACK)
317 target_compile_definitions(opus PRIVATE NONTHREADSAFE_PSEUDOSTACK)
318else()
Marcus Asteborg87cdaae2020-06-04 17:35:13 -0700319 message(ERROR "Need to set a define for stack allocation")
Marcus Asteborg268780f2019-04-10 16:34:01 -0700320endif()
321
322if(OPUS_CUSTOM_MODES)
323 target_compile_definitions(opus PRIVATE CUSTOM_MODES)
324endif()
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800325
Marcus Asteborgc350cec2020-04-27 08:52:57 -0700326if(OPUS_FAST_MATH)
327 if(MSVC)
328 target_compile_options(opus PRIVATE /fp:fast)
329 else()
330 target_compile_options(opus PRIVATE -ffast-math)
331 endif()
332endif()
333
334if(OPUS_STACK_PROTECTOR)
335 if(MSVC)
336 target_compile_options(opus PRIVATE /GS)
337 else()
338 target_compile_options(opus PRIVATE -fstack-protector-strong)
339 endif()
340elseif(STACK_PROTECTOR_DISABLED_SUPPORTED)
341 target_compile_options(opus PRIVATE /GS-)
342endif()
343
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800344if(BUILD_SHARED_LIBS)
345 if(WIN32)
346 target_compile_definitions(opus PRIVATE DLL_EXPORT)
Marcus Asteborgc350cec2020-04-27 08:52:57 -0700347 elseif(HIDDEN_VISIBILITY_SUPPORTED)
348 set_target_properties(opus PROPERTIES C_VISIBILITY_PRESET hidden)
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800349 endif()
350endif()
351
Marcus Asteborg7f011832020-04-22 20:17:57 -0700352add_sources_group(opus silk ${silk_headers} ${silk_sources})
353add_sources_group(opus celt ${celt_headers} ${celt_sources})
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800354
355if(OPUS_FIXED_POINT)
356 add_sources_group(opus silk ${silk_sources_fixed})
357 target_include_directories(opus PRIVATE silk/fixed)
358 target_compile_definitions(opus PRIVATE FIXED_POINT=1)
359else()
360 add_sources_group(opus silk ${silk_sources_float})
361 target_include_directories(opus PRIVATE silk/float)
362endif()
363
364if(NOT OPUS_ENABLE_FLOAT_API)
365 target_compile_definitions(opus PRIVATE DISABLE_FLOAT_API)
366endif()
367
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700368if(NOT OPUS_DISABLE_INTRINSICS)
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700369 if((OPUS_X86_MAY_HAVE_SSE AND NOT OPUS_X86_PRESUME_SSE) OR
370 (OPUS_X86_MAY_HAVE_SSE2 AND NOT OPUS_X86_PRESUME_SSE2) OR
371 (OPUS_X86_MAY_HAVE_SSE4_1 AND NOT OPUS_X86_PRESUME_SSE4_1) OR
372 (OPUS_X86_MAY_HAVE_AVX AND NOT OPUS_X86_PRESUME_AVX))
373 target_compile_definitions(opus PRIVATE OPUS_HAVE_RTCD)
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800374 endif()
Marcus Asteborg927de842020-03-13 13:31:29 -0700375
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700376 if(SSE1_SUPPORTED)
377 if(OPUS_X86_MAY_HAVE_SSE)
378 add_sources_group(opus celt ${celt_sources_sse})
379 target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_SSE)
Marcus Asteborg927de842020-03-13 13:31:29 -0700380 if(NOT MSVC)
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700381 set_source_files_properties(${celt_sources_sse} PROPERTIES COMPILE_FLAGS -msse)
382 endif()
383 endif()
384 if(OPUS_X86_PRESUME_SSE)
385 target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_SSE)
386 if(NOT MSVC)
387 target_compile_options(opus PRIVATE -msse)
Marcus Asteborg927de842020-03-13 13:31:29 -0700388 endif()
389 endif()
390 endif()
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700391
392 if(SSE2_SUPPORTED)
393 if(OPUS_X86_MAY_HAVE_SSE2)
394 add_sources_group(opus celt ${celt_sources_sse2})
395 target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_SSE2)
396 if(NOT MSVC)
397 set_source_files_properties(${celt_sources_sse2} PROPERTIES COMPILE_FLAGS -msse2)
398 endif()
399 endif()
400 if(OPUS_X86_PRESUME_SSE2)
401 target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_SSE2)
402 if(NOT MSVC)
403 target_compile_options(opus PRIVATE -msse2)
404 endif()
Marcus Asteborg927de842020-03-13 13:31:29 -0700405 endif()
406 endif()
Marcus Asteborg927de842020-03-13 13:31:29 -0700407
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700408 if(SSE4_1_SUPPORTED)
409 if(OPUS_X86_MAY_HAVE_SSE4_1)
410 add_sources_group(opus celt ${celt_sources_sse4_1})
411 add_sources_group(opus silk ${silk_sources_sse4_1})
412 target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_SSE4_1)
413 if(NOT MSVC)
414 set_source_files_properties(${celt_sources_sse4_1} ${silk_sources_sse4_1} PROPERTIES COMPILE_FLAGS -msse4.1)
415 endif()
416
417 if(OPUS_FIXED_POINT)
418 add_sources_group(opus silk ${silk_sources_fixed_sse4_1})
419 if(NOT MSVC)
420 set_source_files_properties(${silk_sources_fixed_sse4_1} PROPERTIES COMPILE_FLAGS -msse4.1)
421 endif()
422 endif()
423 endif()
424 if(OPUS_X86_PRESUME_SSE4_1)
425 target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_SSE4_1)
426 if(NOT MSVC)
427 target_compile_options(opus PRIVATE -msse4.1)
428 endif()
Marcus Asteborg927de842020-03-13 13:31:29 -0700429 endif()
430 endif()
Marcus Asteborg927de842020-03-13 13:31:29 -0700431
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700432 if(AVX_SUPPORTED)
433 # mostly placeholder in case of avx intrinsics is added
434 if(OPUS_X86_MAY_HAVE_AVX)
435 target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_AVX)
436 endif()
437 if(OPUS_X86_PRESUME_AVX)
438 target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_AVX)
439 if(NOT MSVC)
440 target_compile_options(opus PRIVATE -mavx)
441 endif()
Marcus Asteborg927de842020-03-13 13:31:29 -0700442 endif()
443 endif()
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800444
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700445 if(MSVC)
446 if(AVX_SUPPORTED AND OPUS_X86_PRESUME_AVX) # on 64 bit and 32 bits
447 add_definitions(/arch:AVX)
448 elseif(OPUS_CPU_X86) # if AVX not supported then set SSE flag
449 if((SSE4_1_SUPPORTED AND OPUS_X86_PRESUME_SSE4_1)
450 OR (SSE2_SUPPORTED AND OPUS_X86_PRESUME_SSE2))
451 target_compile_definitions(opus PRIVATE /arch:SSE2)
452 elseif(SSE1_SUPPORTED AND OPUS_X86_PRESUME_SSE)
453 target_compile_definitions(opus PRIVATE /arch:SSE)
454 endif()
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800455 endif()
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800456 endif()
457
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700458 if(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm|aarch64)")
459 add_sources_group(opus celt ${celt_sources_arm})
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800460 endif()
461
Marcus Asteborg97fca1b2020-04-27 12:19:59 -0700462 if(COMPILER_SUPPORT_NEON)
463 if(OPUS_MAY_HAVE_NEON)
464 if(RUNTIME_CPU_CAPABILITY_DETECTION)
465 message(STATUS "OPUS_MAY_HAVE_NEON enabling runtime detection")
466 target_compile_definitions(opus PRIVATE OPUS_HAVE_RTCD)
467 else()
468 message(ERROR "Runtime cpu capability detection needed for MAY_HAVE_NEON")
469 endif()
470 # Do runtime check for NEON
471 target_compile_definitions(opus
472 PRIVATE
473 OPUS_ARM_MAY_HAVE_NEON
474 OPUS_ARM_MAY_HAVE_NEON_INTR)
475 endif()
476
477 add_sources_group(opus celt ${celt_sources_arm_neon_intr})
478 add_sources_group(opus silk ${silk_sources_arm_neon_intr})
479
480 # silk arm neon depends on main_Fix.h
481 target_include_directories(opus PRIVATE silk/fixed)
482
483 if(OPUS_FIXED_POINT)
484 add_sources_group(opus silk ${silk_sources_fixed_arm_neon_intr})
485 endif()
486
487 if(OPUS_PRESUME_NEON)
488 target_compile_definitions(opus
489 PRIVATE
490 OPUS_ARM_PRESUME_NEON
491 OPUS_ARM_PRESUME_NEON_INTR)
492 endif()
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800493 endif()
494endif()
495
Nathaniel R. Lewis94b68f32019-05-09 21:38:14 -0700496target_compile_definitions(opus
497 PRIVATE
498 $<$<BOOL:${HAVE_LRINT}>:HAVE_LRINT>
499 $<$<BOOL:${HAVE_LRINTF}>:HAVE_LRINTF>)
500
Simon Jacksonb2547012020-04-15 17:58:55 +0100501if(OPUS_BUILD_FRAMEWORK)
502 set_target_properties(opus PROPERTIES
503 FRAMEWORK TRUE
504 FRAMEWORK_VERSION ${PROJECT_VERSION}
505 MACOSX_FRAMEWORK_IDENTIFIER org.xiph.opus
506 MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PROJECT_VERSION}
507 MACOSX_FRAMEWORK_BUNDLE_VERSION ${PROJECT_VERSION}
508 XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
509 OUTPUT_NAME Opus)
510endif()
511
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800512install(TARGETS opus
513 EXPORT OpusTargets
514 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
515 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
516 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Simon Jacksonb2547012020-04-15 17:58:55 +0100517 FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800518 PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/opus)
519
520if(OPUS_INSTALL_PKG_CONFIG_MODULE)
521 set(prefix ${CMAKE_INSTALL_PREFIX})
522 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
523 set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
524 set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
DeadSix276d29f512019-12-05 06:00:58 +0100525 set(VERSION ${PACKAGE_VERSION})
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800526 if(HAVE_LIBM)
527 set(LIBM "-lm")
528 endif()
529 configure_file(opus.pc.in opus.pc)
530 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/opus.pc
531 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
532endif()
533
534if(OPUS_INSTALL_CMAKE_CONFIG_MODULE)
Marcus Asteborge7806452020-03-26 23:13:04 -0700535 set(CPACK_GENERATOR TGZ)
536 include(CPack)
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800537 set(CMAKE_INSTALL_PACKAGEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
538 install(EXPORT OpusTargets
539 NAMESPACE Opus::
540 DESTINATION ${CMAKE_INSTALL_PACKAGEDIR})
541
542 include(CMakePackageConfigHelpers)
543
544 set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR})
Marcus Asteborg8ad827c2020-06-24 21:25:57 -0700545 configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/OpusConfig.cmake.in
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800546 OpusConfig.cmake
547 INSTALL_DESTINATION
548 ${CMAKE_INSTALL_PACKAGEDIR}
549 PATH_VARS
550 INCLUDE_INSTALL_DIR
551 INSTALL_PREFIX
552 ${CMAKE_INSTALL_PREFIX})
553 write_basic_package_version_file(OpusConfigVersion.cmake
554 VERSION ${PROJECT_VERSION}
555 COMPATIBILITY SameMajorVersion)
556 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/OpusConfig.cmake
557 ${CMAKE_CURRENT_BINARY_DIR}/OpusConfigVersion.cmake
558 DESTINATION ${CMAKE_INSTALL_PACKAGEDIR})
559endif()
560
Marcus Asteborg268780f2019-04-10 16:34:01 -0700561if(OPUS_BUILD_PROGRAMS)
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800562 # demo
Marcus Asteborg268780f2019-04-10 16:34:01 -0700563 if(OPUS_CUSTOM_MODES)
564 add_executable(opus_custom_demo ${opus_custom_demo_sources})
565 target_include_directories(opus_custom_demo
566 PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
567 target_link_libraries(opus_custom_demo PRIVATE opus)
568 endif()
569
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800570 add_executable(opus_demo ${opus_demo_sources})
571 target_include_directories(opus_demo PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
Marcus Asteborg268780f2019-04-10 16:34:01 -0700572 target_include_directories(opus_demo PRIVATE silk) # debug.h
573 target_include_directories(opus_demo PRIVATE celt) # arch.h
willson-chenddb2c972019-12-19 16:59:32 +0800574 target_link_libraries(opus_demo PRIVATE opus ${OPUS_REQUIRED_LIBRARIES})
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800575
576 # compare
577 add_executable(opus_compare ${opus_compare_sources})
578 target_include_directories(opus_compare PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
willson-chenddb2c972019-12-19 16:59:32 +0800579 target_link_libraries(opus_compare PRIVATE opus ${OPUS_REQUIRED_LIBRARIES})
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800580endif()
581
582if(BUILD_TESTING)
583 enable_testing()
584
585 # tests
586 add_executable(test_opus_decode ${test_opus_decode_sources})
587 target_include_directories(test_opus_decode
588 PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
589 target_link_libraries(test_opus_decode PRIVATE opus)
590 if(OPUS_FIXED_POINT)
591 target_compile_definitions(test_opus_decode PRIVATE DISABLE_FLOAT_API)
592 endif()
Davide Beatricif040fb02020-06-05 01:19:21 +0200593 add_test(NAME test_opus_decode COMMAND $<TARGET_FILE:test_opus_decode> WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800594
595 add_executable(test_opus_padding ${test_opus_padding_sources})
596 target_include_directories(test_opus_padding
597 PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
598 target_link_libraries(test_opus_padding PRIVATE opus)
Davide Beatricif040fb02020-06-05 01:19:21 +0200599 add_test(NAME test_opus_padding COMMAND $<TARGET_FILE:test_opus_padding> WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800600
601 if(NOT BUILD_SHARED_LIBS)
602 # disable tests that depends on private API when building shared lib
603 add_executable(test_opus_api ${test_opus_api_sources})
604 target_include_directories(test_opus_api
605 PRIVATE ${CMAKE_CURRENT_BINARY_DIR} celt)
606 target_link_libraries(test_opus_api PRIVATE opus)
607 if(OPUS_FIXED_POINT)
608 target_compile_definitions(test_opus_api PRIVATE DISABLE_FLOAT_API)
609 endif()
Davide Beatricif040fb02020-06-05 01:19:21 +0200610 add_test(NAME test_opus_api COMMAND $<TARGET_FILE:test_opus_api> WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800611
612 add_executable(test_opus_encode ${test_opus_encode_sources})
613 target_include_directories(test_opus_encode
614 PRIVATE ${CMAKE_CURRENT_BINARY_DIR} celt)
615 target_link_libraries(test_opus_encode PRIVATE opus)
Davide Beatricif040fb02020-06-05 01:19:21 +0200616 add_test(NAME test_opus_encode COMMAND $<TARGET_FILE:test_opus_encode> WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
Marcus Asteborgf9d3d432018-11-15 19:48:38 -0800617 endif()
618endif()