From a80e9e9533d4edeaae282b82f77b8bd8a4903eca Mon Sep 17 00:00:00 2001 From: Marcus Asteborg Date: Tue, 5 Jul 2022 22:48:35 -0700 Subject: 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 --- cmake/OpusConfig.cmake | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/cmake/OpusConfig.cmake b/cmake/OpusConfig.cmake index 8d19a535..b82307a1 100644 --- a/cmake/OpusConfig.cmake +++ b/cmake/OpusConfig.cmake @@ -9,16 +9,18 @@ configure_file(cmake/config.h.cmake.in config.h @ONLY) 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 @@ else() 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) -- cgit v1.2.3