History

Fix the math/clip handling code

Correctly set NEED_MATH and link the required libm

Flamefire committed 7 years ago

Commit a7d5fa41 parent b12668a2 files · +32 −37Browse files

Unified · Split

2 files
  1. CMakeLists.txt +24 −11
  2. cmake/ClipMode.cmake +8 −26
CMakeLists.txt+24−11
@@ -11,6 +11,7 @@ include(CheckFunctionExists) · 10 unmodified lines
1111 include(CheckIncludeFiles)
1212 include(CheckSymbolExists)
1313 include(CheckTypeSize)
14+include(CMakePushCheckState)
1415 include(ClipMode)
1516
1617 set(SAMPLERATE_SRC
@@ -34,14 +35,25 @@ else() · 17 unmodified lines
3435 set(CPU_IS_LITTLE_ENDIAN 1)
3536 endif()
3637
37−check_function_exists(pow RESULT)
38−if(NOT RESULT)
39− list(APPEND CMAKE_REQUIRED_LIBRARIES m)
40− set(NEED_MATH)
38+cmake_push_check_state(RESET)
39+
40+check_symbol_exists(pow math.h RESULT)
41+if(RESULT)
42+ set(NEED_MATH OFF)
43+else()
44+ set(NEED_MATH ON)
45+ list(APPEND CMAKE_REQUIRED_LIBRARIES m)
4146 endif()
47+check_symbol_exists(lrint math.h HAVE_LRINT)
48+check_symbol_exists(lrintf math.h HAVE_LRINTF)
49+
50+# This will set CPU_CLIPS_NEGATIVE and CPU_CLIPS_POSITIVE
51+# requires HAVE_LRINT being set
52+clip_mode()
53+
54+cmake_pop_check_state()
55+
4256 check_function_exists(alarm HAVE_ALARM)
43−check_function_exists(lrint HAVE_LRINT)
44−check_function_exists(lrintf HAVE_LRINTF)
4557 check_function_exists(signal HAVE_SIGNAL)
4658
4759 check_include_files(stdint.h HAVE_STDINT)
@@ -52,9 +64,6 @@ check_symbol_exists(SIGALRM signal.h HAVE_SIGALRM) · 4 unmodified lines
5264 check_type_size(int SIZEOF_INT)
5365 check_type_size(long SIZEOF_LONG)
5466
55−# This will set CPU_CLIPS_NEGATIVE and CPU_CLIPS_POSITIVE
56−clip_mode()
57−
5867 find_package(ALSA)
5968 set(HAVE_ALSA ${ALSA_FOUND})
6069 if(ALSA_FOUND)
@@ -88,6 +97,10 @@ endif() · 27 unmodified lines
8897 target_include_directories(samplerate PUBLIC
8998 ${PROJECT_SOURCE_DIR}/src
9099 ${CMAKE_CURRENT_BINARY_DIR})
100+
101+if(NEED_MATH)
102+ target_link_libraries(samplerate PUBLIC m)
103+endif()
91104
92105 if(LIBSAMPLERATE_TESTS)
93106
@@ -101,7 +114,7 @@ foreach(testSrc ${TEST_SRCS}) · 7 unmodified lines
101114 ${testSrc}
102115 ${PROJECT_SOURCE_DIR}/tests/util.c
103116 ${PROJECT_SOURCE_DIR}/tests/calc_snr.c)
104− target_link_libraries(${testName} PUBLIC samplerate ${CMAKE_REQUIRED_LIBRARIES})
117+ target_link_libraries(${testName} PUBLIC samplerate)
105118 if(FFTW_FOUND)
106119 target_link_libraries(${testName} PUBLIC ${FFTW_LIBRARY})
107120 endif()
@@ -117,7 +130,7 @@ foreach(exampleSrc ${EXAMPLE_SRCS}) · 9 unmodified lines
117130 add_executable(${exampleName}
118131 ${exampleSrc}
119132 ${PROJECT_SOURCE_DIR}/examples/audio_out.c)
120− target_link_libraries(${exampleName} PUBLIC samplerate ${CMAKE_REQUIRED_LIBRARIES})
133+ target_link_libraries(${exampleName} PUBLIC samplerate)
121134 if(ALSA_FOUND)
122135 target_link_libraries(${exampleName} PUBLIC ${ALSA_LIBRARY})
123136 endif()
cmake/ClipMode.cmake+8−26
@@ -1,5 +1,4 @@
11 include (CheckCSourceRuns)
2−include (CMakePushCheckState)
32
43 macro (CLIP_MODE)
54
@@ -8,27 +7,16 @@ macro (CLIP_MODE) · 2 unmodified lines
87
98 message (STATUS "Checking processor clipping capabilities...")
109
11− if (CMAKE_CROSSCOMPILING)
10+ if (CMAKE_CROSSCOMPILING OR NOT HAVE_LRINT)
1211
1312 set (CLIP_MSG "disabled")
1413 set (CPU_CLIPS_POSITIVE FALSE CACHE BOOL ${CLIP_MODE_POSITIVE_MESSAGE})
1514 set (CPU_CLIPS_NEGATIVE FALSE CACHE BOOL ${CLIP_MODE_NEGATIVE_MESSAGE})
1615
17− else (NOT CMAKE_CROSSCOMPILING)
18−
19− cmake_push_check_state ()
20−
21− set (CMAKE_REQUIRED_QUIET TRUE)
22− if (LIBM_REQUIRED)
23− set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${M_LIBRARY})
24− endif ()
16+ else ()
2517
2618 check_c_source_runs (
2719 "
28− #define _ISOC9X_SOURCE 1
29− #define _ISOC99_SOURCE 1
30− #define __USE_ISOC99 1
31− #define __USE_ISOC9X 1
3220 #include <math.h>
3321 int main (void)
3422 { double fval ;
@@ -50,10 +38,6 @@ macro (CLIP_MODE) · 15 unmodified lines
5038
5139 check_c_source_runs (
5240 "
53− #define _ISOC9X_SOURCE 1
54− #define _ISOC99_SOURCE 1
55− #define __USE_ISOC99 1
56− #define __USE_ISOC9X 1
5741 #include <math.h>
5842 int main (void)
5943 { double fval ;
@@ -73,20 +57,18 @@ macro (CLIP_MODE) · 13 unmodified lines
7357 "
7458 CPU_CLIPS_NEGATIVE)
7559
76− cmake_pop_check_state ()
77−
78− if (CPU_CLIPS_POSITIVE AND (NOT CPU_CLIPS_NEGATIVE))
60+ if (CPU_CLIPS_POSITIVE AND CPU_CLIPS_NEGATIVE)
61+ set (CLIP_MSG "both")
62+ elseif (CPU_CLIPS_POSITIVE)
7963 set (CLIP_MSG "positive")
80− elseif (CPU_CLIPS_NEGATIVE AND (NOT CPU_CLIPS_POSITIVE))
64+ elseif (CPU_CLIPS_NEGATIVE)
8165 set (CLIP_MSG "negative")
82− elseif (CPU_CLIPS_POSITIVE AND CPU_CLIPS_NEGATIVE)
83− set (CLIP_MSG "both")
8466 else ()
8567 set (CLIP_MSG "none")
8668 endif ()
8769
88− endif (CMAKE_CROSSCOMPILING)
70+ endif ()
8971
9072 message (STATUS "Checking processor clipping capabilities... ${CLIP_MSG}")
9173
92−endmacro (CLIP_MODE)
74+endmacro ()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t