Skip to content

Commit

Permalink
libsamplerate: Fetch and build from source, vst3 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
timbencker committed Sep 15, 2024
1 parent 1985319 commit 73b9da2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
path = modules/JUCE
url = https://github.com/juce-framework/JUCE.git
shallow = true


27 changes: 2 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<TARGET_FILE_DIR:${TARGET_NAME}>/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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
34 changes: 34 additions & 0 deletions cmake/libsamplerate.cmake
Original file line number Diff line number Diff line change
@@ -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})

0 comments on commit 73b9da2

Please sign in to comment.