ref: a7d5fa49022756baecd6c39d998db3cf79aca812
parent: b12668ac1c0a223d0effd13447e7f7c3a6690912
author: Flamefire <Flamefire@users.noreply.github.com>
date: Tue Jul 23 09:24:59 EDT 2019
Fix the math/clip handling code Correctly set NEED_MATH and link the required libm
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,6 +11,7 @@
include(CheckIncludeFiles)
include(CheckSymbolExists)
include(CheckTypeSize)
+include(CMakePushCheckState)
include(ClipMode)
set(SAMPLERATE_SRC
@@ -34,14 +35,25 @@
set(CPU_IS_LITTLE_ENDIAN 1)
endif()
-check_function_exists(pow RESULT)
-if(NOT RESULT)
- list(APPEND CMAKE_REQUIRED_LIBRARIES m)
- set(NEED_MATH)
+cmake_push_check_state(RESET)
+
+check_symbol_exists(pow math.h RESULT)
+if(RESULT)
+ set(NEED_MATH OFF)
+else()
+ set(NEED_MATH ON)
+ list(APPEND CMAKE_REQUIRED_LIBRARIES m)
endif()
+check_symbol_exists(lrint math.h HAVE_LRINT)
+check_symbol_exists(lrintf math.h HAVE_LRINTF)
+
+# This will set CPU_CLIPS_NEGATIVE and CPU_CLIPS_POSITIVE
+# requires HAVE_LRINT being set
+clip_mode()
+
+cmake_pop_check_state()
+
check_function_exists(alarm HAVE_ALARM)
-check_function_exists(lrint HAVE_LRINT)
-check_function_exists(lrintf HAVE_LRINTF)
check_function_exists(signal HAVE_SIGNAL)
check_include_files(stdint.h HAVE_STDINT)
@@ -52,9 +64,6 @@
check_type_size(int SIZEOF_INT)
check_type_size(long SIZEOF_LONG)
-# This will set CPU_CLIPS_NEGATIVE and CPU_CLIPS_POSITIVE
-clip_mode()
-
find_package(ALSA)
set(HAVE_ALSA ${ALSA_FOUND})
if(ALSA_FOUND)
@@ -88,6 +97,10 @@
target_include_directories(samplerate PUBLIC
${PROJECT_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR})
+
+if(NEED_MATH)
+ target_link_libraries(samplerate PUBLIC m)
+endif()
if(LIBSAMPLERATE_TESTS)
@@ -101,7 +114,7 @@
${testSrc}
${PROJECT_SOURCE_DIR}/tests/util.c
${PROJECT_SOURCE_DIR}/tests/calc_snr.c)
- target_link_libraries(${testName} PUBLIC samplerate ${CMAKE_REQUIRED_LIBRARIES})
+ target_link_libraries(${testName} PUBLIC samplerate)
if(FFTW_FOUND)
target_link_libraries(${testName} PUBLIC ${FFTW_LIBRARY})
endif()
@@ -117,7 +130,7 @@
add_executable(${exampleName}
${exampleSrc}
${PROJECT_SOURCE_DIR}/examples/audio_out.c)
- target_link_libraries(${exampleName} PUBLIC samplerate ${CMAKE_REQUIRED_LIBRARIES})
+ target_link_libraries(${exampleName} PUBLIC samplerate)
if(ALSA_FOUND)
target_link_libraries(${exampleName} PUBLIC ${ALSA_LIBRARY})
endif()
--- a/cmake/ClipMode.cmake
+++ b/cmake/ClipMode.cmake
@@ -1,5 +1,4 @@
include (CheckCSourceRuns)
-include (CMakePushCheckState)
macro (CLIP_MODE)
@@ -8,27 +7,16 @@
message (STATUS "Checking processor clipping capabilities...")
- if (CMAKE_CROSSCOMPILING)
+ if (CMAKE_CROSSCOMPILING OR NOT HAVE_LRINT)
set (CLIP_MSG "disabled")
set (CPU_CLIPS_POSITIVE FALSE CACHE BOOL ${CLIP_MODE_POSITIVE_MESSAGE})
set (CPU_CLIPS_NEGATIVE FALSE CACHE BOOL ${CLIP_MODE_NEGATIVE_MESSAGE})
- else (NOT CMAKE_CROSSCOMPILING)
+ else ()
- cmake_push_check_state ()
-
- set (CMAKE_REQUIRED_QUIET TRUE)
- if (LIBM_REQUIRED)
- set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${M_LIBRARY})
- endif ()
-
check_c_source_runs (
"
- #define _ISOC9X_SOURCE 1
- #define _ISOC99_SOURCE 1
- #define __USE_ISOC99 1
- #define __USE_ISOC9X 1
#include <math.h>
int main (void)
{ double fval ;
@@ -50,10 +38,6 @@
check_c_source_runs (
"
- #define _ISOC9X_SOURCE 1
- #define _ISOC99_SOURCE 1
- #define __USE_ISOC99 1
- #define __USE_ISOC9X 1
#include <math.h>
int main (void)
{ double fval ;
@@ -73,20 +57,18 @@
"
CPU_CLIPS_NEGATIVE)
- cmake_pop_check_state ()
-
- if (CPU_CLIPS_POSITIVE AND (NOT CPU_CLIPS_NEGATIVE))
+ if (CPU_CLIPS_POSITIVE AND CPU_CLIPS_NEGATIVE)
+ set (CLIP_MSG "both")
+ elseif (CPU_CLIPS_POSITIVE)
set (CLIP_MSG "positive")
- elseif (CPU_CLIPS_NEGATIVE AND (NOT CPU_CLIPS_POSITIVE))
+ elseif (CPU_CLIPS_NEGATIVE)
set (CLIP_MSG "negative")
- elseif (CPU_CLIPS_POSITIVE AND CPU_CLIPS_NEGATIVE)
- set (CLIP_MSG "both")
else ()
set (CLIP_MSG "none")
endif ()
- endif (CMAKE_CROSSCOMPILING)
+ endif ()
message (STATUS "Checking processor clipping capabilities... ${CLIP_MSG}")
-endmacro (CLIP_MODE)
+endmacro ()