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