1if(__opus_config) 2 return() 3endif() 4set(__opus_config INCLUDED) 5 6include(OpusFunctions) 7 8configure_file(cmake/config.h.cmake.in config.h @ONLY) 9add_definitions(-DHAVE_CONFIG_H) 10 11set_property(GLOBAL PROPERTY USE_FOLDERS ON) 12 13if(MSVC) 14 # For compilers that have no notion of a C standard level, 15 # such as Microsoft Visual C++ before VS 16.7, 16 # this property has no effect. 17 set(CMAKE_C_STANDARD 11) 18else() 19 set(CMAKE_C_STANDARD 99) 20endif() 21 22if(MSVC) 23 add_definitions(-D_CRT_SECURE_NO_WARNINGS) 24endif() 25 26include(CFeatureCheck) 27c_feature_check(VLA) 28 29include(CheckIncludeFile) 30check_include_file(alloca.h HAVE_ALLOCA_H) 31 32include(CheckSymbolExists) 33if(HAVE_ALLOCA_H) 34 add_definitions(-DHAVE_ALLOCA_H) 35 check_symbol_exists(alloca "alloca.h" USE_ALLOCA_SUPPORTED) 36else() 37 check_symbol_exists(alloca "stdlib.h;malloc.h" USE_ALLOCA_SUPPORTED) 38endif() 39 40include(CMakePushCheckState) 41cmake_push_check_state(RESET) 42include(CheckLibraryExists) 43check_library_exists(m floor "" HAVE_LIBM) 44if(HAVE_LIBM) 45 list(APPEND OPUS_REQUIRED_LIBRARIES m) 46 set(CMAKE_REQUIRED_LIBRARIES m) 47endif() 48 49check_symbol_exists(lrintf "math.h" HAVE_LRINTF) 50check_symbol_exists(lrint "math.h" HAVE_LRINT) 51cmake_pop_check_state() 52 53if(CMAKE_SYSTEM_PROCESSOR MATCHES "(i[0-9]86|x86|X86|amd64|AMD64|x86_64)") 54 if(CMAKE_SIZEOF_VOID_P EQUAL 8) 55 set(OPUS_CPU_X64 1) 56 else() 57 set(OPUS_CPU_X86 1) 58 endif() 59elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm|aarch64)") 60 set(OPUS_CPU_ARM 1) 61endif() 62 63if(NOT OPUS_DISABLE_INTRINSICS) 64 opus_supports_cpu_detection(RUNTIME_CPU_CAPABILITY_DETECTION) 65endif() 66 67if(OPUS_CPU_X86 OR OPUS_CPU_X64 AND NOT OPUS_DISABLE_INTRINSICS) 68 opus_detect_sse(COMPILER_SUPPORT_SIMD) 69elseif(OPUS_CPU_ARM AND NOT OPUS_DISABLE_INTRINSICS) 70 opus_detect_neon(COMPILER_SUPPORT_NEON) 71 if(COMPILER_SUPPORT_NEON) 72 option(OPUS_USE_NEON "Option to enable NEON" ON) 73 option(OPUS_MAY_HAVE_NEON "Does runtime check for neon support" ON) 74 option(OPUS_PRESUME_NEON "Assume target CPU has NEON support" OFF) 75 if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") 76 set(OPUS_PRESUME_NEON ON) 77 elseif(CMAKE_SYSTEM_NAME MATCHES "iOS") 78 set(OPUS_PRESUME_NEON ON) 79 endif() 80 endif() 81endif() 82 83if(MSVC) 84 check_flag(FAST_MATH /fp:fast) 85 check_flag(STACK_PROTECTOR /GS) 86 check_flag(STACK_PROTECTOR_DISABLED /GS-) 87else() 88 check_flag(FAST_MATH -ffast-math) 89 check_flag(STACK_PROTECTOR -fstack-protector-strong) 90 check_flag(HIDDEN_VISIBILITY -fvisibility=hidden) 91 set(FORTIFY_SOURCE_SUPPORTED 1) 92endif() 93 94if(MINGW) 95 # For MINGW we need to link ssp lib for security features such as 96 # stack protector and fortify_sources 97 check_library_exists(ssp __stack_chk_fail "" HAVE_LIBSSP) 98 if(NOT HAVE_LIBSSP) 99 message(WARNING "Could not find libssp in MinGW, disabling STACK_PROTECTOR and FORTIFY_SOURCE") 100 set(STACK_PROTECTOR_SUPPORTED 0) 101 set(FORTIFY_SOURCE_SUPPORTED 0) 102 endif() 103endif() 104 105if(MSVC) 106 # move cosmetic warnings to level 4 107 add_compile_options(/w44244 /w44305 /w44267) 108else() 109 set(WARNING_LIST -Wall -W -Wstrict-prototypes -Wextra -Wcast-align -Wnested-externs -Wshadow) 110 include(CheckCCompilerFlag) 111 foreach(WARNING_FLAG ${WARNING_LIST}) 112 string(REPLACE - "" WARNING_VAR ${WARNING_FLAG}) 113 check_c_compiler_flag(${WARNING_FLAG} ${WARNING_VAR}_SUPPORTED) 114 if(${WARNING_VAR}_SUPPORTED) 115 add_compile_options(${WARNING_FLAG}) 116 endif() 117 endforeach() 118endif() 119