1cmake_minimum_required(VERSION 3.1) 2list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 3 4include(OpusPackageVersion) 5get_package_version(PACKAGE_VERSION PROJECT_VERSION) 6 7project(Opus LANGUAGES C VERSION ${PROJECT_VERSION}) 8 9include(OpusFunctions) 10include(OpusBuildtype) 11include(OpusConfig) 12include(OpusSources) 13include(GNUInstallDirs) 14include(CMakeDependentOption) 15include(FeatureSummary) 16 17set(OPUS_BUILD_SHARED_LIBRARY_HELP_STR "build shared library.") 18option(OPUS_BUILD_SHARED_LIBRARY ${OPUS_BUILD_SHARED_LIBRARY_HELP_STR} OFF) 19if(OPUS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS OR OPUS_BUILD_FRAMEWORK) 20 # Global flag to cause add_library() to create shared libraries if on. 21 set(BUILD_SHARED_LIBS ON) 22 set(OPUS_BUILD_SHARED_LIBRARY ON) 23endif() 24add_feature_info(OPUS_BUILD_SHARED_LIBRARY OPUS_BUILD_SHARED_LIBRARY ${OPUS_BUILD_SHARED_LIBRARY_HELP_STR}) 25 26set(OPUS_BUILD_TESTING_HELP_STR "build tests.") 27option(OPUS_BUILD_TESTING ${OPUS_BUILD_TESTING_HELP_STR} OFF) 28if(OPUS_BUILD_TESTING OR BUILD_TESTING) 29 set(OPUS_BUILD_TESTING ON) 30 set(BUILD_TESTING ON) 31endif() 32add_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) 52add_feature_info(OPUS_ENABLE_FLOAT_API OPUS_ENABLE_FLOAT_API ${OPUS_ENABLE_FLOAT_API_HELP_STR}) 53 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 58set(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 62set(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 66set(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 70set(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 74set(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 88set(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 96set(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}) 135 136if(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) 149endif() 150 151if(OPUS_CPU_X86 OR OPUS_CPU_X64) 152 set(OPUS_X86_MAY_HAVE_SSE_HELP_STR "does runtime check for SSE1 support.") 153 cmake_dependent_option(OPUS_X86_MAY_HAVE_SSE 154 ${OPUS_X86_MAY_HAVE_SSE_HELP_STR} 155 ON 156 "SSE1_SUPPORTED; NOT OPUS_DISABLE_INTRINSICS" 157 OFF) 158 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.") 161 cmake_dependent_option(OPUS_X86_MAY_HAVE_SSE2 162 ${OPUS_X86_MAY_HAVE_SSE2_HELP_STR} 163 ON 164 "SSE2_SUPPORTED; NOT OPUS_DISABLE_INTRINSICS" 165 OFF) 166 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.") 169 cmake_dependent_option(OPUS_X86_MAY_HAVE_SSE4_1 170 ${OPUS_X86_MAY_HAVE_SSE4_1_HELP_STR} 171 ON 172 "SSE4_1_SUPPORTED; NOT OPUS_DISABLE_INTRINSICS" 173 OFF) 174 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.") 177 cmake_dependent_option(OPUS_X86_MAY_HAVE_AVX 178 ${OPUS_X86_MAY_HAVE_AVX_HELP_STR} 179 ON 180 "AVX_SUPPORTED; NOT OPUS_DISABLE_INTRINSICS" 181 OFF) 182 add_feature_info(OPUS_X86_MAY_HAVE_AVX OPUS_X86_MAY_HAVE_AVX ${OPUS_X86_MAY_HAVE_AVX_HELP_STR}) 183 184 # PRESUME depends on MAY HAVE, but PRESUME will override runtime detection 185 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 188 cmake_dependent_option(OPUS_X86_PRESUME_SSE 189 ${OPUS_X86_PRESUME_SSE_HELP_STR} 190 ON 191 "OPUS_X86_MAY_HAVE_SSE; NOT OPUS_DISABLE_INTRINSICS" 192 OFF) 193 194 cmake_dependent_option(OPUS_X86_PRESUME_SSE2 195 ${OPUS_X86_PRESUME_SSE2_HELP_STR} 196 ON 197 "OPUS_X86_MAY_HAVE_SSE2; NOT OPUS_DISABLE_INTRINSICS" 198 OFF) 199 else() 200 cmake_dependent_option(OPUS_X86_PRESUME_SSE 201 ${OPUS_X86_PRESUME_SSE_HELP_STR} 202 OFF 203 "OPUS_X86_MAY_HAVE_SSE; NOT OPUS_DISABLE_INTRINSICS" 204 OFF) 205 206 cmake_dependent_option(OPUS_X86_PRESUME_SSE2 207 ${OPUS_X86_PRESUME_SSE2_HELP_STR} 208 OFF 209 "OPUS_X86_MAY_HAVE_SSE2; NOT OPUS_DISABLE_INTRINSICS" 210 OFF) 211 endif() 212 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).") 216 cmake_dependent_option(OPUS_X86_PRESUME_SSE4_1 217 ${OPUS_X86_PRESUME_SSE4_1_HELP_STR} 218 OFF 219 "OPUS_X86_MAY_HAVE_SSE4_1; NOT OPUS_DISABLE_INTRINSICS" 220 OFF) 221 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).") 224 cmake_dependent_option(OPUS_X86_PRESUME_AVX 225 ${OPUS_X86_PRESUME_AVX_HELP_STR} 226 OFF 227 "OPUS_X86_MAY_HAVE_AVX; NOT OPUS_DISABLE_INTRINSICS" 228 OFF) 229 add_feature_info(OPUS_X86_PRESUME_AVX OPUS_X86_PRESUME_AVX ${OPUS_X86_PRESUME_AVX_HELP_STR}) 230endif() 231 232feature_summary(WHAT ALL) 233 234set_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 245set(Opus_PUBLIC_HEADER 246 ${CMAKE_CURRENT_SOURCE_DIR}/include/opus.h 247 ${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 252if(OPUS_CUSTOM_MODES) 253 list(APPEND Opus_PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_custom.h) 254endif() 255 256add_library(opus ${opus_headers} ${opus_sources} ${opus_sources_float} ${Opus_PUBLIC_HEADER}) 257add_library(Opus::opus ALIAS opus) 258 259get_library_version(OPUS_LIBRARY_VERSION OPUS_LIBRARY_VERSION_MAJOR) 260message(DEBUG "Opus library version: ${OPUS_LIBRARY_VERSION}") 261 262set_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}> 274 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/opus> 275 PRIVATE ${CMAKE_CURRENT_BINARY_DIR} 276 ${CMAKE_CURRENT_SOURCE_DIR} 277 celt 278 silk) 279 280target_link_libraries(opus PRIVATE ${OPUS_REQUIRED_LIBRARIES}) 281target_compile_definitions(opus PRIVATE OPUS_BUILD) 282 283if(OPUS_FIXED_POINT_DEBUG) 284 target_compile_definitions(opus PRIVATE FIXED_DEBUG) 285endif() 286 287if(OPUS_FORTIFY_SOURCE AND NOT MSVC) 288 target_compile_definitions(opus PRIVATE 289 $<$<NOT:$<CONFIG:debug>>:_FORTIFY_SOURCE=2>) 290endif() 291 292if(OPUS_FLOAT_APPROX) 293 target_compile_definitions(opus PRIVATE FLOAT_APPROX) 294endif() 295 296if(OPUS_ASSERTIONS) 297 target_compile_definitions(opus PRIVATE ENABLE_ASSERTIONS) 298endif() 299 300if(OPUS_HARDENING) 301 target_compile_definitions(opus PRIVATE ENABLE_HARDENING) 302endif() 303 304if(OPUS_FUZZING) 305 target_compile_definitions(opus PRIVATE FUZZING) 306endif() 307 308if(OPUS_CHECK_ASM) 309 target_compile_definitions(opus PRIVATE OPUS_CHECK_ASM) 310endif() 311 312if(OPUS_VAR_ARRAYS) 313 target_compile_definitions(opus PRIVATE VAR_ARRAYS) 314elseif(OPUS_USE_ALLOCA) 315 target_compile_definitions(opus PRIVATE USE_ALLOCA) 316elseif(OPUS_NONTHREADSAFE_PSEUDOSTACK) 317 target_compile_definitions(opus PRIVATE NONTHREADSAFE_PSEUDOSTACK) 318else() 319 message(ERROR "Need to set a define for stack allocation") 320endif() 321 322if(OPUS_CUSTOM_MODES) 323 target_compile_definitions(opus PRIVATE CUSTOM_MODES) 324endif() 325 326if(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 344if(BUILD_SHARED_LIBS) 345 if(WIN32) 346 target_compile_definitions(opus PRIVATE DLL_EXPORT) 347 elseif(HIDDEN_VISIBILITY_SUPPORTED) 348 set_target_properties(opus PROPERTIES C_VISIBILITY_PRESET hidden) 349 endif() 350endif() 351 352add_sources_group(opus silk ${silk_headers} ${silk_sources}) 353add_sources_group(opus celt ${celt_headers} ${celt_sources}) 354 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 368if(NOT OPUS_DISABLE_INTRINSICS) 369 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)) AND 373 RUNTIME_CPU_CAPABILITY_DETECTION) 374 target_compile_definitions(opus PRIVATE OPUS_HAVE_RTCD) 375 if(NOT MSVC) 376 if(CPU_INFO_BY_ASM_SUPPORTED) 377 target_compile_definitions(opus PRIVATE CPU_INFO_BY_ASM) 378 elseif(CPU_INFO_BY_C_SUPPORTED) 379 target_compile_definitions(opus PRIVATE CPU_INFO_BY_C) 380 else() 381 message(ERROR "Runtime cpu capability detection is enabled while CPU_INFO is not supported") 382 endif() 383 endif() 384 add_sources_group(opus celt ${celt_sources_x86_rtcd}) 385 add_sources_group(opus silk ${silk_sources_x86_rtcd}) 386 endif() 387 388 if(SSE1_SUPPORTED) 389 if(OPUS_X86_MAY_HAVE_SSE) 390 add_sources_group(opus celt ${celt_sources_sse}) 391 target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_SSE) 392 if(NOT MSVC) 393 set_source_files_properties(${celt_sources_sse} PROPERTIES COMPILE_FLAGS -msse) 394 endif() 395 endif() 396 if(OPUS_X86_PRESUME_SSE) 397 target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_SSE) 398 if(NOT MSVC) 399 target_compile_options(opus PRIVATE -msse) 400 endif() 401 endif() 402 endif() 403 404 if(SSE2_SUPPORTED) 405 if(OPUS_X86_MAY_HAVE_SSE2) 406 add_sources_group(opus celt ${celt_sources_sse2}) 407 target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_SSE2) 408 if(NOT MSVC) 409 set_source_files_properties(${celt_sources_sse2} PROPERTIES COMPILE_FLAGS -msse2) 410 endif() 411 endif() 412 if(OPUS_X86_PRESUME_SSE2) 413 target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_SSE2) 414 if(NOT MSVC) 415 target_compile_options(opus PRIVATE -msse2) 416 endif() 417 endif() 418 endif() 419 420 if(SSE4_1_SUPPORTED) 421 if(OPUS_X86_MAY_HAVE_SSE4_1) 422 add_sources_group(opus celt ${celt_sources_sse4_1}) 423 add_sources_group(opus silk ${silk_sources_sse4_1}) 424 target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_SSE4_1) 425 if(NOT MSVC) 426 set_source_files_properties(${celt_sources_sse4_1} ${silk_sources_sse4_1} PROPERTIES COMPILE_FLAGS -msse4.1) 427 endif() 428 429 if(OPUS_FIXED_POINT) 430 add_sources_group(opus silk ${silk_sources_fixed_sse4_1}) 431 if(NOT MSVC) 432 set_source_files_properties(${silk_sources_fixed_sse4_1} PROPERTIES COMPILE_FLAGS -msse4.1) 433 endif() 434 endif() 435 endif() 436 if(OPUS_X86_PRESUME_SSE4_1) 437 target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_SSE4_1) 438 if(NOT MSVC) 439 target_compile_options(opus PRIVATE -msse4.1) 440 endif() 441 endif() 442 endif() 443 444 if(AVX_SUPPORTED) 445 # mostly placeholder in case of avx intrinsics is added 446 if(OPUS_X86_MAY_HAVE_AVX) 447 target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_AVX) 448 endif() 449 if(OPUS_X86_PRESUME_AVX) 450 target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_AVX) 451 if(NOT MSVC) 452 target_compile_options(opus PRIVATE -mavx) 453 endif() 454 endif() 455 endif() 456 457 if(MSVC) 458 if(AVX_SUPPORTED AND OPUS_X86_PRESUME_AVX) # on 64 bit and 32 bits 459 add_definitions(/arch:AVX) 460 elseif(OPUS_CPU_X86) # if AVX not supported then set SSE flag 461 if((SSE4_1_SUPPORTED AND OPUS_X86_PRESUME_SSE4_1) 462 OR (SSE2_SUPPORTED AND OPUS_X86_PRESUME_SSE2)) 463 target_compile_definitions(opus PRIVATE /arch:SSE2) 464 elseif(SSE1_SUPPORTED AND OPUS_X86_PRESUME_SSE) 465 target_compile_definitions(opus PRIVATE /arch:SSE) 466 endif() 467 endif() 468 endif() 469 470 if(COMPILER_SUPPORT_NEON) 471 if(OPUS_MAY_HAVE_NEON) 472 if(RUNTIME_CPU_CAPABILITY_DETECTION) 473 message(STATUS "OPUS_MAY_HAVE_NEON enabling runtime detection") 474 target_compile_definitions(opus PRIVATE OPUS_HAVE_RTCD) 475 add_sources_group(opus celt ${celt_sources_arm_rtcd}) 476 add_sources_group(opus silk ${silk_sources_arm_rtcd}) 477 else() 478 message(ERROR "Runtime cpu capability detection needed for MAY_HAVE_NEON") 479 endif() 480 # Do runtime check for NEON 481 target_compile_definitions(opus 482 PRIVATE 483 OPUS_ARM_MAY_HAVE_NEON 484 OPUS_ARM_MAY_HAVE_NEON_INTR) 485 endif() 486 487 add_sources_group(opus celt ${celt_sources_arm_neon_intr}) 488 add_sources_group(opus silk ${silk_sources_arm_neon_intr}) 489 490 # silk arm neon depends on main_Fix.h 491 target_include_directories(opus PRIVATE silk/fixed) 492 493 if(OPUS_FIXED_POINT) 494 add_sources_group(opus silk ${silk_sources_fixed_arm_neon_intr}) 495 endif() 496 497 if(OPUS_PRESUME_NEON) 498 target_compile_definitions(opus 499 PRIVATE 500 OPUS_ARM_PRESUME_NEON 501 OPUS_ARM_PRESUME_NEON_INTR) 502 endif() 503 endif() 504endif() 505 506target_compile_definitions(opus 507 PRIVATE 508 $<$<BOOL:${HAVE_LRINT}>:HAVE_LRINT> 509 $<$<BOOL:${HAVE_LRINTF}>:HAVE_LRINTF>) 510 511if(OPUS_BUILD_FRAMEWORK) 512 set_target_properties(opus PROPERTIES 513 FRAMEWORK TRUE 514 FRAMEWORK_VERSION ${PROJECT_VERSION} 515 MACOSX_FRAMEWORK_IDENTIFIER org.xiph.opus 516 MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PROJECT_VERSION} 517 MACOSX_FRAMEWORK_BUNDLE_VERSION ${PROJECT_VERSION} 518 XCODE_ATTRIBUTE_INSTALL_PATH "@rpath" 519 OUTPUT_NAME Opus) 520endif() 521 522install(TARGETS opus 523 EXPORT OpusTargets 524 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 525 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 526 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 527 FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX} 528 PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/opus) 529 530if(OPUS_INSTALL_PKG_CONFIG_MODULE) 531 set(prefix ${CMAKE_INSTALL_PREFIX}) 532 set(exec_prefix ${CMAKE_INSTALL_PREFIX}) 533 set(libdir ${CMAKE_INSTALL_FULL_LIBDIR}) 534 set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR}) 535 set(VERSION ${PACKAGE_VERSION}) 536 if(HAVE_LIBM) 537 set(LIBM "-lm") 538 endif() 539 configure_file(opus.pc.in opus.pc) 540 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/opus.pc 541 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) 542endif() 543 544if(OPUS_INSTALL_CMAKE_CONFIG_MODULE) 545 set(CPACK_GENERATOR TGZ) 546 include(CPack) 547 set(CMAKE_INSTALL_PACKAGEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) 548 install(EXPORT OpusTargets 549 NAMESPACE Opus:: 550 DESTINATION ${CMAKE_INSTALL_PACKAGEDIR}) 551 552 include(CMakePackageConfigHelpers) 553 554 set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) 555 configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/OpusConfig.cmake.in 556 OpusConfig.cmake 557 INSTALL_DESTINATION 558 ${CMAKE_INSTALL_PACKAGEDIR} 559 PATH_VARS 560 INCLUDE_INSTALL_DIR 561 INSTALL_PREFIX 562 ${CMAKE_INSTALL_PREFIX}) 563 write_basic_package_version_file(OpusConfigVersion.cmake 564 VERSION ${PROJECT_VERSION} 565 COMPATIBILITY SameMajorVersion) 566 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/OpusConfig.cmake 567 ${CMAKE_CURRENT_BINARY_DIR}/OpusConfigVersion.cmake 568 DESTINATION ${CMAKE_INSTALL_PACKAGEDIR}) 569endif() 570 571if(OPUS_BUILD_PROGRAMS) 572 # demo 573 if(OPUS_CUSTOM_MODES) 574 add_executable(opus_custom_demo ${opus_custom_demo_sources}) 575 target_include_directories(opus_custom_demo 576 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) 577 target_link_libraries(opus_custom_demo PRIVATE opus) 578 target_compile_definitions(opus_custom_demo PRIVATE OPUS_BUILD) 579 endif() 580 581 add_executable(opus_demo ${opus_demo_sources}) 582 target_include_directories(opus_demo PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) 583 target_include_directories(opus_demo PRIVATE silk) # debug.h 584 target_include_directories(opus_demo PRIVATE celt) # arch.h 585 target_link_libraries(opus_demo PRIVATE opus ${OPUS_REQUIRED_LIBRARIES}) 586 target_compile_definitions(opus_demo PRIVATE OPUS_BUILD) 587 588 # compare 589 add_executable(opus_compare ${opus_compare_sources}) 590 target_include_directories(opus_compare PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) 591 target_link_libraries(opus_compare PRIVATE opus ${OPUS_REQUIRED_LIBRARIES}) 592 if(MSVC) 593 # move cosmetic warning to level 4 for opus_compare 594 target_compile_options(opus_compare PRIVATE /w44244) 595 endif() 596endif() 597 598if(BUILD_TESTING AND NOT BUILD_SHARED_LIBS) 599 enable_testing() 600 601 # tests 602 add_executable(test_opus_decode ${test_opus_decode_sources}) 603 target_include_directories(test_opus_decode 604 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) 605 target_link_libraries(test_opus_decode PRIVATE opus) 606 target_compile_definitions(test_opus_decode PRIVATE OPUS_BUILD) 607 if(OPUS_FIXED_POINT) 608 target_compile_definitions(test_opus_decode PRIVATE DISABLE_FLOAT_API) 609 endif() 610 add_test(NAME test_opus_decode COMMAND ${CMAKE_COMMAND} 611 -DTEST_EXECUTABLE=$<TARGET_FILE:test_opus_decode> 612 -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} 613 -P "${PROJECT_SOURCE_DIR}/cmake/RunTest.cmake") 614 615 add_executable(test_opus_padding ${test_opus_padding_sources}) 616 target_include_directories(test_opus_padding 617 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) 618 target_link_libraries(test_opus_padding PRIVATE opus) 619 add_test(NAME test_opus_padding COMMAND ${CMAKE_COMMAND} 620 -DTEST_EXECUTABLE=$<TARGET_FILE:test_opus_padding> 621 -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} 622 -P "${PROJECT_SOURCE_DIR}/cmake/RunTest.cmake") 623 624 add_executable(test_opus_api ${test_opus_api_sources}) 625 target_include_directories(test_opus_api 626 PRIVATE ${CMAKE_CURRENT_BINARY_DIR} celt) 627 target_link_libraries(test_opus_api PRIVATE opus) 628 target_compile_definitions(test_opus_api PRIVATE OPUS_BUILD) 629 if(OPUS_FIXED_POINT) 630 target_compile_definitions(test_opus_api PRIVATE DISABLE_FLOAT_API) 631 endif() 632 add_test(NAME test_opus_api COMMAND ${CMAKE_COMMAND} 633 -DTEST_EXECUTABLE=$<TARGET_FILE:test_opus_api> 634 -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} 635 -P "${PROJECT_SOURCE_DIR}/cmake/RunTest.cmake") 636 637 add_executable(test_opus_encode ${test_opus_encode_sources}) 638 target_include_directories(test_opus_encode 639 PRIVATE ${CMAKE_CURRENT_BINARY_DIR} celt) 640 target_link_libraries(test_opus_encode PRIVATE opus) 641 target_compile_definitions(test_opus_encode PRIVATE OPUS_BUILD) 642 add_test(NAME test_opus_encode COMMAND ${CMAKE_COMMAND} 643 -DTEST_EXECUTABLE=$<TARGET_FILE:test_opus_encode> 644 -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} 645 -P "${PROJECT_SOURCE_DIR}/cmake/RunTest.cmake") 646endif() 647