From 36786dd83de8e7e19f1a96607b4dc5a7a1233aaf Mon Sep 17 00:00:00 2001 From: Rossmaxx <74815851+Rossmaxx@users.noreply.github.com> Date: Mon, 13 May 2024 13:14:42 +0530 Subject: [PATCH] Enable LADSPA plugins on MSVC (#6973) Co-authored-by: Tres Finocchiaro Co-authored-by: Dominic Clark Co-authored-by: Dalton Messmer --- CMakeLists.txt | 1 + cmake/modules/PluginList.cmake | 9 --------- plugins/LadspaEffect/calf/CMakeLists.txt | 11 ++++++++++- plugins/LadspaEffect/caps/CMakeLists.txt | 12 +++++++++++- plugins/LadspaEffect/caps/basics.h | 5 ++++- plugins/LadspaEffect/caps/dsp/Eq.h | 6 +++--- plugins/LadspaEffect/caps/interface.cc | 11 ++++++++--- plugins/LadspaEffect/cmt/CMakeLists.txt | 11 ++++++++++- plugins/LadspaEffect/cmt/cmt | 2 +- plugins/LadspaEffect/swh/CMakeLists.txt | 14 +++++++++++--- plugins/LadspaEffect/tap/CMakeLists.txt | 10 ++++++++-- 11 files changed, 67 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e0158e75..1da10775b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -645,6 +645,7 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") ENDIF() ELSEIF(MSVC) # Remove any existing /W flags + string(REGEX REPLACE "/W[0-4]" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) STRING(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) SET(WERROR_FLAGS "/W2") IF(${USE_WERROR}) diff --git a/cmake/modules/PluginList.cmake b/cmake/modules/PluginList.cmake index 8c444aca2..8b26d4ed5 100644 --- a/cmake/modules/PluginList.cmake +++ b/cmake/modules/PluginList.cmake @@ -100,12 +100,3 @@ IF(LIST_PLUGINS) UNSET(LIST_PLUGINS CACHE) LIST_ALL_PLUGINS() ENDIF() - -IF(MSVC) - SET(MSVC_INCOMPATIBLE_PLUGINS - LadspaEffect - ) - message(WARNING "Compiling with MSVC. The following plugins are not available: ${MSVC_INCOMPATIBLE_PLUGINS}") - LIST(REMOVE_ITEM PLUGIN_LIST ${MSVC_INCOMPATIBLE_PLUGINS}) -ENDIF() - diff --git a/plugins/LadspaEffect/calf/CMakeLists.txt b/plugins/LadspaEffect/calf/CMakeLists.txt index 67bdc5cd2..038fa6afb 100644 --- a/plugins/LadspaEffect/calf/CMakeLists.txt +++ b/plugins/LadspaEffect/calf/CMakeLists.txt @@ -40,7 +40,16 @@ IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") SET(INLINE_FLAGS -finline-functions-called-once -finline-limit=80) SET(OTHER_FLAGS -Wno-format-overflow) ENDIF() -target_compile_options(veal PRIVATE -fexceptions -O2 -finline-functions ${INLINE_FLAGS} ${OTHER_FLAGS}) + +if(MSVC) + target_compile_options(veal PRIVATE /wd4099 /wd4244 /wd4305) +else() + target_compile_options(veal PRIVATE -fexceptions -O2 -finline-functions ${INLINE_FLAGS} ${OTHER_FLAGS}) +endif() + +if(MSVC) + target_link_options(veal PRIVATE "/EXPORT:ladspa_descriptor") +endif() if(LMMS_BUILD_WIN32) add_custom_command( diff --git a/plugins/LadspaEffect/caps/CMakeLists.txt b/plugins/LadspaEffect/caps/CMakeLists.txt index bdcf3a96a..f82fa5ab0 100644 --- a/plugins/LadspaEffect/caps/CMakeLists.txt +++ b/plugins/LadspaEffect/caps/CMakeLists.txt @@ -7,7 +7,16 @@ IF(LMMS_BUILD_WIN64) ADD_DEFINITIONS(-DLMMS_BUILD_WIN64) ENDIF(LMMS_BUILD_WIN64) SET_TARGET_PROPERTIES(caps PROPERTIES PREFIX "") -SET_TARGET_PROPERTIES(caps PROPERTIES COMPILE_FLAGS "-O2 -funroll-loops -Wno-write-strings") + +if(MSVC) + target_compile_options(caps PRIVATE /wd4244 /wd4305) +else() + target_compile_options(caps PRIVATE -O2 -funroll-loops -Wno-write-strings) +endif() + +if(MSVC) + target_link_options(caps PRIVATE "/EXPORT:ladspa_descriptor") +endif() IF(LMMS_BUILD_WIN32) add_custom_command( @@ -18,6 +27,7 @@ IF(LMMS_BUILD_WIN32) COMMAND_EXPAND_LISTS ) ENDIF(LMMS_BUILD_WIN32) + IF(NOT LMMS_BUILD_APPLE AND NOT LMMS_BUILD_OPENBSD) SET_TARGET_PROPERTIES(caps PROPERTIES LINK_FLAGS "${LINK_FLAGS} -shared -Wl,-no-undefined") ENDIF(NOT LMMS_BUILD_APPLE AND NOT LMMS_BUILD_OPENBSD) diff --git a/plugins/LadspaEffect/caps/basics.h b/plugins/LadspaEffect/caps/basics.h index df24e8c05..62eb77887 100644 --- a/plugins/LadspaEffect/caps/basics.h +++ b/plugins/LadspaEffect/caps/basics.h @@ -41,6 +41,9 @@ #include #include +#ifndef _USE_MATH_DEFINES +#define _USE_MATH_DEFINES +#endif #include #include @@ -76,7 +79,7 @@ #define MIN_GAIN .000001 /* -120 dB */ -/* smallest non-denormal 32 bit IEEE float is 1.18×10-38 */ +/* smallest non-denormal 32 bit IEEE float is 1.18×10^-38 */ #define NOISE_FLOOR .00000000000005 /* -266 dB */ typedef int8_t int8; diff --git a/plugins/LadspaEffect/caps/dsp/Eq.h b/plugins/LadspaEffect/caps/dsp/Eq.h index 92639e8a1..89c86dd18 100644 --- a/plugins/LadspaEffect/caps/dsp/Eq.h +++ b/plugins/LadspaEffect/caps/dsp/Eq.h @@ -62,11 +62,11 @@ class Eq { public: /* recursion coefficients, 3 per band */ - eq_sample __attribute__ ((aligned)) a[Bands], b[Bands], c[Bands]; + eq_sample a[Bands], b[Bands], c[Bands]; /* past outputs, 2 per band */ - eq_sample __attribute__ ((aligned)) y[2][Bands]; + eq_sample y[2][Bands]; /* current gain and recursion factor, each 1 per band = 2 */ - eq_sample __attribute__ ((aligned)) gain[Bands], gf[Bands]; + eq_sample gain[Bands], gf[Bands]; /* input history */ eq_sample x[2]; /* history index */ diff --git a/plugins/LadspaEffect/caps/interface.cc b/plugins/LadspaEffect/caps/interface.cc index 96e3d9806..4c7ca46b5 100644 --- a/plugins/LadspaEffect/caps/interface.cc +++ b/plugins/LadspaEffect/caps/interface.cc @@ -29,7 +29,7 @@ (2541 - 2580 donated to artemio@kdemail.net) */ -#include +// #include #include "basics.h" @@ -69,7 +69,6 @@ seed() extern "C" { -__attribute__ ((constructor)) void caps_so_init() { DescriptorStub ** d = descriptors; @@ -125,7 +124,6 @@ void caps_so_init() //seed(); } -__attribute__ ((destructor)) void caps_so_fini() { for (ulong i = 0; i < N; ++i) @@ -142,4 +140,11 @@ ladspa_descriptor (unsigned long i) return 0; } +struct CapsSoInit +{ + CapsSoInit() { caps_so_init(); } + ~CapsSoInit() { caps_so_fini(); } +}; +static CapsSoInit capsSoInit; + }; /* extern "C" */ diff --git a/plugins/LadspaEffect/cmt/CMakeLists.txt b/plugins/LadspaEffect/cmt/CMakeLists.txt index 75dba319d..65430d109 100644 --- a/plugins/LadspaEffect/cmt/CMakeLists.txt +++ b/plugins/LadspaEffect/cmt/CMakeLists.txt @@ -5,7 +5,12 @@ ADD_LIBRARY(cmt MODULE ${SOURCES}) INSTALL(TARGETS cmt LIBRARY DESTINATION "${PLUGIN_DIR}/ladspa") SET_TARGET_PROPERTIES(cmt PROPERTIES PREFIX "") -target_compile_options(cmt PRIVATE -Wall -O3 -fno-strict-aliasing) + +if(MSVC) + target_compile_options(cmt PRIVATE /wd4244 /wd4305) +else() + target_compile_options(cmt PRIVATE -Wall -O3 -fno-strict-aliasing) +endif() if(LMMS_BUILD_WIN32) add_custom_command( @@ -17,6 +22,10 @@ if(LMMS_BUILD_WIN32) ) endif() +if(MSVC) + target_link_options(cmt PRIVATE "/EXPORT:ladspa_descriptor") +endif() + if(NOT LMMS_BUILD_WIN32) target_compile_options(cmt PRIVATE -fPIC) endif() diff --git a/plugins/LadspaEffect/cmt/cmt b/plugins/LadspaEffect/cmt/cmt index d8bf8084a..24599fb45 160000 --- a/plugins/LadspaEffect/cmt/cmt +++ b/plugins/LadspaEffect/cmt/cmt @@ -1 +1 @@ -Subproject commit d8bf8084aa3a47497092f5ab99c843a55090d151 +Subproject commit 24599fb45b99fff6302136f13adb3817e5833e7d diff --git a/plugins/LadspaEffect/swh/CMakeLists.txt b/plugins/LadspaEffect/swh/CMakeLists.txt index a83001177..b76c95931 100644 --- a/plugins/LadspaEffect/swh/CMakeLists.txt +++ b/plugins/LadspaEffect/swh/CMakeLists.txt @@ -9,9 +9,13 @@ ELSE() ENDIF() # Additional compile flags -SET(COMPILE_FLAGS "${COMPILE_FLAGS} -O3 -Wall") -SET(COMPILE_FLAGS "${COMPILE_FLAGS} -fomit-frame-pointer -funroll-loops -ffast-math -c -fno-strict-aliasing") -SET(COMPILE_FLAGS "${COMPILE_FLAGS} ${PIC_FLAGS}") +if(MSVC) + set(COMPILE_FLAGS "${COMPILE_FLAGS} /wd4244 /wd4273 /wd4305") +else() + set(COMPILE_FLAGS "${COMPILE_FLAGS} -O3 -Wall") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -fomit-frame-pointer -funroll-loops -ffast-math -c -fno-strict-aliasing") + set(COMPILE_FLAGS "${COMPILE_FLAGS} ${PIC_FLAGS}") +endif() # Loop over every XML file FILE(GLOB XML_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/ladspa/*.xml") @@ -34,6 +38,10 @@ FOREACH(_item ${XML_SOURCES}) # Add a library target for this C file, which depends on success of makestup.pl ADD_LIBRARY("${_plugin}" MODULE "${_out_file}") + if(MSVC) + target_link_options("${_plugin}" PRIVATE "/EXPORT:ladspa_descriptor") + endif() + # Vocoder does not use fftw IF(NOT ("${_plugin}" STREQUAL "vocoder_1337")) TARGET_LINK_LIBRARIES("${_plugin}" ${FFTW3F_LIBRARIES}) diff --git a/plugins/LadspaEffect/tap/CMakeLists.txt b/plugins/LadspaEffect/tap/CMakeLists.txt index c8d0a4eb8..b895c7531 100644 --- a/plugins/LadspaEffect/tap/CMakeLists.txt +++ b/plugins/LadspaEffect/tap/CMakeLists.txt @@ -1,10 +1,17 @@ INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include") FILE(GLOB PLUGIN_SOURCES tap-plugins/*.c) LIST(SORT PLUGIN_SOURCES) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wno-write-strings -fomit-frame-pointer -fno-strict-aliasing -funroll-loops -ffast-math") +if(MSVC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4244 /fp:fast") +else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wno-write-strings -fomit-frame-pointer -fno-strict-aliasing -funroll-loops -ffast-math") +endif() FOREACH(_item ${PLUGIN_SOURCES}) GET_FILENAME_COMPONENT(_plugin "${_item}" NAME_WE) ADD_LIBRARY("${_plugin}" MODULE "${_item}") + if(MSVC) + target_link_options("${_plugin}" PRIVATE "/EXPORT:ladspa_descriptor") + endif() # TAP pinknoise will re-init srand(); use existing seed instead IF("${_plugin}" MATCHES "tap_pinknoise") TARGET_COMPILE_DEFINITIONS("${_plugin}" PRIVATE TAP_DISABLE_SRAND=1) @@ -24,4 +31,3 @@ FOREACH(_item ${PLUGIN_SOURCES}) TARGET_LINK_LIBRARIES("${_plugin}" m) ENDIF() ENDFOREACH() -