shithub: opus

Download patch

ref: a80e9e9533d4edeaae282b82f77b8bd8a4903eca
parent: f1b088001ecbc523ffb07109f301d8773bec44b8
author: Marcus Asteborg <maastebo@microsoft.com>
date: Tue Jul 5 18:48:35 EDT 2022

cmake - fix lrintf, lrint detection

This commit addresses the issues of not finding lrintf and lrint. We
switch to check_symbol_exists instead per cmake documentation. Also
make sure to link math lib for detection for nix.

For MSVC the issue for non x86 builds was that the standard was set to
default which is 199409L. This resulted in not using lrintf even that
it was found. To address this we set the C standard to C11 and it will
only apply to newer versions of MSVC where the /std flag is supported.

Signed-off-by: Mark Harris <mark.hsj@gmail.com>

--- a/cmake/OpusConfig.cmake
+++ b/cmake/OpusConfig.cmake
@@ -9,16 +9,18 @@
 add_definitions(-DHAVE_CONFIG_H)
 
 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
-set_property(GLOBAL PROPERTY C_STANDARD 99)
 
 if(MSVC)
-  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
+  # For compilers that have no notion of a C standard level,
+  # such as Microsoft Visual C++ before VS 16.7,
+  # this property has no effect.
+  set(CMAKE_C_STANDARD 11)
+else()
+  set(CMAKE_C_STANDARD 99)
 endif()
 
-include(CheckLibraryExists)
-check_library_exists(m floor "" HAVE_LIBM)
-if(HAVE_LIBM)
-  list(APPEND OPUS_REQUIRED_LIBRARIES m)
+if(MSVC)
+  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
 endif()
 
 include(CFeatureCheck)
@@ -35,9 +37,18 @@
   check_symbol_exists(alloca "stdlib.h;malloc.h" USE_ALLOCA_SUPPORTED)
 endif()
 
-include(CheckFunctionExists)
-check_function_exists(lrintf HAVE_LRINTF)
-check_function_exists(lrint HAVE_LRINT)
+include(CMakePushCheckState)
+cmake_push_check_state(RESET)
+include(CheckLibraryExists)
+check_library_exists(m floor "" HAVE_LIBM)
+if(HAVE_LIBM)
+  list(APPEND OPUS_REQUIRED_LIBRARIES m)
+  set(CMAKE_REQUIRED_LIBRARIES m)
+endif()
+
+check_symbol_exists(lrintf "math.h" HAVE_LRINTF)
+check_symbol_exists(lrint "math.h" HAVE_LRINT)
+cmake_pop_check_state()
 
 if(CMAKE_SYSTEM_PROCESSOR MATCHES "(i[0-9]86|x86|X86|amd64|AMD64|x86_64)")
   if(CMAKE_SIZEOF_VOID_P EQUAL 8)