|
| 1 | +# TODO |
| 2 | +# - backend selection via command line, rather than simply detecting headers. |
| 3 | + |
| 4 | +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) |
| 5 | +project(cubeb |
| 6 | + VERSION 0.0.0) |
| 7 | + |
| 8 | +if(POLICY CMP0063) |
| 9 | + cmake_policy(SET CMP0063 NEW) |
| 10 | +endif() |
| 11 | +set(CMAKE_C_STANDARD 99) |
| 12 | +set(CMAKE_CXX_STANDARD 11) |
| 13 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 14 | + |
| 15 | +set(CMAKE_C_VISIBILITY_PRESET hidden) |
| 16 | +set(CMAKE_CXX_VISIBILITY_PRESET hidden) |
| 17 | +set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) |
| 18 | + |
| 19 | +add_library(cubeb |
| 20 | + src/cubeb.c |
| 21 | + src/cubeb_resampler.cpp |
| 22 | + src/cubeb_panner.cpp |
| 23 | + $<TARGET_OBJECTS:speex>) |
| 24 | +target_include_directories(cubeb PUBLIC include) |
| 25 | +target_include_directories(cubeb PRIVATE src) |
| 26 | +target_compile_definitions(cubeb PRIVATE OUTSIDE_SPEEX) |
| 27 | +target_compile_definitions(cubeb PRIVATE FLOATING_POINT) |
| 28 | +target_compile_definitions(cubeb PRIVATE EXPORT=) |
| 29 | +target_compile_definitions(cubeb PRIVATE RANDOM_PREFIX=speex) |
| 30 | + |
| 31 | +include(GenerateExportHeader) |
| 32 | +generate_export_header(cubeb EXPORT_FILE_NAME ${CMAKE_BINARY_DIR}/exports/cubeb_export.h) |
| 33 | +target_include_directories(cubeb PUBLIC ${CMAKE_BINARY_DIR}/exports) |
| 34 | + |
| 35 | +add_library(speex OBJECT |
| 36 | + src/speex/resample.c) |
| 37 | +set_target_properties(speex PROPERTIES POSITION_INDEPENDENT_CODE TRUE) |
| 38 | +target_compile_definitions(speex PRIVATE OUTSIDE_SPEEX) |
| 39 | +target_compile_definitions(speex PRIVATE FLOATING_POINT) |
| 40 | +target_compile_definitions(speex PRIVATE EXPORT=) |
| 41 | +target_compile_definitions(speex PRIVATE RANDOM_PREFIX=speex) |
| 42 | + |
| 43 | +include(CheckIncludeFiles) |
| 44 | + |
| 45 | +check_include_files(AudioUnit/AudioUnit.h USE_AUDIOUNIT) |
| 46 | +if(USE_AUDIOUNIT) |
| 47 | + target_sources(cubeb PRIVATE |
| 48 | + src/cubeb_audiounit.cpp |
| 49 | + src/cubeb_osx_run_loop.c) |
| 50 | + target_compile_definitions(cubeb PRIVATE USE_AUDIOUNIT) |
| 51 | + target_link_libraries(cubeb PRIVATE "-framework AudioUnit" "-framework CoreAudio" "-framework CoreServices") |
| 52 | +endif() |
| 53 | + |
| 54 | +check_include_files(pulse/pulseaudio.h USE_PULSE) |
| 55 | +if(USE_PULSE) |
| 56 | + target_sources(cubeb PRIVATE |
| 57 | + src/cubeb_pulse.c) |
| 58 | + target_compile_definitions(cubeb PRIVATE USE_PULSE) |
| 59 | + target_link_libraries(cubeb PRIVATE pulse) |
| 60 | +endif() |
| 61 | + |
| 62 | +check_include_files(alsa/asoundlib.h USE_ALSA) |
| 63 | +if(USE_ALSA) |
| 64 | + target_sources(cubeb PRIVATE |
| 65 | + src/cubeb_alsa.c) |
| 66 | + target_compile_definitions(cubeb PRIVATE USE_ALSA) |
| 67 | + target_link_libraries(cubeb PRIVATE asound dl pthread) |
| 68 | +endif() |
| 69 | + |
| 70 | +check_include_files(jack/jack.h USE_JACK) |
| 71 | +if(USE_JACK) |
| 72 | + target_sources(cubeb PRIVATE |
| 73 | + src/cubeb_jack.cpp) |
| 74 | + target_compile_definitions(cubeb PRIVATE USE_JACK) |
| 75 | + target_link_libraries(cubeb PRIVATE jack dl pthread) |
| 76 | +endif() |
| 77 | + |
| 78 | +check_include_files(audioclient.h USE_WASAPI) |
| 79 | +if(USE_WASAPI) |
| 80 | + target_sources(cubeb PRIVATE |
| 81 | + src/cubeb_wasapi.cpp) |
| 82 | + target_compile_definitions(cubeb PRIVATE USE_WASAPI) |
| 83 | +endif() |
| 84 | + |
| 85 | +check_include_files("windows.h;mmsystem.h" USE_WINMM) |
| 86 | +if(USE_WINMM) |
| 87 | + target_sources(cubeb PRIVATE |
| 88 | + src/cubeb_winmm.c) |
| 89 | + target_compile_definitions(cubeb PRIVATE USE_WINMM) |
| 90 | + target_link_libraries(cubeb PRIVATE winmm) |
| 91 | +endif() |
| 92 | + |
| 93 | +check_include_files(SLES/OpenSLES.h USE_OPENSL) |
| 94 | +if(USE_OPENSL) |
| 95 | + target_sources(cubeb PRIVATE |
| 96 | + src/cubeb_opensl.c) |
| 97 | + target_compile_definitions(cubeb PRIVATE USE_OPENSL) |
| 98 | + target_link_libraries(cubeb PRIVATE OpenSLES) |
| 99 | +endif() |
| 100 | + |
| 101 | +check_include_files(android/log.h USE_AUDIOTRACK) |
| 102 | +if(USE_AUDIOTRACK) |
| 103 | + target_sources(cubeb PRIVATE |
| 104 | + src/cubeb_audiotrack.c) |
| 105 | + target_compile_definitions(cubeb PRIVATE USE_AUDIOTRACK) |
| 106 | +endif() |
| 107 | + |
| 108 | +check_include_files(sndio.h USE_SNDIO) |
| 109 | +if(USE_SNDIO) |
| 110 | + target_sources(cubeb PRIVATE |
| 111 | + src/cubeb_sndio.c) |
| 112 | + target_compile_definitions(cubeb PRIVATE USE_SNDIO) |
| 113 | + target_link_libraries(cubeb PRIVATE sndio) |
| 114 | +endif() |
| 115 | + |
| 116 | +check_include_files(kai.h USE_KAI) |
| 117 | +if(USE_KAI) |
| 118 | + target_sources(cubeb PRIVATE |
| 119 | + src/cubeb_kai.c) |
| 120 | + target_compile_definitions(cubeb PRIVATE USE_KAI) |
| 121 | + target_link_libraries(cubeb PRIVATE kai) |
| 122 | +endif() |
| 123 | + |
| 124 | +find_package(Doxygen) |
| 125 | +if(DOXYGEN_FOUND) |
| 126 | + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile @ONLY) |
| 127 | + add_custom_target(doc ALL |
| 128 | + ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile |
| 129 | + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/docs |
| 130 | + COMMENT "Generating API documentation with Doxygen" VERBATIM) |
| 131 | +endif() |
| 132 | + |
| 133 | +enable_testing() |
| 134 | + |
| 135 | +add_executable(test_sanity test/test_sanity.cpp) |
| 136 | +target_link_libraries(test_sanity PRIVATE cubeb) |
| 137 | +add_test(sanity test_sanity) |
| 138 | + |
| 139 | +add_executable(test_tone test/test_tone.cpp) |
| 140 | +target_link_libraries(test_tone PRIVATE cubeb) |
| 141 | +add_test(tone test_tone) |
| 142 | + |
| 143 | +add_executable(test_audio test/test_audio.cpp) |
| 144 | +target_link_libraries(test_audio PRIVATE cubeb) |
| 145 | +add_test(audio test_audio) |
| 146 | + |
| 147 | +add_executable(test_record test/test_record.cpp) |
| 148 | +target_link_libraries(test_record PRIVATE cubeb) |
| 149 | +add_test(record test_record) |
| 150 | + |
| 151 | +add_executable(test_devices test/test_devices.c) |
| 152 | +target_link_libraries(test_devices PRIVATE cubeb) |
| 153 | +add_test(devices test_devices) |
| 154 | + |
| 155 | +add_executable(test_resampler test/test_resampler.cpp src/cubeb_resampler.cpp $<TARGET_OBJECTS:speex>) |
| 156 | +target_include_directories(test_resampler PRIVATE src) |
| 157 | +target_compile_definitions(test_resampler PRIVATE OUTSIDE_SPEEX) |
| 158 | +target_compile_definitions(test_resampler PRIVATE FLOATING_POINT) |
| 159 | +target_compile_definitions(test_resampler PRIVATE EXPORT=) |
| 160 | +target_compile_definitions(test_resampler PRIVATE RANDOM_PREFIX=speex) |
| 161 | +target_link_libraries(test_resampler PRIVATE cubeb) |
| 162 | +add_test(resampler test_resampler) |
| 163 | + |
| 164 | +add_executable(test_duplex test/test_duplex.cpp) |
| 165 | +target_link_libraries(test_duplex PRIVATE cubeb) |
| 166 | +add_test(duplex test_duplex) |
| 167 | + |
| 168 | +add_executable(test_latency test/test_latency.cpp) |
| 169 | +target_link_libraries(test_latency PRIVATE cubeb) |
| 170 | +add_test(latency test_latency) |
| 171 | + |
| 172 | +add_executable(test_ring_array test/test_ring_array.cpp) |
| 173 | +target_include_directories(test_ring_array PRIVATE src) |
| 174 | +target_link_libraries(test_ring_array PRIVATE cubeb) |
| 175 | +add_test(ring_array test_ring_array) |
| 176 | + |
| 177 | +add_executable(test_utils test/test_utils.cpp) |
| 178 | +target_include_directories(test_utils PRIVATE src) |
| 179 | +target_link_libraries(test_utils PRIVATE cubeb) |
| 180 | +add_test(utils test_utils) |
0 commit comments