From 73b9da24fb8b97e952243b1218ac010fe94936a6 Mon Sep 17 00:00:00 2001 From: timbencker Date: Sun, 15 Sep 2024 14:12:56 +0200 Subject: [PATCH] libsamplerate: Fetch and build from source, vst3 fixed --- .gitmodules | 2 ++ CMakeLists.txt | 27 ++------------------------- README.md | 2 +- cmake/libsamplerate.cmake | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 cmake/libsamplerate.cmake diff --git a/.gitmodules b/.gitmodules index dd06622..972c145 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,5 @@ path = modules/JUCE url = https://github.com/juce-framework/JUCE.git shallow = true + + diff --git a/CMakeLists.txt b/CMakeLists.txt index e19dd44..64fb872 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,32 +128,9 @@ target_compile_definitions(${TARGET_NAME} DONT_SET_USING_JUCE_NAMESPACE=1 ) -# --- SampleRate --- -#target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/modules/libsamplerate-0.2.2-win64/include) -#target_link_libraries(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/modules/libsamplerate-0.2.2-win64/lib/samplerate.lib) -# Set the path where the libsamplerate's CMake config files are located -set(SAMPLERATE_DIR "${CMAKE_CURRENT_LIST_DIR}/modules/libsamplerate-0.2.2-win64/lib/cmake/SampleRate") - -# Use find_package to locate and configure libsamplerate -find_package(SampleRate REQUIRED PATHS ${SAMPLERATE_DIR}) - -if (SampleRate_FOUND) - target_include_directories(${TARGET_NAME} PRIVATE ${SampleRate_INCLUDE_DIRS}) - target_link_libraries(${TARGET_NAME} PRIVATE SampleRate::samplerate) -else() - message(FATAL_ERROR "libsamplerate not found") -endif() - -# Copy samplerate.dll to the output directory after build -set(SAMPLERATE_DLL "${CMAKE_CURRENT_LIST_DIR}/modules/libsamplerate-0.2.2-win64/bin/samplerate.dll") -set(TARGET_DLL_DIR "$/Standalone") - -# Add custom command to ensure directory exists and copy DLL -add_custom_command(TARGET ${TARGET_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SAMPLERATE_DLL}" "${TARGET_DLL_DIR}" - COMMENT "Copying samplerate.dll to Standalone directory" -) +# Include libsamplerate +include(cmake/libsamplerate.cmake) # Add the onnxruntime library diff --git a/README.md b/README.md index bd58816..833063a 100644 --- a/README.md +++ b/README.md @@ -66,5 +66,5 @@ cmake --build cmake-build --config Release This project is subject to multiple licenses. The primary license for the entire project is the GNU General Public License version 3 (GPLv3), which is the most restrictive of all the licenses applied herein. - The Granular Delay module located at ```modules/RnboExport/``` is licensed under the [GPLv3](https://support.cycling74.com/hc/en-us/articles/10730637742483-RNBO-Export-Licensing-FAQ) - All pretrained onnx models located at ```assets/models/``` are licensed under the [Creative Commons Attribution-NonCommercial 4.0 International License](https://github.com/acids-ircam/RAVE/blob/master/LICENSE) - - sampleratelib in `libsamplerate-0.2.2-win64/` is licensed under BSD-2-Clause. + - libsamplerate is licensed under BSD-2-Clause. - All other code within this project is licensed under the MIT License. diff --git a/cmake/libsamplerate.cmake b/cmake/libsamplerate.cmake new file mode 100644 index 0000000..375eed4 --- /dev/null +++ b/cmake/libsamplerate.cmake @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.15) + +set(LIBSAMPLERATE_INSTALL OFF) +set(LIBSAMPLERATE_EXAMPLES OFF) +# libsamplerate itself does not require any dependencies, +# but if you want to build examples and tests, you will need the libsndfile and FFTW libraries +# Find dependencies (e.g., libsndfile if used) +# find_package(SndFile REQUIRED) + +# Define the library name (as defined in libsamplerate's CMakeLists.txt) +set(LIBSAMPLERATE_LIB "samplerate") + +# Check for 32-bit build on Windows +if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4) + message(WARNING "You are trying to compile the project for a 32-bit (Win32) system. This might not work as expected. Please check https://github.com/libsndfile/libsamplerate/blob/master/docs/win32.md") +endif() + +# Download libsamplerate from a remote repository +include(FetchContent) +FetchContent_Declare( + libsamplerate + GIT_REPOSITORY https://github.com/libsndfile/libsamplerate.git + GIT_TAG 0.2.2 # The version of libsamplerate you wish to use +) +FetchContent_MakeAvailable(libsamplerate) + +if(NOT TARGET ${LIBSAMPLERATE_LIB}) + message(FATAL_ERROR "Failed to build or find libsamplerate") +endif() + + +# Used in main CMakeLists.txt to link the target +target_link_libraries(${TARGET_NAME} PRIVATE ${LIBSAMPLERATE_LIB}) +