From d8d86e1a9208589df6dc00e1e8f9928472bc1eba Mon Sep 17 00:00:00 2001 From: Be Date: Mon, 2 Aug 2021 10:37:07 -0500 Subject: [PATCH 1/2] add CMake build system --- CMakeLists.txt | 111 ++++++++++++++++++++++++++++++++++++++ SoundTouchConfig.cmake.in | 8 +++ include/STTypes.h | 2 +- 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 CMakeLists.txt create mode 100644 SoundTouchConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1bddfd9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,111 @@ +cmake_minimum_required(VERSION 3.1) +project(SoundTouch VERSION 2.2.1 LANGUAGES CXX) + +include(GNUInstallDirs) + +add_library(SoundTouch + source/SoundTouch/AAFilter.cpp + source/SoundTouch/BPMDetect.cpp + source/SoundTouch/cpu_detect_x86.cpp + source/SoundTouch/FIFOSampleBuffer.cpp + source/SoundTouch/FIRFilter.cpp + source/SoundTouch/InterpolateCubic.cpp + source/SoundTouch/InterpolateLinear.cpp + source/SoundTouch/InterpolateShannon.cpp + source/SoundTouch/mmx_optimized.cpp + source/SoundTouch/PeakFinder.cpp + source/SoundTouch/RateTransposer.cpp + source/SoundTouch/SoundTouch.cpp + source/SoundTouch/sse_optimized.cpp + source/SoundTouch/TDStretch.cpp +) +target_include_directories(SoundTouch PUBLIC + $ + $ + ) + +option(SOUNDTOUCH_DLL "Build SoundTouchDLL C wrapper library" OFF) +if(SOUNDTOUCH_DLL) + add_library(SoundTouchDLL + source/SoundTouchDLL/SoundTouchDLL.cpp + source/SoundTouchDLL/SoundTouchDLL.rc + ) + install(FILES source/SoundTouchDLL/SoundTouchDLL.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/soundtouch") +endif() + +if(WIN32 AND BUILD_SHARED_LIBS) + set_target_properties(SoundTouch PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) + if(SOUNDTOUCH_DLL) + target_compile_definitions(SoundTouchDLL PRIVATE DLL_EXPORTS) + endif() +endif() + +target_compile_definitions(SoundTouch PRIVATE CMAKE) + +option(INTEGER_SAMPLES "Use integers instead of floats for samples" OFF) +if(INTEGER_SAMPLES) + target_compile_definitions(SoundTouch PRIVATE SOUNDTOUCH_INTEGER_SAMPLES) +else() + target_compile_definitions(SoundTouch PRIVATE SOUNDTOUCH_FLOAT_SAMPLES) +endif() + +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|armv7.*)$") # but not armv8 + set(NEON_DEFAULT ON) +endif() +option(NEON "Use ARM Neon SIMD instructions" NEON_DEFAULT) +if(NEON) + target_compile_definitions(SoundTouch PRIVATE SOUNDTOUCH_USE_NEON) +endif() + +install( + FILES + include/BPMDetect.h + include/FIFOSampleBuffer.h + include/FIFOSamplePipe.h + include/STTypes.h + include/SoundTouch.h + DESTINATION + "${CMAKE_INSTALL_INCLUDEDIR}/soundtouch" +) + +install(TARGETS SoundTouch + EXPORT SoundTouchTargets + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) + +# pkgconfig +set(prefix "${CMAKE_INSTALL_PREFIX}") +set(execprefix "\${prefix}") +set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") +set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") +set(VERSION "${CMAKE_PROJECT_VERSION}") +configure_file(soundtouch.pc.in "${CMAKE_CURRENT_BINARY_DIR}/soundtouch.pc" @ONLY) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/soundtouch.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + +# CMake config +include(CMakePackageConfigHelpers) +set(SOUNDTOUCH_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/SoundTouch") +install( + EXPORT SoundTouchTargets + FILE SoundTouchTargets.cmake + NAMESPACE SoundTouch:: + DESTINATION "${SOUNDTOUCH_INSTALL_CMAKEDIR}" +) +configure_package_config_file(SoundTouchConfig.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/SoundTouchConfig.cmake" + INSTALL_DESTINATION "${SOUNDTOUCH_INSTALL_CMAKEDIR}" +) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/SoundTouchConfigVersion.cmake" + VERSION "${CMAKE_PROJECT_VERSION}" + COMPATIBILITY SameMajorVersion +) +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/SoundTouchConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/SoundTouchConfigVersion.cmake" + DESTINATION "${SOUNDTOUCH_INSTALL_CMAKEDIR}" +) diff --git a/SoundTouchConfig.cmake.in b/SoundTouchConfig.cmake.in new file mode 100644 index 0000000..3e1e494 --- /dev/null +++ b/SoundTouchConfig.cmake.in @@ -0,0 +1,8 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/SoundTouchTargets.cmake") + +check_required_components(SoundTouch) + +get_target_property(SoundTouch_LOCATION SoundTouch::SoundTouch LOCATION) +message(STATUS "Found SoundTouch: ${SoundTouch_LOCATION}") diff --git a/include/STTypes.h b/include/STTypes.h index 71dd0eb..e846dfe 100644 --- a/include/STTypes.h +++ b/include/STTypes.h @@ -47,7 +47,7 @@ typedef unsigned long ulong; #define SOUNDTOUCH_ALIGN_POINTER_16(x) ( ( (ulongptr)(x) + 15 ) & ~(ulongptr)15 ) -#if (defined(__GNUC__) && !defined(ANDROID)) +#if (defined(__GNUC__) && !defined(ANDROID) && !defined(CMAKE)) // In GCC, include soundtouch_config.h made by config scritps. // Skip this in Android compilation that uses GCC but without configure scripts. #include "soundtouch_config.h" From 3617bd166b7ed3f3a94b30f7412f79c9ad792cf9 Mon Sep 17 00:00:00 2001 From: Be Date: Sun, 15 Aug 2021 21:16:41 -0500 Subject: [PATCH 2/2] add build directory to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4269200..fdf5da0 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,5 @@ source/android-lib/local.properties source/android-lib/build source/android-lib/.externalNativeBuild +# CMake build directory +build*