OpusConfig.cmake 2.9 KB

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