From cc8a3c38e8021fc6903044a270047fddeb9b77db Mon Sep 17 00:00:00 2001 From: timbencker Date: Sun, 15 Sep 2024 17:26:02 +0200 Subject: [PATCH] Chore: CMakeLists - Cleanup and Outfactor --- CMakeLists.txt | 269 ++---------------- cmake/add_source_files.cmake | 28 ++ cmake/configure_platform.cmake | 19 ++ ...ug.cmake => download_onnx_win_debug.cmake} | 0 cmake/juce_compile_config.cmake | 41 +++ cmake/juce_plugin_setup.cmake | 51 ++++ ...lerate.cmake => setup_libsamplerate.cmake} | 4 + cmake/setup_onnx_runtime.cmake | 42 +++ cmake/setup_tests_and_benchmarks.cmake | 57 ++++ 9 files changed, 263 insertions(+), 248 deletions(-) create mode 100644 cmake/add_source_files.cmake create mode 100644 cmake/configure_platform.cmake rename cmake/{onnx-win-x86_64_debug.cmake => download_onnx_win_debug.cmake} (100%) create mode 100644 cmake/juce_compile_config.cmake create mode 100644 cmake/juce_plugin_setup.cmake rename cmake/{libsamplerate.cmake => setup_libsamplerate.cmake} (83%) create mode 100644 cmake/setup_onnx_runtime.cmake create mode 100644 cmake/setup_tests_and_benchmarks.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 64fb872..afab62e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,177 +1,34 @@ -# The first line of any CMake project should be a call to `cmake_minimum_required`, which checks -# that the installed CMake will be able to understand the following CMakeLists, and ensures that -# CMake's behaviour is compatible with the named version. This is a standard CMake command, so more -# information can be found in the CMake docs. - cmake_minimum_required(VERSION 3.24) -# Sets the minimum macOS version -if (APPLE) - set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "Minimum version of the target platform" FORCE) - if(CMAKE_OSX_DEPLOYMENT_TARGET) - message("The minimum macOS version is set to " $CACHE{CMAKE_OSX_DEPLOYMENT_TARGET}.) - endif() -endif () - -# The top-level CMakeLists.txt file for a project must contain a literal, direct call to the -# `project()` command. `project()` sets up some helpful variables that describe source/binary -# directories, and the current project version. This is a standard CMake command. - +# The top-level CMakeLists.txt file for a project must contain a literal, direct call to the `project()` command. +# `project()` sets up some helpful variables that describe source/binary directories, and the current project version. project(Scyclone VERSION 0.0.3) set (TARGET_NAME ${PROJECT_NAME}) -if(APPLE) - set (FORMATS_TO_BUILD AU VST3 Standalone) -else() - set (FORMATS_TO_BUILD VST3 Standalone) -endif() - -#static linking runtime library in Windows (for onnxruntime) -set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - -add_subdirectory(modules/JUCE) # If you've put JUCE in a subdirectory called JUCE - -# If you are building a VST2 or AAX plugin, CMake needs to be told where to find these SDKs on your -# system. This setup should be done before calling `juce_add_plugin`. +include(cmake/configure_platform.cmake) -# juce_set_vst2_sdk_path(...) -# juce_set_aax_sdk_path(...) +# Add JUCE module +add_subdirectory(modules/JUCE) +# JUCE plugin setup +include(cmake/juce_plugin_setup.cmake) -# `juce_add_plugin` adds a static library target with the name passed as the first argument -# (Scyclone here). This target is a normal CMake target, but has a lot of extra properties set -# up by default. As well as this shared code static library, this function adds targets for each of -# the formats specified by the FORMATS arguments. This function accepts many optional arguments. -# Check the readme at `docs/CMake API.md` in the JUCE repo for the full list. -juce_add_plugin(${TARGET_NAME} - # VERSION ... # Set this if the plugin version is different to the project version - # ICON_BIG ... # ICON_* arguments specify a path to an image file to use as an icon for the Standalone - # ICON_SMALL ... - COMPANY_NAME "Torsion Audio" - # IS_SYNTH TRUE/FALSE # Is this a synth or an effect? - # NEEDS_MIDI_INPUT TRUE/FALSE # Does the plugin need midi input? - # NEEDS_MIDI_OUTPUT TRUE/FALSE # Does the plugin need midi output? - # IS_MIDI_EFFECT TRUE/FALSE # Is this plugin a MIDI effect? - # EDITOR_WANTS_KEYBOARD_FOCUS TRUE/FALSE # Does the editor need keyboard focus? - # COPY_PLUGIN_AFTER_BUILD TRUE/FALSE # Should the plugin be installed to a default location after building? - PLUGIN_MANUFACTURER_CODE TORA # A four-character manufacturer id with at least one upper-case character - PLUGIN_CODE SCYC # A unique four-character plugin id with exactly one upper-case character - # GarageBand 10.3 requires the first letter to be upper-case, and the remaining letters to be lower-case +# ONNX Runtime and libsamplerate +include(cmake/setup_onnx_runtime.cmake) +include(cmake/setup_libsamplerate.cmake) - if(APPLE) - HARDENED_RUNTIME_ENABLED TRUE - HARDENED_RUNTIME_OPTIONS "com.apple.security.device.audio-input" - MICROPHONE_PERMISSION_ENABLED TRUE - MICROPHONE_PERMISSION_TEXT "Need access to your audio interface" - endif() +# Tests and Benchmarks +include(cmake/setup_tests_and_benchmarks.cmake) - FORMATS ${FORMATS_TO_BUILD} # The formats to build. Other valid formats are: AAX Unity VST AU AUv3 - PRODUCT_NAME "Scyclone" # The name of the final executable, which can differ from the target name - ) - -# `juce_generate_juce_header` will create a JuceHeader.h for a given target, which will be generated -# into your build tree. This should be included with `#include `. The include path for -# this header will be automatically added to the target. The main function of the JuceHeader is to -# include all your JUCE module headers; if you're happy to include module headers directly, you -# probably don't need to call this. - -juce_generate_juce_header(${TARGET_NAME}) - -# Sets the cpp language minimum -set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD 20) -set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) - -# Export only public symbols -# We set this option for all our libraries since the onnxruntime lib and the google benchmark lib are setup with hidden visibility this otherwise we get linker warnings that say ... means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings -set(CMAKE_CXX_VISIBILITY_PRESET hidden) -set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) +# JUCE compile definitions and linking +include(cmake/juce_compile_config.cmake) +# Add Installer and RNBO +add_subdirectory(installer) add_subdirectory(modules/RnboExport) -# Add all source files to file list -file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/source/*.h) -# list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_LIST_DIR}/source/ui/CustomComponents/OpenGLBackground/OpenGLUtil/OpenGLUtil.h) - -# Add all sources to target -target_sources(${TARGET_NAME} PRIVATE ${SOURCES} ${RNBO_SOURCES}) - -# Add include directories for all folders in the source -file(GLOB_RECURSE source_dirs LIST_DIRECTORIES true ${CMAKE_CURRENT_LIST_DIR}/source/*) -list(APPEND source_dirs ${CMAKE_CURRENT_LIST_DIR}/source) - -foreach (dir ${source_dirs}) -if (IS_DIRECTORY ${dir}) - target_include_directories(${TARGET_NAME} PRIVATE ${dir}) - endif () -endforeach () - -target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/modules/onnxruntime/include) - -# Make the folder structure visible in the IDE -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/source PREFIX "source" FILES ${SOURCES}) -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/modules PREFIX "modules" FILES ${RNBO_SOURCES}) - -# `target_compile_definitions` adds some preprocessor definitions to our target. In a Projucer -# project, these might be passed in the 'Preprocessor Definitions' field. JUCE modules also make use -# of compile definitions to switch certain features on/off, so if there's a particular feature you -# need that's not on by default, check the module header for the correct flag to set here. These -# definitions will be visible both to your code, and also the JUCE module code, so for new -# definitions, pick unique names that are unlikely to collide! This is a standard CMake command. - -target_compile_definitions(${TARGET_NAME} - PRIVATE - # JUCE_WEB_BROWSER and JUCE_USE_CURL would be on by default, but you might not need them. - JUCE_WEB_BROWSER=0 # If you remove this, add `NEEDS_WEB_BROWSER TRUE` to the `juce_add_plugin` call - JUCE_USE_CURL=0 # If you remove this, add `NEEDS_CURL TRUE` to the `juce_add_plugin` call - JUCE_VST3_CAN_REPLACE_VST2=0 - JUCE_DISPLAY_SPLASH_SCREEN=0 - DONT_SET_USING_JUCE_NAMESPACE=1 - ) - - -# Include libsamplerate -include(cmake/libsamplerate.cmake) - - -# Add the onnxruntime library -add_library(onnxruntime STATIC IMPORTED) - -if (APPLE) - message(STATUS ${CMAKE_HOST_SYSTEM_PROCESSOR}) - if (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") - set_property(TARGET onnxruntime PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/modules/onnxruntime/lib/onnxruntime-osx-x64.a) - elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64") - set_property(TARGET onnxruntime PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/modules/onnxruntime/lib/onnxruntime-osx-arm64.a) - set_property(TARGET onnxruntime PROPERTY CXX_VISIBILITY_PRESET default) - else() - message(FATAL_ERROR "CMAKE_HOST_SYSTEM_PROCESSOR not defined.") - endif() -elseif (MSVC) - include(cmake/onnx-win-x86_64_debug.cmake) - - set_property(TARGET onnxruntime APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) - set_target_properties(onnxruntime PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX" - IMPORTED_LOCATION_RELEASE "${CMAKE_CURRENT_LIST_DIR}/modules/onnxruntime/lib/onnxruntime-win-x64.lib" - ) - set_target_properties(onnxruntime PROPERTIES - MAP_IMPORTED_CONFIG_DEBUG Release - MAP_IMPORTED_CONFIG_MINSIZEREL Release - MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release - ) - - set_property(TARGET onnxruntime APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) - set_target_properties(onnxruntime PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX" - IMPORTED_LOCATION_DEBUG "${CMAKE_CURRENT_LIST_DIR}/modules/onnxruntime-1.14.1-win-x86_64_Debug/onnxruntime-1.14.1-win-x86_64_Debug.lib" - ) - set_target_properties(onnxruntime PROPERTIES - MAP_IMPORTED_CONFIG_DEBUG Debug - ) -elseif(LINUX) - set_property(TARGET onnxruntime PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/modules/onnxruntime/lib/onnxruntime-linux_x86_64-static-combined.a) -endif() - +# Add all source files to file list. Todo RNBO and ONNX still partially in here +include(cmake/add_source_files.cmake) # If your target needs extra binary assets, you can add them here. The first argument is the name of # a new static library target that will include all the binary resources. There is an optional @@ -179,38 +36,10 @@ endif() # the SOURCES argument should be followed by a list of source files that should be built into the # static library. These source files can be of any kind (wav data, images, fonts, icons etc.). # Conversion to binary-data will happen when your target is built. - add_subdirectory(assets) -# `target_link_libraries` links libraries and JUCE modules to other libraries or executables. Here, -# we're linking our executable target to the `juce::juce_audio_utils` module. Inter-module -# dependencies are resolved automatically, so `juce_core`, `juce_events` and so on will also be -# linked automatically. If we'd generated a binary data target above, we would need to link to it -# here too. This is a standard CMake command. - -target_link_libraries(${TARGET_NAME} - PRIVATE - BinaryData - juce::juce_audio_utils - juce::juce_dsp - juce::juce_opengl - juce::juce_graphics - juce::juce_gui_basics - juce::juce_gui_extra - juce::juce_audio_basics - onnxruntime - - PUBLIC - juce::juce_recommended_config_flags - juce::juce_recommended_lto_flags - juce::juce_recommended_warning_flags -) - -add_subdirectory(installer) - # enable ctest enable_testing() - # this is a test on application level starting the app and checking if it is running # add_test(NAME RegularUsage COMMAND "Scyclone_artefacts/Debug/Standalone/Scyclone.app/Contents/MacOS/Scyclone") # we can specify som REGEX to check the output of the application @@ -218,66 +47,10 @@ enable_testing() # PROPERTIES FAIL_REGULAR_EXPRESSION "Custom Slider Component" # ) -# get all test cpp and header files -file(GLOB_RECURSE TestFiles CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/test/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/test/*.h") -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/test PREFIX "" FILES ${TestFiles}) - -# This module enables populating content at configure time via any method supported by the ExternalProject module. Whereas ExternalProject_Add() downloads at build time, the FetchContent module makes content available immediately, allowing the configure step to use the content in commands like add_subdirectory(), include() or file() operations. -include(FetchContent) - -# Externally provided libraries -# Using zip files instead is faster -FetchContent_Declare(googletest - URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip) - -FetchContent_Declare(benchmark - GIT_REPOSITORY https://github.com/google/benchmark.git - GIT_TAG v1.8.0) - -# This command ensures that each of the named dependencies are made available to the project by the time it returns. If the dependency has already been populated the command does nothing. Otherwise, the command populates the dependency and then calls add_subdirectory() on the result. -FetchContent_MakeAvailable(googletest) - -# For benchmark we want to set the BENCMARK_ENABLE_TESTING to OFF therefore we cannot use FetchContent_MakeAvailable() -# Check if population has already been performed -FetchContent_GetProperties(benchmark) -if(NOT benchmark_POPULATED) - # Fetch the content using previously declared details - FetchContent_Populate(benchmark) - - # Set custom variables, policies, etc. - set(BENCHMARK_ENABLE_TESTING OFF) - - # Bring the populated content into the build - add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR}) -endif() - -# Setup the test executable -add_executable(Test ${TestFiles}) -set_property(TARGET Test PROPERTY CXX_STANDARD 20) - -# Link the test executable against gtest_main and google benchmark -target_link_libraries(Test PRIVATE gtest_main benchmark::benchmark "${TARGET_NAME}") - -# We can't link again to the shared juce target without ODL violations (https://github.com/sudara/pamplejuce/issues/31, https://forum.juce.com/t/windows-linker-issue-on-develop/55524/2) -# Therefore we steal the compile definitions and include directories from the main target and pass them to our test target -# Since we linked the shared juce targets in PRIVATE mode, they are not linked to the test target again -target_compile_definitions(Test PRIVATE $) -target_include_directories(Test PRIVATE $) - -# Make an Xcode Scheme for the test executable so we can run Test in the IDE -set_target_properties(Test PROPERTIES XCODE_GENERATE_SCHEME ON) - -# Organize the test source in the test/ folder in the IDE -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/test PREFIX "" FILES ${TestFiles}) - -# include Loads and runs CMake code from the file given. Loads and runs CMake code from the file given. -include(GoogleTest) -# gtest_discover_tests will register a CTest test for each gtest and run them all in parallel with the rest of the Test. -gtest_discover_tests(Test) # Color our warnings and errors if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - add_compile_options (-fdiagnostics-color=always) + add_compile_options (-fdiagnostics-color=always) elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_compile_options (-fcolor-diagnostics) -endif () \ No newline at end of file + add_compile_options (-fcolor-diagnostics) +endif() diff --git a/cmake/add_source_files.cmake b/cmake/add_source_files.cmake new file mode 100644 index 0000000..d06656d --- /dev/null +++ b/cmake/add_source_files.cmake @@ -0,0 +1,28 @@ +# Collect all source files (.cpp and .h) in the 'source' directory +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/source/*.h +) + +# list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/source/ui/CustomComponents/OpenGLBackground/OpenGLUtil/OpenGLUtil.h) + +# Add all sources to target +target_sources(${TARGET_NAME} PRIVATE ${SOURCES} ${RNBO_SOURCES}) + +# Add include directories for all folders in the source +file(GLOB_RECURSE SOURCE_DIRS LIST_DIRECTORIES true + ${CMAKE_CURRENT_SOURCE_DIR}/source/* +) +list(APPEND SOURCE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/source) + +# Add include directories for all directories found in 'source' +target_include_directories(${TARGET_NAME} PRIVATE + ${SOURCE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}/modules/onnxruntime/include +) + +target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/modules/onnxruntime/include) + +# Make the folder structure visible in the IDE +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/source PREFIX "source" FILES ${SOURCES}) +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/modules PREFIX "modules" FILES ${RNBO_SOURCES}) \ No newline at end of file diff --git a/cmake/configure_platform.cmake b/cmake/configure_platform.cmake new file mode 100644 index 0000000..df0231c --- /dev/null +++ b/cmake/configure_platform.cmake @@ -0,0 +1,19 @@ +# Platform-specific settings +if(APPLE) + set(MIN_MACOS_VERSION "10.13") + set(CMAKE_OSX_DEPLOYMENT_TARGET ${MIN_MACOS_VERSION} CACHE STRING "Minimum version of the target platform" FORCE) + + # Check if the current deployment target is at least the minimum required version + if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS MIN_MACOS_VERSION) + message(FATAL_ERROR "macOS deployment target is too old. Minimum required version is ${MIN_MACOS_VERSION}. Current target: ${CMAKE_OSX_DEPLOYMENT_TARGET}") + endif() + + set(FORMATS_TO_BUILD AU VST3 Standalone) +else() + set(FORMATS_TO_BUILD VST3 Standalone) +endif() + +# MSVC runtime linking +if(MSVC) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") #static linking runtime library in Windows (for onnxruntime) +endif() \ No newline at end of file diff --git a/cmake/onnx-win-x86_64_debug.cmake b/cmake/download_onnx_win_debug.cmake similarity index 100% rename from cmake/onnx-win-x86_64_debug.cmake rename to cmake/download_onnx_win_debug.cmake diff --git a/cmake/juce_compile_config.cmake b/cmake/juce_compile_config.cmake new file mode 100644 index 0000000..e16d8fa --- /dev/null +++ b/cmake/juce_compile_config.cmake @@ -0,0 +1,41 @@ + +# `target_compile_definitions` adds some preprocessor definitions to our target. In a Projucer +# project, these might be passed in the 'Preprocessor Definitions' field. JUCE modules also make use +# of compile definitions to switch certain features on/off, so if there's a particular feature you +# need that's not on by default, check the module header for the correct flag to set here. These +# definitions will be visible both to your code, and also the JUCE module code, so for new +# definitions, pick unique names that are unlikely to collide! This is a standard CMake command. + +target_compile_definitions(${TARGET_NAME} + PRIVATE + # JUCE_WEB_BROWSER and JUCE_USE_CURL would be on by default, but you might not need them. + JUCE_WEB_BROWSER=0 # If you remove this, add `NEEDS_WEB_BROWSER TRUE` to the `juce_add_plugin` call + JUCE_USE_CURL=0 # If you remove this, add `NEEDS_CURL TRUE` to the `juce_add_plugin` call + JUCE_VST3_CAN_REPLACE_VST2=0 + JUCE_DISPLAY_SPLASH_SCREEN=0 + DONT_SET_USING_JUCE_NAMESPACE=1 +) + + +# `target_link_libraries` links libraries and JUCE modules to other libraries or executables. Here, +# we're linking our executable target to the `juce::juce_audio_utils` module. Inter-module +# dependencies are resolved automatically, so `juce_core`, `juce_events` and so on will also be +# linked automatically. If we'd generated a binary data target above, we would need to link to it +# here too. This is a standard CMake command. + +target_link_libraries(${TARGET_NAME} + PRIVATE + BinaryData + juce::juce_audio_utils + juce::juce_dsp + juce::juce_opengl + juce::juce_graphics + juce::juce_gui_basics + juce::juce_gui_extra + juce::juce_audio_basics + + PUBLIC + juce::juce_recommended_config_flags + juce::juce_recommended_lto_flags + juce::juce_recommended_warning_flags +) diff --git a/cmake/juce_plugin_setup.cmake b/cmake/juce_plugin_setup.cmake new file mode 100644 index 0000000..2e79573 --- /dev/null +++ b/cmake/juce_plugin_setup.cmake @@ -0,0 +1,51 @@ +# If you are building a VST2 or AAX plugin, CMake needs to be told where to find these SDKs on your +# system. This setup should be done before calling `juce_add_plugin`. +# juce_set_vst2_sdk_path(...) +# juce_set_aax_sdk_path(...) + + +# `juce_add_plugin` adds a static library target with the name passed as the first argument +# (Scyclone here). This target is a normal CMake target, but has a lot of extra properties set +# up by default. As well as this shared code static library, this function adds targets for each of +# the formats specified by the FORMATS arguments. This function accepts many optional arguments. +# Check the readme at `docs/CMake API.md` in the JUCE repo for the full list. + +juce_add_plugin(${TARGET_NAME} + # VERSION ... # Set this if the plugin version is different to the project version + # ICON_BIG ... # ICON_* arguments specify a path to an image file to use as an icon for the Standalone + # ICON_SMALL ... + COMPANY_NAME "Torsion Audio" + # IS_SYNTH TRUE/FALSE # Is this a synth or an effect? + # NEEDS_MIDI_INPUT TRUE/FALSE # Does the plugin need midi input? + # NEEDS_MIDI_OUTPUT TRUE/FALSE # Does the plugin need midi output? + # IS_MIDI_EFFECT TRUE/FALSE # Is this plugin a MIDI effect? + # EDITOR_WANTS_KEYBOARD_FOCUS TRUE/FALSE # Does the editor need keyboard focus? + # COPY_PLUGIN_AFTER_BUILD TRUE/FALSE # Should the plugin be installed to a default location after building? + PLUGIN_MANUFACTURER_CODE TORA # A four-character manufacturer id with at least one upper-case character + PLUGIN_CODE SCYC # A unique four-character plugin id with exactly one upper-case character + # GarageBand 10.3 requires the first letter to be upper-case, and the remaining letters to be lower-case + + if(APPLE) + HARDENED_RUNTIME_ENABLED TRUE + HARDENED_RUNTIME_OPTIONS "com.apple.security.device.audio-input" + MICROPHONE_PERMISSION_ENABLED TRUE + MICROPHONE_PERMISSION_TEXT "Need access to your audio interface" + endif() + + FORMATS ${FORMATS_TO_BUILD} # The formats to build. Other valid formats are: AAX Unity VST AU AUv3 + PRODUCT_NAME "Scyclone" # The name of the final executable, which can differ from the target name +) + +# JUCE Headers and definitions +juce_generate_juce_header(${TARGET_NAME}) + +# Now we can set the properties +set_target_properties(${TARGET_NAME} PROPERTIES + CXX_STANDARD 20 + CXX_STANDARD_REQUIRED ON + + # Export only public symbols + # We set this option for all our libraries since the onnxruntime lib and the google benchmark lib are setup with hidden visibility this otherwise we get linker warnings that say ... means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN ON +) \ No newline at end of file diff --git a/cmake/libsamplerate.cmake b/cmake/setup_libsamplerate.cmake similarity index 83% rename from cmake/libsamplerate.cmake rename to cmake/setup_libsamplerate.cmake index ab2e072..3a0c1cd 100644 --- a/cmake/libsamplerate.cmake +++ b/cmake/setup_libsamplerate.cmake @@ -1,6 +1,10 @@ cmake_minimum_required(VERSION 3.15) +# Use cmake -DCMAKE_BUILD_TYPE=Release .. to make a release build. + set(BUILD_TESTING OFF) +# disabled build testing for now, to avoid having to integrate libsndfile and FFTW libraries +# more information here: https://github.com/libsndfile/libsamplerate/blob/master/docs/win32.md set(LIBSAMPLERATE_INSTALL OFF) set(LIBSAMPLERATE_EXAMPLES OFF) # libsamplerate itself does not require any dependencies, diff --git a/cmake/setup_onnx_runtime.cmake b/cmake/setup_onnx_runtime.cmake new file mode 100644 index 0000000..92e8150 --- /dev/null +++ b/cmake/setup_onnx_runtime.cmake @@ -0,0 +1,42 @@ +# Add the onnxruntime library +add_library(onnxruntime STATIC IMPORTED) + +if (APPLE) + message(STATUS ${CMAKE_HOST_SYSTEM_PROCESSOR}) + if (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + set_property(TARGET onnxruntime PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/modules/onnxruntime/lib/onnxruntime-osx-x64.a) + elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64") + set_property(TARGET onnxruntime PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/modules/onnxruntime/lib/onnxruntime-osx-arm64.a) + set_property(TARGET onnxruntime PROPERTY CXX_VISIBILITY_PRESET default) + else() + message(FATAL_ERROR "CMAKE_HOST_SYSTEM_PROCESSOR not defined.") + endif() +elseif (MSVC) + include(cmake/download_onnx_win_debug.cmake) + + set_property(TARGET onnxruntime APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(onnxruntime PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX" + IMPORTED_LOCATION_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/modules/onnxruntime/lib/onnxruntime-win-x64.lib" + ) + set_target_properties(onnxruntime PROPERTIES + MAP_IMPORTED_CONFIG_DEBUG Release + MAP_IMPORTED_CONFIG_MINSIZEREL Release + MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release + ) + + set_property(TARGET onnxruntime APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(onnxruntime PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX" + IMPORTED_LOCATION_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/modules/onnxruntime-1.14.1-win-x86_64_Debug/onnxruntime-1.14.1-win-x86_64_Debug.lib" + ) + set_target_properties(onnxruntime PROPERTIES + MAP_IMPORTED_CONFIG_DEBUG Debug + ) +elseif(LINUX) + set_property(TARGET onnxruntime PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/modules/onnxruntime/lib/onnxruntime-linux_x86_64-static-combined.a) +endif() + + +# Link the onnxruntime library to the target +target_link_libraries(${TARGET_NAME} PRIVATE onnxruntime) diff --git a/cmake/setup_tests_and_benchmarks.cmake b/cmake/setup_tests_and_benchmarks.cmake new file mode 100644 index 0000000..ad2ff5b --- /dev/null +++ b/cmake/setup_tests_and_benchmarks.cmake @@ -0,0 +1,57 @@ +# Externally provided libraries +# Using zip files instead is faster + +# get all test cpp and header files +file(GLOB_RECURSE TestFiles CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/test/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/test/*.h") +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/test PREFIX "" FILES ${TestFiles}) + +# This module enables populating content at configure time via any method supported by the ExternalProject module. Whereas ExternalProject_Add() downloads at build time, the FetchContent module makes content available immediately, allowing the configure step to use the content in commands like add_subdirectory(), include() or file() operations. +include(FetchContent) + +FetchContent_Declare(googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip) + +FetchContent_Declare(benchmark + GIT_REPOSITORY https://github.com/google/benchmark.git + GIT_TAG v1.8.0) + +# This command ensures that each of the named dependencies are made available to the project by the time it returns. If the dependency has already been populated the command does nothing. Otherwise, the command populates the dependency and then calls add_subdirectory() on the result. +FetchContent_MakeAvailable(googletest) + +# For benchmark we want to set the BENCMARK_ENABLE_TESTING to OFF therefore we cannot use FetchContent_MakeAvailable() +# Check if population has already been performed +FetchContent_GetProperties(benchmark) +if(NOT benchmark_POPULATED) + # Fetch the content using previously declared details + FetchContent_Populate(benchmark) + + # Set custom variables, policies, etc. + set(BENCHMARK_ENABLE_TESTING OFF) + + # Bring the populated content into the build + add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR}) +endif() + +# Setup the test executable +add_executable(Test ${TestFiles}) +set_property(TARGET Test PROPERTY CXX_STANDARD 20) + +# Link the test executable against gtest_main and google benchmark +target_link_libraries(Test PRIVATE gtest_main benchmark::benchmark "${TARGET_NAME}") + +# We can't link again to the shared juce target without ODL violations (https://github.com/sudara/pamplejuce/issues/31, https://forum.juce.com/t/windows-linker-issue-on-develop/55524/2) +# Therefore we steal the compile definitions and include directories from the main target and pass them to our test target +# Since we linked the shared juce targets in PRIVATE mode, they are not linked to the test target again +target_compile_definitions(Test PRIVATE $) +target_include_directories(Test PRIVATE $) + +# Make an Xcode Scheme for the test executable so we can run Test in the IDE +set_target_properties(Test PROPERTIES XCODE_GENERATE_SCHEME ON) + +# Organize the test source in the test/ folder in the IDE +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/test PREFIX "" FILES ${TestFiles}) + +# include Loads and runs CMake code from the file given. Loads and runs CMake code from the file given. +include(GoogleTest) +# gtest_discover_tests will register a CTest test for each gtest and run them all in parallel with the rest of the Test. +gtest_discover_tests(Test)