diff options
author | Andrea Pappacoda <[email protected]> | 2021-11-07 00:09:57 +0100 |
---|---|---|
committer | Matthew Gregan <[email protected]> | 2021-11-09 09:38:18 +1300 |
commit | 07c352c65a95cb0ed44353859b83ee494458ca63 (patch) | |
tree | 3e12389671c12685a55b260ae126df084fdd7aaa | |
parent | 5a64bc898cf1823a46aa1d4aa2dc1830e02c69d2 (diff) | |
download | cubeb-07c352c65a95cb0ed44353859b83ee494458ca63.tar.gz cubeb-07c352c65a95cb0ed44353859b83ee494458ca63.zip |
build: use system speex when possible
Following
https://github.com/mozilla/cubeb/issues/658#issuecomment-955998734, the
speex library is now handled like a normal dependency: cubeb will link
against the system version if available, and fall back to the bundled
one if not.
I've also added a BUNDLE_SPEEX option, so that you can force the use of
the bundled library if needed (e.g. creating a standalone libcubeb on a
system where libspeex is available).
I also had to move the bundled library to a separate folder. As `src` is
always added as an include path, the headers in `src/speex` would
conflict with system headers. And it also clears the relationship
between cubeb and speex. I choose the "subprojects" name to follow the
Meson convention, since CMake does not have one. A bit OT, but if you're
curious you can see their rationale here:
https://mesonbuild.com/Subprojects.html#why-must-all-subprojects-be-inside-a-single-directory
Lastly, I added cubeb_log.cpp to the list of sources of test_resampler,
as I was getting linking errors when building with BUILD_SHARED_LIBS=true
Fixes #658
-rw-r--r-- | CMakeLists.txt | 55 | ||||
-rw-r--r-- | subprojects/speex/arch.h (renamed from src/speex/arch.h) | 0 | ||||
-rw-r--r-- | subprojects/speex/fixed_generic.h (renamed from src/speex/fixed_generic.h) | 0 | ||||
-rw-r--r-- | subprojects/speex/resample.c (renamed from src/speex/resample.c) | 0 | ||||
-rw-r--r-- | subprojects/speex/resample_neon.h (renamed from src/speex/resample_neon.h) | 0 | ||||
-rw-r--r-- | subprojects/speex/resample_sse.h (renamed from src/speex/resample_sse.h) | 0 | ||||
-rw-r--r-- | subprojects/speex/speex_config_types.h (renamed from src/speex/speex_config_types.h) | 0 | ||||
-rw-r--r-- | subprojects/speex/speex_resampler.h (renamed from src/speex/speex_resampler.h) | 0 | ||||
-rw-r--r-- | subprojects/speex/stack_alloc.h (renamed from src/speex/stack_alloc.h) | 0 |
9 files changed, 31 insertions, 24 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d505bfc..651953d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(BUILD_TESTS "Build tests" ON) option(BUILD_RUST_LIBS "Build rust backends" OFF) option(BUILD_TOOLS "Build tools" ON) +option(BUNDLE_SPEEX "Bundle the speex library" OFF) option(LAZY_LOAD_LIBS "Lazily load shared libraries" ON) option(USE_SANITIZERS "Use sanitizers" ON) @@ -81,15 +82,10 @@ add_library(cubeb src/cubeb_log.cpp src/cubeb_strings.c src/cubeb_utils.cpp - $<TARGET_OBJECTS:speex>) +) target_include_directories(cubeb PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include> ) -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) set_target_properties(cubeb PROPERTIES VERSION ${cubeb_VERSION} SOVERSION ${cubeb_VERSION_MAJOR} @@ -146,13 +142,30 @@ install( DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" ) -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) +if(NOT BUNDLE_SPEEX) + find_package(PkgConfig) + if(PKG_CONFIG_FOUND) + pkg_check_modules(speexdsp IMPORTED_TARGET speexdsp) + if(speexdsp_FOUND) + add_library(speex ALIAS PkgConfig::speexdsp) + endif() + endif() +endif() + +if(NOT TARGET speex) + add_library(speex STATIC subprojects/speex/resample.c) + set_target_properties(speex PROPERTIES POSITION_INDEPENDENT_CODE TRUE) + target_include_directories(speex INTERFACE subprojects) + target_compile_definitions(speex PUBLIC + OUTSIDE_SPEEX + FLOATING_POINT + EXPORT= + RANDOM_PREFIX=speex + ) +endif() + +# $<BUILD_INTERFACE:> required because of https://gitlab.kitware.com/cmake/cmake/-/issues/15415 +target_link_libraries(cubeb PRIVATE $<BUILD_INTERFACE:speex>) include(CheckIncludeFiles) @@ -366,8 +379,7 @@ if(BUILD_TESTS) 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_include_directories(test_${NAME} PRIVATE ${gtest_SOURCE_DIR}/include src) target_link_libraries(test_${NAME} PRIVATE cubeb gtest_main) add_test(${NAME} test_${NAME}) add_sanitizers(test_${NAME}) @@ -381,14 +393,9 @@ if(BUILD_TESTS) cubeb_add_test(devices) cubeb_add_test(callback_ret) - 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_executable(test_resampler test/test_resampler.cpp src/cubeb_resampler.cpp src/cubeb_log.cpp) + target_include_directories(test_resampler PRIVATE ${gtest_SOURCE_DIR}/include src) + target_link_libraries(test_resampler PRIVATE cubeb gtest_main speex) add_test(resampler test_resampler) add_sanitizers(test_resampler) install(TARGETS test_resampler DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}) @@ -421,7 +428,7 @@ add_custom_target(clang-format-check ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/include -type f (-name "*.cpp" -o -name "*.c" -o -name "*.h") - -not -path "*/src/speex/*" + -not -path "*/subprojects/speex/*" -print0 | xargs -0 clang-format -Werror -n COMMENT "Check formatting with clang-format" diff --git a/src/speex/arch.h b/subprojects/speex/arch.h index 73a45a0..73a45a0 100644 --- a/src/speex/arch.h +++ b/subprojects/speex/arch.h diff --git a/src/speex/fixed_generic.h b/subprojects/speex/fixed_generic.h index 12d27aa..12d27aa 100644 --- a/src/speex/fixed_generic.h +++ b/subprojects/speex/fixed_generic.h diff --git a/src/speex/resample.c b/subprojects/speex/resample.c index 10cb065..10cb065 100644 --- a/src/speex/resample.c +++ b/subprojects/speex/resample.c diff --git a/src/speex/resample_neon.h b/subprojects/speex/resample_neon.h index 0acbd27..0acbd27 100644 --- a/src/speex/resample_neon.h +++ b/subprojects/speex/resample_neon.h diff --git a/src/speex/resample_sse.h b/subprojects/speex/resample_sse.h index fed5b82..fed5b82 100644 --- a/src/speex/resample_sse.h +++ b/subprojects/speex/resample_sse.h diff --git a/src/speex/speex_config_types.h b/subprojects/speex/speex_config_types.h index cea3628..cea3628 100644 --- a/src/speex/speex_config_types.h +++ b/subprojects/speex/speex_config_types.h diff --git a/src/speex/speex_resampler.h b/subprojects/speex/speex_resampler.h index 901de37..901de37 100644 --- a/src/speex/speex_resampler.h +++ b/subprojects/speex/speex_resampler.h diff --git a/src/speex/stack_alloc.h b/subprojects/speex/stack_alloc.h index 6c56334..6c56334 100644 --- a/src/speex/stack_alloc.h +++ b/subprojects/speex/stack_alloc.h |