• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)
12set_property(GLOBAL PROPERTY C_STANDARD 99)
13
14if(MSVC)
15  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
16endif()
17
18include(CheckLibraryExists)
19check_library_exists(m floor "" HAVE_LIBM)
20if(HAVE_LIBM)
21  list(APPEND OPUS_REQUIRED_LIBRARIES m)
22endif()
23
24include(CFeatureCheck)
25c_feature_check(VLA)
26
27include(CheckIncludeFile)
28check_include_file(alloca.h HAVE_ALLOCA_H)
29
30include(CheckSymbolExists)
31if(HAVE_ALLOCA_H)
32  add_definitions(-DHAVE_ALLOCA_H)
33  check_symbol_exists(alloca "alloca.h" USE_ALLOCA_SUPPORTED)
34else()
35  check_symbol_exists(alloca "stdlib.h;malloc.h" USE_ALLOCA_SUPPORTED)
36endif()
37
38include(CheckFunctionExists)
39check_function_exists(lrintf HAVE_LRINTF)
40check_function_exists(lrint HAVE_LRINT)
41
42if(CMAKE_SYSTEM_PROCESSOR MATCHES "(i[0-9]86|x86|X86|amd64|AMD64|x86_64)")
43  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
44    set(OPUS_CPU_X64 1)
45  else()
46    set(OPUS_CPU_X86 1)
47  endif()
48elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm|aarch64)")
49  set(OPUS_CPU_ARM 1)
50endif()
51
52if(NOT OPUS_DISABLE_INTRINSICS)
53  opus_supports_cpu_detection(RUNTIME_CPU_CAPABILITY_DETECTION)
54endif()
55
56if(OPUS_CPU_X86 OR OPUS_CPU_X64 AND NOT OPUS_DISABLE_INTRINSICS)
57  opus_detect_sse(COMPILER_SUPPORT_SIMD)
58elseif(OPUS_CPU_ARM AND NOT OPUS_DISABLE_INTRINSICS)
59  opus_detect_neon(COMPILER_SUPPORT_NEON)
60  if(COMPILER_SUPPORT_NEON)
61    option(OPUS_USE_NEON "Option to enable NEON" ON)
62    option(OPUS_MAY_HAVE_NEON "Does runtime check for neon support" ON)
63    option(OPUS_PRESUME_NEON "Assume target CPU has NEON support" OFF)
64    if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
65      set(OPUS_PRESUME_NEON ON)
66    elseif(CMAKE_SYSTEM_NAME MATCHES "iOS")
67      set(OPUS_PRESUME_NEON ON)
68    endif()
69  endif()
70endif()
71
72if(MSVC)
73  check_flag(FAST_MATH /fp:fast)
74  check_flag(STACK_PROTECTOR /GS)
75  check_flag(STACK_PROTECTOR_DISABLED /GS-)
76else()
77  check_flag(FAST_MATH -ffast-math)
78  check_flag(STACK_PROTECTOR -fstack-protector-strong)
79  check_flag(HIDDEN_VISIBILITY -fvisibility=hidden)
80  set(FORTIFY_SOURCE_SUPPORTED 1)
81endif()
82
83if(MINGW)
84  # For MINGW we need to link ssp lib for security features such as
85  # stack protector and fortify_sources
86  check_library_exists(ssp __stack_chk_fail "" HAVE_LIBSSP)
87  if(NOT HAVE_LIBSSP)
88    message(WARNING "Could not find libssp in MinGW, disabling STACK_PROTECTOR and FORTIFY_SOURCE")
89    set(STACK_PROTECTOR_SUPPORTED 0)
90    set(FORTIFY_SOURCE_SUPPORTED 0)
91  endif()
92endif()
93
94if(NOT MSVC)
95  set(WARNING_LIST -Wall -W -Wstrict-prototypes -Wextra -Wcast-align -Wnested-externs -Wshadow)
96  include(CheckCCompilerFlag)
97  foreach(WARNING_FLAG ${WARNING_LIST})
98    string(REPLACE - "" WARNING_VAR ${WARNING_FLAG})
99    check_c_compiler_flag(${WARNING_FLAG} ${WARNING_VAR}_SUPPORTED)
100    if(${WARNING_VAR}_SUPPORTED)
101      add_compile_options(${WARNING_FLAG})
102    endif()
103  endforeach()
104endif()
105