2016-09-21 16:40:55 +03:00
|
|
|
# TODO
|
|
|
|
# - backend selection via command line, rather than simply detecting headers.
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
|
|
|
|
project(cubeb
|
|
|
|
VERSION 0.0.0)
|
|
|
|
|
2017-02-09 18:00:31 +03:00
|
|
|
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
|
2017-06-08 03:31:41 +03:00
|
|
|
option(BUILD_TESTS "Build tests" ON)
|
2017-02-09 18:00:31 +03:00
|
|
|
|
2016-10-19 22:39:36 +03:00
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
|
|
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
|
|
|
|
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
|
|
|
|
endif()
|
|
|
|
|
2016-09-21 16:40:55 +03:00
|
|
|
if(POLICY CMP0063)
|
|
|
|
cmake_policy(SET CMP0063 NEW)
|
|
|
|
endif()
|
|
|
|
set(CMAKE_C_STANDARD 99)
|
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
|
2017-05-22 07:34:32 +03:00
|
|
|
if(NOT COMMAND add_sanitizers)
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/sanitizers-cmake/cmake")
|
|
|
|
find_package(Sanitizers)
|
|
|
|
if(NOT COMMAND add_sanitizers)
|
|
|
|
message(FATAL_ERROR "Could not find sanitizers-cmake: run\n\tgit submodule update --init --recursive\nin base git checkout")
|
|
|
|
endif()
|
2017-05-15 05:54:35 +03:00
|
|
|
endif()
|
|
|
|
|
2017-06-08 03:31:41 +03:00
|
|
|
if(BUILD_TESTS)
|
|
|
|
if(NOT TARGET gtest_main)
|
|
|
|
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/googletest/CMakeLists.txt")
|
|
|
|
message(FATAL_ERROR "Could not find googletest: run\n\tgit submodule update --init --recursive\nin base git checkout")
|
|
|
|
endif()
|
|
|
|
add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
|
|
|
|
set(gtest_force_shared_crt ON CACHE BOOL "")
|
|
|
|
add_subdirectory(googletest)
|
2017-05-22 07:34:32 +03:00
|
|
|
endif()
|
|
|
|
endif()
|
2016-11-10 05:43:49 +03:00
|
|
|
|
2017-10-20 07:43:40 +03:00
|
|
|
# On OS/2, visibility attribute is not supported.
|
|
|
|
if(NOT OS2)
|
|
|
|
set(CMAKE_C_VISIBILITY_PRESET hidden)
|
|
|
|
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
|
|
|
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
|
|
|
|
endif()
|
2016-09-21 16:40:55 +03:00
|
|
|
|
2016-10-13 05:09:57 +03:00
|
|
|
set(CMAKE_CXX_WARNING_LEVEL 4)
|
|
|
|
if(NOT MSVC)
|
2016-11-14 07:15:27 +03:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter")
|
2016-10-13 05:09:57 +03:00
|
|
|
endif()
|
|
|
|
|
2016-09-21 16:40:55 +03:00
|
|
|
add_library(cubeb
|
|
|
|
src/cubeb.c
|
2016-12-21 08:18:07 +03:00
|
|
|
src/cubeb_mixer.cpp
|
2016-09-21 16:40:55 +03:00
|
|
|
src/cubeb_resampler.cpp
|
|
|
|
src/cubeb_panner.cpp
|
2017-03-14 02:00:31 +03:00
|
|
|
src/cubeb_log.cpp
|
2017-05-15 04:15:20 +03:00
|
|
|
src/cubeb_strings.c
|
2018-03-19 16:57:07 +03:00
|
|
|
src/cubeb_utils.cpp
|
2016-09-21 16:40:55 +03:00
|
|
|
$<TARGET_OBJECTS:speex>)
|
2017-10-20 07:43:40 +03:00
|
|
|
target_include_directories(cubeb
|
|
|
|
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>
|
2017-10-04 13:57:17 +03:00
|
|
|
)
|
2016-09-21 16:40:55 +03:00
|
|
|
target_include_directories(cubeb PRIVATE src)
|
|
|
|
target_compile_definitions(cubeb PRIVATE OUTSIDE_SPEEX)
|
|
|
|
target_compile_definitions(cubeb PRIVATE FLOATING_POINT)
|
|
|
|
target_compile_definitions(cubeb PRIVATE EXPORT=)
|
|
|
|
target_compile_definitions(cubeb PRIVATE RANDOM_PREFIX=speex)
|
|
|
|
|
2017-05-19 10:06:38 +03:00
|
|
|
add_sanitizers(cubeb)
|
|
|
|
|
2016-09-21 16:40:55 +03:00
|
|
|
include(GenerateExportHeader)
|
|
|
|
generate_export_header(cubeb EXPORT_FILE_NAME ${CMAKE_BINARY_DIR}/exports/cubeb_export.h)
|
2017-10-20 07:43:40 +03:00
|
|
|
target_include_directories(cubeb
|
2017-10-04 13:57:17 +03:00
|
|
|
PUBLIC $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/exports>
|
|
|
|
)
|
2016-09-21 16:40:55 +03:00
|
|
|
|
2018-07-22 20:03:32 +03:00
|
|
|
if(UNIX)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
else()
|
|
|
|
set(CMAKE_INSTALL_LIBDIR "lib")
|
|
|
|
set(CMAKE_INSTALL_BINDIR "bin")
|
|
|
|
set(CMAKE_INSTALL_DATADIR "share")
|
|
|
|
set(CMAKE_INSTALL_DOCDIR "${CMAKE_INSTALL_DATADIR}/doc")
|
|
|
|
set(CMAKE_INSTALL_INCLUDEDIR "include")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
|
|
install(DIRECTORY ${CMAKE_BINARY_DIR}/exports/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
|
2017-06-08 03:31:41 +03:00
|
|
|
|
2017-10-04 13:57:17 +03:00
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
write_basic_package_version_file(
|
|
|
|
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
|
|
|
COMPATIBILITY SameMajorVersion
|
|
|
|
)
|
|
|
|
|
|
|
|
configure_package_config_file(
|
|
|
|
"Config.cmake.in"
|
|
|
|
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
2018-07-22 20:03:32 +03:00
|
|
|
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
2017-10-04 13:57:17 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
install(TARGETS cubeb
|
2017-10-20 07:43:40 +03:00
|
|
|
EXPORT "${PROJECT_NAME}Targets"
|
2017-10-04 13:57:17 +03:00
|
|
|
DESTINATION ${CMAKE_INSTALL_PREFIX}
|
2018-07-22 20:03:32 +03:00
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
2017-10-04 13:57:17 +03:00
|
|
|
)
|
|
|
|
install(
|
|
|
|
FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
2018-07-22 20:03:32 +03:00
|
|
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
2017-10-04 13:57:17 +03:00
|
|
|
)
|
|
|
|
install(
|
|
|
|
EXPORT "${PROJECT_NAME}Targets"
|
|
|
|
NAMESPACE "${PROJECT_NAME}::"
|
2018-07-22 20:03:32 +03:00
|
|
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
2017-10-04 13:57:17 +03:00
|
|
|
)
|
|
|
|
|
2016-09-21 16:40:55 +03:00
|
|
|
add_library(speex OBJECT
|
|
|
|
src/speex/resample.c)
|
|
|
|
set_target_properties(speex PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
|
|
|
|
target_compile_definitions(speex PRIVATE OUTSIDE_SPEEX)
|
|
|
|
target_compile_definitions(speex PRIVATE FLOATING_POINT)
|
|
|
|
target_compile_definitions(speex PRIVATE EXPORT=)
|
|
|
|
target_compile_definitions(speex PRIVATE RANDOM_PREFIX=speex)
|
|
|
|
|
|
|
|
include(CheckIncludeFiles)
|
|
|
|
|
|
|
|
check_include_files(AudioUnit/AudioUnit.h USE_AUDIOUNIT)
|
|
|
|
if(USE_AUDIOUNIT)
|
|
|
|
target_sources(cubeb PRIVATE
|
|
|
|
src/cubeb_audiounit.cpp
|
2016-10-06 18:18:30 +03:00
|
|
|
src/cubeb_osx_run_loop.cpp)
|
2016-09-21 16:40:55 +03:00
|
|
|
target_compile_definitions(cubeb PRIVATE USE_AUDIOUNIT)
|
|
|
|
target_link_libraries(cubeb PRIVATE "-framework AudioUnit" "-framework CoreAudio" "-framework CoreServices")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
check_include_files(pulse/pulseaudio.h USE_PULSE)
|
|
|
|
if(USE_PULSE)
|
|
|
|
target_sources(cubeb PRIVATE
|
|
|
|
src/cubeb_pulse.c)
|
|
|
|
target_compile_definitions(cubeb PRIVATE USE_PULSE)
|
2017-07-30 23:54:50 +03:00
|
|
|
target_link_libraries(cubeb PRIVATE pulse)
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
|
|
|
target_link_libraries(cubeb PRIVATE dl)
|
|
|
|
endif()
|
2016-09-21 16:40:55 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
check_include_files(alsa/asoundlib.h USE_ALSA)
|
|
|
|
if(USE_ALSA)
|
|
|
|
target_sources(cubeb PRIVATE
|
|
|
|
src/cubeb_alsa.c)
|
|
|
|
target_compile_definitions(cubeb PRIVATE USE_ALSA)
|
2017-07-30 23:54:50 +03:00
|
|
|
target_link_libraries(cubeb PRIVATE asound pthread)
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
|
|
|
target_link_libraries(cubeb PRIVATE dl)
|
|
|
|
endif()
|
2016-09-21 16:40:55 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
check_include_files(jack/jack.h USE_JACK)
|
|
|
|
if(USE_JACK)
|
|
|
|
target_sources(cubeb PRIVATE
|
|
|
|
src/cubeb_jack.cpp)
|
|
|
|
target_compile_definitions(cubeb PRIVATE USE_JACK)
|
2017-07-30 23:54:50 +03:00
|
|
|
target_link_libraries(cubeb PRIVATE jack pthread)
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
|
|
|
target_link_libraries(cubeb PRIVATE dl)
|
|
|
|
endif()
|
2016-09-21 16:40:55 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
check_include_files(audioclient.h USE_WASAPI)
|
|
|
|
if(USE_WASAPI)
|
|
|
|
target_sources(cubeb PRIVATE
|
|
|
|
src/cubeb_wasapi.cpp)
|
|
|
|
target_compile_definitions(cubeb PRIVATE USE_WASAPI)
|
2017-02-08 04:19:28 +03:00
|
|
|
target_link_libraries(cubeb PRIVATE avrt)
|
2016-09-21 16:40:55 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
check_include_files("windows.h;mmsystem.h" USE_WINMM)
|
|
|
|
if(USE_WINMM)
|
|
|
|
target_sources(cubeb PRIVATE
|
|
|
|
src/cubeb_winmm.c)
|
|
|
|
target_compile_definitions(cubeb PRIVATE USE_WINMM)
|
|
|
|
target_link_libraries(cubeb PRIVATE winmm)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
check_include_files(SLES/OpenSLES.h USE_OPENSL)
|
|
|
|
if(USE_OPENSL)
|
|
|
|
target_sources(cubeb PRIVATE
|
2018-02-19 18:50:15 +03:00
|
|
|
src/cubeb_opensl.c
|
|
|
|
src/cubeb-jni.cpp)
|
2016-09-21 16:40:55 +03:00
|
|
|
target_compile_definitions(cubeb PRIVATE USE_OPENSL)
|
|
|
|
target_link_libraries(cubeb PRIVATE OpenSLES)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
check_include_files(android/log.h USE_AUDIOTRACK)
|
|
|
|
if(USE_AUDIOTRACK)
|
|
|
|
target_sources(cubeb PRIVATE
|
|
|
|
src/cubeb_audiotrack.c)
|
|
|
|
target_compile_definitions(cubeb PRIVATE USE_AUDIOTRACK)
|
2016-11-18 08:32:21 +03:00
|
|
|
target_link_libraries(cubeb PRIVATE log)
|
2016-09-21 16:40:55 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
check_include_files(sndio.h USE_SNDIO)
|
|
|
|
if(USE_SNDIO)
|
|
|
|
target_sources(cubeb PRIVATE
|
|
|
|
src/cubeb_sndio.c)
|
|
|
|
target_compile_definitions(cubeb PRIVATE USE_SNDIO)
|
|
|
|
target_link_libraries(cubeb PRIVATE sndio)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
check_include_files(kai.h USE_KAI)
|
|
|
|
if(USE_KAI)
|
|
|
|
target_sources(cubeb PRIVATE
|
|
|
|
src/cubeb_kai.c)
|
|
|
|
target_compile_definitions(cubeb PRIVATE USE_KAI)
|
|
|
|
target_link_libraries(cubeb PRIVATE kai)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_package(Doxygen)
|
|
|
|
if(DOXYGEN_FOUND)
|
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile @ONLY)
|
|
|
|
add_custom_target(doc ALL
|
|
|
|
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/docs
|
|
|
|
COMMENT "Generating API documentation with Doxygen" VERBATIM)
|
|
|
|
endif()
|
|
|
|
|
2017-06-08 03:31:41 +03:00
|
|
|
if(BUILD_TESTS)
|
|
|
|
enable_testing()
|
|
|
|
|
|
|
|
macro(cubeb_add_test NAME)
|
|
|
|
add_executable(test_${NAME} test/test_${NAME}.cpp)
|
|
|
|
target_include_directories(test_${NAME} PRIVATE ${gtest_SOURCE_DIR}/include)
|
|
|
|
target_include_directories(test_${NAME} PRIVATE src)
|
|
|
|
target_link_libraries(test_${NAME} PRIVATE cubeb gtest_main)
|
|
|
|
add_test(${NAME} test_${NAME})
|
|
|
|
add_sanitizers(test_${NAME})
|
2018-07-22 20:03:32 +03:00
|
|
|
install(TARGETS test_${NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})
|
2017-06-08 03:31:41 +03:00
|
|
|
endmacro(cubeb_add_test)
|
|
|
|
|
|
|
|
cubeb_add_test(sanity)
|
|
|
|
cubeb_add_test(tone)
|
|
|
|
cubeb_add_test(audio)
|
|
|
|
cubeb_add_test(record)
|
|
|
|
cubeb_add_test(devices)
|
2018-02-05 19:09:51 +03:00
|
|
|
cubeb_add_test(callback_ret)
|
2017-06-08 03:31:41 +03:00
|
|
|
|
|
|
|
add_executable(test_resampler test/test_resampler.cpp src/cubeb_resampler.cpp $<TARGET_OBJECTS:speex>)
|
|
|
|
target_include_directories(test_resampler PRIVATE ${gtest_SOURCE_DIR}/include)
|
|
|
|
target_include_directories(test_resampler PRIVATE src)
|
|
|
|
target_compile_definitions(test_resampler PRIVATE OUTSIDE_SPEEX)
|
|
|
|
target_compile_definitions(test_resampler PRIVATE FLOATING_POINT)
|
|
|
|
target_compile_definitions(test_resampler PRIVATE EXPORT=)
|
|
|
|
target_compile_definitions(test_resampler PRIVATE RANDOM_PREFIX=speex)
|
|
|
|
target_link_libraries(test_resampler PRIVATE cubeb gtest_main)
|
|
|
|
add_test(resampler test_resampler)
|
|
|
|
add_sanitizers(test_resampler)
|
2018-07-22 20:03:32 +03:00
|
|
|
install(TARGETS test_resampler DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})
|
2017-06-08 03:31:41 +03:00
|
|
|
|
|
|
|
cubeb_add_test(duplex)
|
|
|
|
|
|
|
|
if (USE_WASAPI)
|
|
|
|
cubeb_add_test(overload_callback)
|
2017-11-21 17:31:36 +03:00
|
|
|
cubeb_add_test(loopback)
|
2017-06-08 03:31:41 +03:00
|
|
|
endif()
|
2017-04-07 13:23:11 +03:00
|
|
|
|
2017-06-08 03:31:41 +03:00
|
|
|
cubeb_add_test(latency test_latency)
|
|
|
|
cubeb_add_test(ring_array)
|
|
|
|
|
|
|
|
cubeb_add_test(utils)
|
|
|
|
cubeb_add_test(ring_buffer)
|
2017-04-07 13:23:11 +03:00
|
|
|
endif()
|