Correctly set NEED_MATH and link the required libm
Unified · Split
| @@ -11,6 +11,7 @@ include(CheckFunctionExists) · 10 unmodified lines | ||
| 11 | 11 | include(CheckIncludeFiles) |
| 12 | 12 | include(CheckSymbolExists) |
| 13 | 13 | include(CheckTypeSize) |
| 14 | +include(CMakePushCheckState) | |
| 14 | 15 | include(ClipMode) |
| 15 | 16 | |
| 16 | 17 | set(SAMPLERATE_SRC |
| @@ -34,14 +35,25 @@ else() · 17 unmodified lines | ||
| 34 | 35 | set(CPU_IS_LITTLE_ENDIAN 1) |
| 35 | 36 | endif() |
| 36 | 37 | |
| 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) | |
| 41 | 46 | 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 | + | |
| 42 | 56 | check_function_exists(alarm HAVE_ALARM) |
| 43 | −check_function_exists(lrint HAVE_LRINT) | |
| 44 | −check_function_exists(lrintf HAVE_LRINTF) | |
| 45 | 57 | check_function_exists(signal HAVE_SIGNAL) |
| 46 | 58 | |
| 47 | 59 | check_include_files(stdint.h HAVE_STDINT) |
| @@ -52,9 +64,6 @@ check_symbol_exists(SIGALRM signal.h HAVE_SIGALRM) · 4 unmodified lines | ||
| 52 | 64 | check_type_size(int SIZEOF_INT) |
| 53 | 65 | check_type_size(long SIZEOF_LONG) |
| 54 | 66 | |
| 55 | −# This will set CPU_CLIPS_NEGATIVE and CPU_CLIPS_POSITIVE | |
| 56 | −clip_mode() | |
| 57 | − | |
| 58 | 67 | find_package(ALSA) |
| 59 | 68 | set(HAVE_ALSA ${ALSA_FOUND}) |
| 60 | 69 | if(ALSA_FOUND) |
| @@ -88,6 +97,10 @@ endif() · 27 unmodified lines | ||
| 88 | 97 | target_include_directories(samplerate PUBLIC |
| 89 | 98 | ${PROJECT_SOURCE_DIR}/src |
| 90 | 99 | ${CMAKE_CURRENT_BINARY_DIR}) |
| 100 | + | |
| 101 | +if(NEED_MATH) | |
| 102 | + target_link_libraries(samplerate PUBLIC m) | |
| 103 | +endif() | |
| 91 | 104 | |
| 92 | 105 | if(LIBSAMPLERATE_TESTS) |
| 93 | 106 | |
| @@ -101,7 +114,7 @@ foreach(testSrc ${TEST_SRCS}) · 7 unmodified lines | ||
| 101 | 114 | ${testSrc} |
| 102 | 115 | ${PROJECT_SOURCE_DIR}/tests/util.c |
| 103 | 116 | ${PROJECT_SOURCE_DIR}/tests/calc_snr.c) |
| 104 | − target_link_libraries(${testName} PUBLIC samplerate ${CMAKE_REQUIRED_LIBRARIES}) | |
| 117 | + target_link_libraries(${testName} PUBLIC samplerate) | |
| 105 | 118 | if(FFTW_FOUND) |
| 106 | 119 | target_link_libraries(${testName} PUBLIC ${FFTW_LIBRARY}) |
| 107 | 120 | endif() |
| @@ -117,7 +130,7 @@ foreach(exampleSrc ${EXAMPLE_SRCS}) · 9 unmodified lines | ||
| 117 | 130 | add_executable(${exampleName} |
| 118 | 131 | ${exampleSrc} |
| 119 | 132 | ${PROJECT_SOURCE_DIR}/examples/audio_out.c) |
| 120 | − target_link_libraries(${exampleName} PUBLIC samplerate ${CMAKE_REQUIRED_LIBRARIES}) | |
| 133 | + target_link_libraries(${exampleName} PUBLIC samplerate) | |
| 121 | 134 | if(ALSA_FOUND) |
| 122 | 135 | target_link_libraries(${exampleName} PUBLIC ${ALSA_LIBRARY}) |
| 123 | 136 | endif() |
| @@ -1,5 +1,4 @@ | ||
| 1 | 1 | include (CheckCSourceRuns) |
| 2 | −include (CMakePushCheckState) | |
| 3 | 2 | |
| 4 | 3 | macro (CLIP_MODE) |
| 5 | 4 | |
| @@ -8,27 +7,16 @@ macro (CLIP_MODE) · 2 unmodified lines | ||
| 8 | 7 | |
| 9 | 8 | message (STATUS "Checking processor clipping capabilities...") |
| 10 | 9 | |
| 11 | − if (CMAKE_CROSSCOMPILING) | |
| 10 | + if (CMAKE_CROSSCOMPILING OR NOT HAVE_LRINT) | |
| 12 | 11 | |
| 13 | 12 | set (CLIP_MSG "disabled") |
| 14 | 13 | set (CPU_CLIPS_POSITIVE FALSE CACHE BOOL ${CLIP_MODE_POSITIVE_MESSAGE}) |
| 15 | 14 | set (CPU_CLIPS_NEGATIVE FALSE CACHE BOOL ${CLIP_MODE_NEGATIVE_MESSAGE}) |
| 16 | 15 | |
| 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 () | |
| 25 | 17 | |
| 26 | 18 | check_c_source_runs ( |
| 27 | 19 | " |
| 28 | − #define _ISOC9X_SOURCE 1 | |
| 29 | − #define _ISOC99_SOURCE 1 | |
| 30 | − #define __USE_ISOC99 1 | |
| 31 | − #define __USE_ISOC9X 1 | |
| 32 | 20 | #include <math.h> |
| 33 | 21 | int main (void) |
| 34 | 22 | { double fval ; |
| @@ -50,10 +38,6 @@ macro (CLIP_MODE) · 15 unmodified lines | ||
| 50 | 38 | |
| 51 | 39 | check_c_source_runs ( |
| 52 | 40 | " |
| 53 | − #define _ISOC9X_SOURCE 1 | |
| 54 | − #define _ISOC99_SOURCE 1 | |
| 55 | − #define __USE_ISOC99 1 | |
| 56 | − #define __USE_ISOC9X 1 | |
| 57 | 41 | #include <math.h> |
| 58 | 42 | int main (void) |
| 59 | 43 | { double fval ; |
| @@ -73,20 +57,18 @@ macro (CLIP_MODE) · 13 unmodified lines | ||
| 73 | 57 | " |
| 74 | 58 | CPU_CLIPS_NEGATIVE) |
| 75 | 59 | |
| 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) | |
| 79 | 63 | set (CLIP_MSG "positive") |
| 80 | − elseif (CPU_CLIPS_NEGATIVE AND (NOT CPU_CLIPS_POSITIVE)) | |
| 64 | + elseif (CPU_CLIPS_NEGATIVE) | |
| 81 | 65 | set (CLIP_MSG "negative") |
| 82 | − elseif (CPU_CLIPS_POSITIVE AND CPU_CLIPS_NEGATIVE) | |
| 83 | − set (CLIP_MSG "both") | |
| 84 | 66 | else () |
| 85 | 67 | set (CLIP_MSG "none") |
| 86 | 68 | endif () |
| 87 | 69 | |
| 88 | − endif (CMAKE_CROSSCOMPILING) | |
| 70 | + endif () | |
| 89 | 71 | |
| 90 | 72 | message (STATUS "Checking processor clipping capabilities... ${CLIP_MSG}") |
| 91 | 73 | |
| 92 | −endmacro (CLIP_MODE) | |
| 74 | +endmacro () | |