From ff9c6ed39637bc9bcd70361943c485d5c6028c94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20L=C3=B3pez-Cabanillas?= Date: Sun, 24 Nov 2024 16:51:15 +0100 Subject: [PATCH] updated cmake build system * debug output for libsndfile, quieter output for pulseaudio * enhanced build summary report * revised building win32 binaries without unicode support --- CMakeLists.txt | 23 +++++++------- cmake_admin/SCMRevision.cmake | 50 +++++++++++++++++++++++++++++++ cmake_admin/report.cmake | 18 +++++++++++ include/fluidsynth/version.h.in | 2 +- src/CMakeLists.txt | 2 +- src/bindings/fluid_filerenderer.c | 2 +- src/fluidsynth.c | 6 ++-- src/utils/fluid_sys.c | 4 +-- src/utils/fluid_sys.h | 5 ++-- 9 files changed, 92 insertions(+), 20 deletions(-) create mode 100644 cmake_admin/SCMRevision.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f4776112..4ebde91ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ set ( FLUIDSYNTH_VERSION_MAJOR 2 ) set ( FLUIDSYNTH_VERSION_MINOR 4 ) set ( FLUIDSYNTH_VERSION_MICRO 0 ) set ( VERSION "${FLUIDSYNTH_VERSION_MAJOR}.${FLUIDSYNTH_VERSION_MINOR}.${FLUIDSYNTH_VERSION_MICRO}" ) -set ( FLUIDSYNTH_VERSION "\"${VERSION}\"" ) +set ( FLUIDSYNTH_VERSION ${VERSION} ) # libfluidsynth - Library version # *** NOTICE *** @@ -339,7 +339,7 @@ if ( WIN32 ) set ( LIBFLUID_CPPFLAGS "-DFLUIDSYNTH_DLL_EXPORTS" ) set ( FLUID_CPPFLAGS "-DFLUIDSYNTH_NOT_A_DLL" ) if ( NOT MSVC ) - # only set debug postfix if not MSVS building + # only set debug postfix if not MSVC building set ( CMAKE_DEBUG_POSTFIX "_debug" ) endif ( NOT MSVC ) @@ -544,34 +544,37 @@ endif ( GLib2_VERSION AND GLib2_VERSION VERSION_LESS "2.26.0" ) unset ( LIBSNDFILE_SUPPORT CACHE ) unset ( LIBSNDFILE_HASVORBIS CACHE ) if ( enable-libsndfile ) - set(CMAKE_FIND_DEBUG_MODE ON) - find_package ( SndFile ${LIBSNDFILE_MINIMUM_VERSION} ) + #set(CMAKE_FIND_DEBUG_MODE ON) + find_package ( SndFile ${LIBSNDFILE_MINIMUM_VERSION} QUIET ) set ( LIBSNDFILE_SUPPORT ${SndFile_FOUND} ) if ( LIBSNDFILE_SUPPORT ) - cmake_print_properties(TARGETS SndFile::sndfile PROPERTIES LOCATION INTERFACE_INCLUDE_DIRECTORIES IMPORTED_CONFIGURATIONS) - cmake_print_variables(SndFile_VERSION SndFile_WITH_EXTERNAL_LIBS SndFile_WITH_MPEG) + message ( STATUS "Found libSndFile: ${SndFile_VERSION}" ) + #cmake_print_properties(TARGETS SndFile::sndfile PROPERTIES LOCATION INTERFACE_INCLUDE_DIRECTORIES IMPORTED_CONFIGURATIONS) + cmake_print_variables(SndFile_WITH_EXTERNAL_LIBS SndFile_WITH_MPEG) list( APPEND PC_REQUIRES_PRIV "sndfile") if ( SndFile_WITH_EXTERNAL_LIBS ) set ( LIBSNDFILE_HASVORBIS 1 ) else (SndFile_WITH_EXTERNAL_LIBS) message ( NOTICE "Seems like libsndfile was compiled without OGG/Vorbis support." ) endif (SndFile_WITH_EXTERNAL_LIBS) + else ( LIBSNDFILE_SUPPORT ) + message( STATUS "Could NOT find SndFile (Set SndFile_DIR to the directory containing its CMake config) (Required is at least version ${LIBSNDFILE_MINIMUM_VERSION})" ) endif ( LIBSNDFILE_SUPPORT ) - set(CMAKE_FIND_DEBUG_MODE OFF) + #set(CMAKE_FIND_DEBUG_MODE OFF) endif ( enable-libsndfile ) unset ( PULSE_SUPPORT CACHE ) if ( enable-pulseaudio ) - find_package ( PulseAudio ${PULSEAUDIO_MINIMUM_VERSION} ) + find_package ( PulseAudio ${PULSEAUDIO_MINIMUM_VERSION} QUIET ) # Upstream config does not search for pulse-simple - find_library ( PULSEAUDIO_SIMPLE_LIBRARY NAMES "pulse-simple" ) + find_library ( PULSEAUDIO_SIMPLE_LIBRARY NAMES "pulse-simple" QUIET ) if ( PULSEAUDIO_FOUND AND PULSEAUDIO_SIMPLE_LIBRARY ) set ( PULSE_SUPPORT TRUE ) set ( PULSEAUDIO_LIBRARIES ${PULSEAUDIO_SIMPLE_LIBRARY} ${PULSEAUDIO_LIBRARY} ) message ( STATUS "Found PulseAudio: ${PULSEAUDIO_LIBRARIES}" ) list( APPEND PC_REQUIRES_PRIV "libpulse-simple") else ( PULSEAUDIO_FOUND AND PULSEAUDIO_SIMPLE_LIBRARY ) - message( STATUS "Could NOT find PulseAudio (Set PulseAudio_DIR to the directory containing its CMake config)" ) + message( STATUS "Could NOT find PulseAudio (Set PulseAudio_DIR to the directory containing its CMake config) (Required is at least version ${PULSEAUDIO_MINIMUM_VERSION})" ) endif ( PULSEAUDIO_FOUND AND PULSEAUDIO_SIMPLE_LIBRARY ) endif ( enable-pulseaudio ) diff --git a/cmake_admin/SCMRevision.cmake b/cmake_admin/SCMRevision.cmake new file mode 100644 index 000000000..b528bb08e --- /dev/null +++ b/cmake_admin/SCMRevision.cmake @@ -0,0 +1,50 @@ +#[=======================================================================[ +Copyright © 2019-2024 Pedro López-Cabanillas + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#]=======================================================================] + +if (NOT DEFINED PROJECT_WC_REVISION) + find_package(Git QUIET) + if (Git_FOUND) + execute_process( + COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + RESULT_VARIABLE _res + OUTPUT_VARIABLE PROJECT_WC_REVISION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if (${_res} EQUAL 0) + message(STATUS "Current revision (Git) is ${PROJECT_WC_REVISION}") + else() + unset(PROJECT_WC_REVISION) + endif() + endif() +endif() + +if (DEFINED PROJECT_WC_REVISION) + set(${PROJECT_NAME}_WC_REVISION ${PROJECT_WC_REVISION}) +else() + set(${PROJECT_NAME}_WC_REVISION "not a git working copy") +endif() diff --git a/cmake_admin/report.cmake b/cmake_admin/report.cmake index 437333d75..e2fe5055f 100644 --- a/cmake_admin/report.cmake +++ b/cmake_admin/report.cmake @@ -1,3 +1,4 @@ +include( SCMRevision ) set ( AUDIO_MIDI_REPORT "\n" ) @@ -189,6 +190,19 @@ else ( HAVE_GETOPT_H ) set ( MISC_REPORT "${MISC_REPORT} getopt: no\n" ) endif ( HAVE_GETOPT_H ) +if ( WIN32 OR CYGWIN ) + set ( WINDOWS_REPORT "\nWindows specific info:\n" ) + if ( windows-version ) + set ( WINDOWS_REPORT "${WINDOWS_REPORT} target version: ${windows-version}\n" ) + endif ( windows-version ) + if ( enable-unicode ) + set ( WINDOWS_REPORT "${WINDOWS_REPORT} unicode support: yes\n" ) + else ( enable-unicode ) + set ( WINDOWS_REPORT "${WINDOWS_REPORT} unicode support: no\n" ) + endif ( enable-unicode ) +else ( WIN32 OR CYGWIN ) + set ( WINDOWS_REPORT "") +endif ( WIN32 OR CYGWIN ) set ( DEVEL_REPORT "\nDeveloper nerds info:\n" ) @@ -249,6 +263,9 @@ endif ( ENABLE_COVERAGE ) message( STATUS "\n**************************************************************\n" "Build Summary:\n" + "FluidSynth Version: " ${FLUIDSYNTH_VERSION} "\n" + "Library version: " ${LIB_VERSION_INFO} "\n" + "Git revision: " ${FluidSynth_WC_REVISION} "\n" "Build type: " ${CMAKE_BUILD_TYPE} "\n" "Install Prefix: " ${CMAKE_INSTALL_PREFIX} "\n" "\n" @@ -257,6 +274,7 @@ message( STATUS ${INPUTS_REPORT} ${RENDERING_REPORT} ${MISC_REPORT} + ${WINDOWS_REPORT} ${DEVEL_REPORT} ) diff --git a/include/fluidsynth/version.h.in b/include/fluidsynth/version.h.in index b687210ee..4cf2b6223 100644 --- a/include/fluidsynth/version.h.in +++ b/include/fluidsynth/version.h.in @@ -31,7 +31,7 @@ extern "C" { * * @{ */ -#define FLUIDSYNTH_VERSION @FLUIDSYNTH_VERSION@ /**< String constant of libfluidsynth version. */ +#define FLUIDSYNTH_VERSION "@FLUIDSYNTH_VERSION@" /**< String constant of libfluidsynth version. */ #define FLUIDSYNTH_VERSION_MAJOR @FLUIDSYNTH_VERSION_MAJOR@ /**< libfluidsynth major version integer constant. */ #define FLUIDSYNTH_VERSION_MINOR @FLUIDSYNTH_VERSION_MINOR@ /**< libfluidsynth minor version integer constant. */ #define FLUIDSYNTH_VERSION_MICRO @FLUIDSYNTH_VERSION_MICRO@ /**< libfluidsynth micro version integer constant. */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4bd6eb903..a2f9e55b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -500,7 +500,7 @@ if ( TARGET PipeWire::PipeWire AND PIPEWIRE_SUPPORT ) # because pw_init() etc. target_link_libraries ( fluidsynth PRIVATE PipeWire::PipeWire ) endif() -if ( MINGW ) +if ( MINGW AND enable-unicode ) target_link_options( fluidsynth PRIVATE -municode ) endif() diff --git a/src/bindings/fluid_filerenderer.c b/src/bindings/fluid_filerenderer.c index d17373996..aab650602 100644 --- a/src/bindings/fluid_filerenderer.c +++ b/src/bindings/fluid_filerenderer.c @@ -289,7 +289,7 @@ new_fluid_file_renderer(fluid_synth_t *synth) goto error_recovery; } -#ifdef _WIN32 +#if defined( _WIN32 ) && defined( _UNICODE ) if (0 == FLUID_STRCMP("-", filename)) { dev->sndfile = sf_open(filename, SFM_WRITE, &info); diff --git a/src/fluidsynth.c b/src/fluidsynth.c index 73f0cd940..fddd28c0f 100644 --- a/src/fluidsynth.c +++ b/src/fluidsynth.c @@ -325,7 +325,7 @@ fast_render_loop(fluid_settings_t *settings, fluid_synth_t *synth, fluid_player_ 15)create the audio driver (i.e synthesis thread) and a synchronous user shell if interactive. */ -#if defined(_WIN32) +#if defined(_WIN32) && defined(_UNICODE) int wmain(int argc, wchar_t **wargv) #else int main(int argc, char **argv) @@ -356,7 +356,7 @@ int main(int argc, char **argv) int fast_render = 0; static const char optchars[] = "a:C:c:dE:f:F:G:g:hijK:L:lm:nO:o:p:QqR:r:sT:Vvz:"; -#if defined(_WIN32) +#if defined(_WIN32) && defined(_UNICODE) // WC_ERR_INVALID_CHARS is only supported on Windows Vista and newer. To support older Windows, our only chance is to use zero for this flag. #ifndef WC_ERR_INVALID_CHARS #define WC_ERR_INVALID_CHARS 0 @@ -1164,7 +1164,7 @@ int main(int argc, char **argv) delete_fluid_synth(synth); delete_fluid_settings(settings); -#ifdef _WIN32 +#if defined(_WIN32) && defined(_UNICODE) if (argv != NULL) { for (i = 0; i < argc; ++i) diff --git a/src/utils/fluid_sys.c b/src/utils/fluid_sys.c index 9b24e56d7..babb11ff8 100644 --- a/src/utils/fluid_sys.c +++ b/src/utils/fluid_sys.c @@ -1659,8 +1659,8 @@ new_fluid_server_socket(int port, fluid_server_func_t func, void *data) fluid_socket_cleanup(); return NULL; } - - if(bind(sock, addr, addr_size) == SOCKET_ERROR) + + if(bind(sock, addr, (int) addr_size) == SOCKET_ERROR) { FLUID_LOG(FLUID_ERR, "Failed to bind server socket: %d", fluid_socket_get_error()); fluid_socket_close(sock); diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h index 0672baefd..a756fc073 100644 --- a/src/utils/fluid_sys.h +++ b/src/utils/fluid_sys.h @@ -157,8 +157,9 @@ typedef gintptr intptr_t; #endif /* - * Required by Windows-specific sf_wchar_open() from - * libsndfile that takes a UTF16_BE encoded filename. + * Required by Windows-specific sf_wchar_open() from old libsndfile + * versions before v1.1.0, that takes a UTF16_BE encoded filename. + * Note that FluidSynth needs libsndfile >= v1.2.1 anyway. */ #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1