add new "enable-glib" option to compile out use of glib bar LADSPA

This commit is contained in:
Paul 2021-05-30 20:46:59 +01:00
parent 17fb48def5
commit 9e9aa997f1
7 changed files with 93 additions and 47 deletions

View file

@ -90,6 +90,7 @@ option ( enable-pkgconfig "use pkg-config to locate fluidsynth's (mostly optiona
option ( enable-pulseaudio "compile PulseAudio support (if it is available)" on )
option ( enable-readline "compile readline lib line editing (if it is available)" on )
option ( enable-threads "enable multi-threading support (such as parallel voice synthesis)" on )
option ( enable-glib "enable use of glib (only disable if you are providing your own glib alternative)" on )
# Platform specific options
if ( CMAKE_SYSTEM MATCHES "Linux|FreeBSD|DragonFly" )
@ -394,6 +395,11 @@ if ( enable-network )
set ( NETWORK_SUPPORT 1 )
endif ( enable-network )
unset ( GLIB_SUPPORT )
if ( enable-glib )
set ( GLIB_SUPPORT 1 )
endif ( enable-glib )
unset ( WITH_FLOAT CACHE )
if ( enable-floats )
set ( WITH_FLOAT 1 )
@ -489,35 +495,38 @@ endif(ASTYLE)
if(NOT enable-pkgconfig)
FIND_LIBRARY( GLIB_LIB NAMES glib glib-2.0 PATH GLIB_LIBRARY_DIR )
FIND_LIBRARY( GTHREAD_LIB NAMES gthread gthread-2.0 PATH GTHREAD_LIBRARY_DIR )
FIND_PATH( GLIBH_DIR glib.h PATH GLIB_INCLUDE_DIR )
FIND_PATH( GLIBCONF_DIR glibconfig.h PATH GLIBCONF_INCLUDE_DIR )
if(enable-glib)
FIND_LIBRARY( GLIB_LIB NAMES glib glib-2.0 PATH GLIB_LIBRARY_DIR )
FIND_LIBRARY( GTHREAD_LIB NAMES gthread gthread-2.0 PATH GTHREAD_LIBRARY_DIR )
FIND_PATH( GLIBH_DIR glib.h PATH GLIB_INCLUDE_DIR )
FIND_PATH( GLIBCONF_DIR glibconfig.h PATH GLIBCONF_INCLUDE_DIR )
IF( GLIB_LIB MATCHES "GLIB_LIB-NOTFOUND" OR
GTHREAD_LIB MATCHES "GTHREAD_LIB-NOTFOUND" OR
GLIBH_DIR MATCHES "GLIBH_DIR-NOTFOUND" OR
GLIBCONF_DIR MATCHES "GLIBCONF_DIR-NOTFOUND")
message( WARNING "Not sure if I found GLIB, continuing anyway.")
ENDIF()
IF( GLIB_LIB MATCHES "GLIB_LIB-NOTFOUND" OR
GTHREAD_LIB MATCHES "GTHREAD_LIB-NOTFOUND" OR
GLIBH_DIR MATCHES "GLIBH_DIR-NOTFOUND" OR
GLIBCONF_DIR MATCHES "GLIBCONF_DIR-NOTFOUND")
message( WARNING "Not sure if I found GLIB, continuing anyway.")
ENDIF()
SET( GLIB_INCLUDE_DIRS ${GLIBH_DIR} ${GLIBCONF_DIR} )
SET( GLIB_LIBRARIES ${GLIB_LIB} ${GTHREAD_LIB} )
message( STATUS "GLIB_INCLUDE_DIRS: " ${GLIB_INCLUDE_DIRS} )
message( STATUS "GLIB_LIBRARIES: " ${GLIB_LIBRARIES} )
SET( GLIB_INCLUDE_DIRS ${GLIBH_DIR} ${GLIBCONF_DIR} )
SET( GLIB_LIBRARIES ${GLIB_LIB} ${GTHREAD_LIB} )
message( STATUS "GLIB_INCLUDE_DIRS: " ${GLIB_INCLUDE_DIRS} )
message( STATUS "GLIB_LIBRARIES: " ${GLIB_LIBRARIES} )
endif(enable-glib)
else(NOT enable-pkgconfig)
find_package ( PkgConfig REQUIRED )
# Mandatory libraries: glib and gthread
pkg_check_modules ( GLIB REQUIRED glib-2.0>=2.6.5 gthread-2.0>=2.6.5 )
if ( GLIB_glib-2.0_VERSION AND GLIB_glib-2.0_VERSION VERSION_LESS "2.26.0" )
message ( WARNING "Your version of glib is very old. This may cause problems with fluidsynth's sample cache on Windows. Consider updating to glib 2.26 or newer!" )
endif ( GLIB_glib-2.0_VERSION AND GLIB_glib-2.0_VERSION VERSION_LESS "2.26.0" )
if (enable-glib)
# Mandatory libraries: glib and gthread
pkg_check_modules ( GLIB REQUIRED glib-2.0>=2.6.5 gthread-2.0>=2.6.5 )
if ( GLIB_glib-2.0_VERSION AND GLIB_glib-2.0_VERSION VERSION_LESS "2.26.0" )
message ( WARNING "Your version of glib is very old. This may cause problems with fluidsynth's sample cache on Windows. Consider updating to glib 2.26 or newer!" )
endif ( GLIB_glib-2.0_VERSION AND GLIB_glib-2.0_VERSION VERSION_LESS "2.26.0" )
endif(enable-glib)
include ( UnsetPkgConfig )
# Optional features

View file

@ -441,14 +441,14 @@ fluid_command(fluid_cmd_handler_t *handler, const char *cmd, fluid_ostream_t out
return 1;
}
if(!g_shell_parse_argv(cmd, &num_tokens, &tokens, NULL))
if(!fluid_shell_parse_argv(cmd, &num_tokens, &tokens))
{
fluid_ostream_printf(out, "Error parsing command\n");
return FLUID_FAILED;
}
result = fluid_cmd_handler_handle(handler, num_tokens, &tokens[0], out);
g_strfreev(tokens);
fluid_strfreev(tokens);
return result;
}

View file

@ -139,6 +139,9 @@
/* Define to enable network support */
#cmakedefine NETWORK_SUPPORT @NETWORK_SUPPORT@
/* Define to enable glib support */
#cmakedefine GLIB_SUPPORT @GLIB_SUPPORT@
/* Defined when fluidsynth is build in an automated environment, where no MSVC++ Runtime Debug Assertion dialogs should pop up */
#cmakedefine NO_GUI @NO_GUI@

View file

@ -857,7 +857,7 @@ int main(int argc, char **argv)
}
/* if the automatically selected command file does not exist, do not even attempt to open it */
if(!g_file_test(config_file, G_FILE_TEST_EXISTS))
if(!fluid_file_test(config_file, FLUID_FILE_TEST_EXISTS))
{
config_file = NULL;
}

View file

@ -376,10 +376,12 @@ char *fluid_strtok(char **str, char *delim)
* Suspend the execution of the current thread for the specified amount of time.
* @param milliseconds to wait.
*/
#ifdef GLIB_SUPPORT
void fluid_msleep(unsigned int msecs)
{
g_usleep(msecs * 1000);
}
#endif
/**
* Get time in milliseconds to be used in relative timing operations.
@ -408,6 +410,7 @@ unsigned int fluid_curtime(void)
* If glib version is too old and in the case of Windows the function
* uses high precision performance counter instead of g_getmonotic_time().
*/
#ifdef GLIB_SUPPORT
double
fluid_utime(void)
{
@ -446,6 +449,7 @@ fluid_utime(void)
return utime;
}
#endif
@ -1012,6 +1016,7 @@ new_fluid_cond(void)
#endif
#ifdef GLIB_SUPPORT
static gpointer
fluid_thread_high_prio(gpointer data)
{
@ -1104,6 +1109,7 @@ new_fluid_thread(const char *name, fluid_thread_func_t func, void *data, int pri
return thread;
}
#endif
/**
* Frees data associated with a thread (does not actually stop thread).
@ -1120,6 +1126,7 @@ delete_fluid_thread(fluid_thread_t *thread)
* @param thread Thread to join
* @return FLUID_OK
*/
#ifdef GLIB_SUPPORT
int
fluid_thread_join(fluid_thread_t *thread)
{
@ -1127,6 +1134,7 @@ fluid_thread_join(fluid_thread_t *thread)
return FLUID_OK;
}
#endif
static fluid_thread_return_t
@ -1730,14 +1738,14 @@ FILE* fluid_file_open(const char* path, const char** errMsg)
FILE* handle = NULL;
if(!g_file_test(path, G_FILE_TEST_EXISTS))
if(!fluid_file_test(path, FLUID_FILE_TEST_EXISTS))
{
if(errMsg != NULL)
{
*errMsg = ErrExist;
}
}
else if(!g_file_test(path, G_FILE_TEST_IS_REGULAR))
else if(!fluid_file_test(path, FLUID_FILE_TEST_IS_REGULAR))
{
if(errMsg != NULL)
{

View file

@ -157,7 +157,9 @@ typedef gintptr intptr_t;
#include <gmodule.h>
#endif
#ifdef GLIB_SUPPORT
#include <glib/gstdio.h>
#endif
/**
* Macro used for safely accessing a message from a GError and using a default
@ -182,10 +184,12 @@ char* fluid_get_windows_error(void);
#define FLUID_INT_TO_POINTER(x) ((void *)(intptr_t)(x))
/* Endian detection */
#ifdef GLIB_SUPPORT
#define FLUID_IS_BIG_ENDIAN (G_BYTE_ORDER == G_BIG_ENDIAN)
#define FLUID_LE32TOH(x) GINT32_FROM_LE(x)
#define FLUID_LE16TOH(x) GINT16_FROM_LE(x)
#endif
#if FLUID_IS_BIG_ENDIAN
#define FLUID_FOURCC(_a, _b, _c, _d) \
@ -200,6 +204,15 @@ char* fluid_get_windows_error(void);
*/
char *fluid_strtok(char **str, char *delim);
#ifdef GLIB_SUPPORT
#define FLUID_FILE_TEST_EXISTS G_FILE_TEST_EXISTS
#define FLUID_FILE_TEST_IS_REGULAR G_FILE_TEST_IS_REGULAR
#define fluid_file_test(path, flags) g_file_test(path, flags)
#define fluid_shell_parse_argv(command_line, argcp, argvp) g_shell_parse_argv(command_line, argcp, argvp, NULL)
#define fluid_strfreev g_strfreev
#endif
#if defined(__OS2__)
#define INCL_DOS
@ -238,6 +251,7 @@ int fluid_timer_stop(fluid_timer_t *timer);
int fluid_timer_is_running(const fluid_timer_t *timer);
long fluid_timer_get_interval(const fluid_timer_t * timer);
#ifdef GLIB_SUPPORT
// Macros to use for pre-processor if statements to test which Glib thread API we have (pre or post 2.32)
#define NEW_GLIB_THREAD_API GLIB_CHECK_VERSION(2,32,0)
#define OLD_GLIB_THREAD_API !GLIB_CHECK_VERSION(2,32,0)
@ -391,6 +405,7 @@ typedef GStaticPrivate fluid_private_t;
#define fluid_atomic_int_compare_and_exchange(_pi, _old, _new) \
g_atomic_int_compare_and_exchange(_pi, _old, _new)
#ifdef GLIB_SUPPORT
#if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 30)
#define fluid_atomic_int_exchange_and_add(_pi, _add) \
g_atomic_int_add(_pi, _add)
@ -407,6 +422,8 @@ typedef GStaticPrivate fluid_private_t;
#define fluid_atomic_pointer_set(_pp, val) g_atomic_pointer_set(_pp, val)
#define fluid_atomic_pointer_compare_and_exchange(_pp, _old, _new) \
g_atomic_pointer_compare_and_exchange(_pp, _old, _new)
#endif
#endif
static FLUID_INLINE void
fluid_atomic_float_set(fluid_atomic_float_t *fptr, float val)
@ -428,7 +445,7 @@ fluid_atomic_float_get(fluid_atomic_float_t *fptr)
/* Threads */
#ifdef GLIB_SUPPORT
/* other thread implementations might change this for their needs */
typedef void *fluid_thread_return_t;
/* static return value for thread functions which requires a return value */
@ -446,6 +463,7 @@ fluid_thread_t *new_fluid_thread(const char *name, fluid_thread_func_t func, voi
void delete_fluid_thread(fluid_thread_t *thread);
void fluid_thread_self_set_prio(int prio_level);
int fluid_thread_join(fluid_thread_t *thread);
#endif
/* Dynamic Module Loading, currently only used by LADSPA subsystem */
#ifdef LADSPA
@ -484,23 +502,25 @@ fluid_istream_t fluid_socket_get_istream(fluid_socket_t sock);
fluid_ostream_t fluid_socket_get_ostream(fluid_socket_t sock);
/* File access */
#define fluid_stat(_filename, _statbuf) g_stat((_filename), (_statbuf))
#if !GLIB_CHECK_VERSION(2, 26, 0)
/* GStatBuf has not been introduced yet, manually typedef to what they had at that time:
* https://github.com/GNOME/glib/blob/e7763678b56e3be073cc55d707a6e92fc2055ee0/glib/gstdio.h#L98-L115
*/
#if defined(WIN32) || HAVE_WINDOWS_H // somehow reliably mock G_OS_WIN32??
// Any effort from our side to reliably mock GStatBuf on Windows is in vain. E.g. glib-2.16 is broken as it uses struct stat rather than struct _stat32 on Win x86.
// Disable it (the user has been warned by cmake).
#undef fluid_stat
#define fluid_stat(_filename, _statbuf) (-1)
typedef struct _fluid_stat_buf_t{int st_mtime;} fluid_stat_buf_t;
#ifdef GLIB_SUPPORT
#define fluid_stat(_filename, _statbuf) g_stat((_filename), (_statbuf))
#if !GLIB_CHECK_VERSION(2, 26, 0)
/* GStatBuf has not been introduced yet, manually typedef to what they had at that time:
* https://github.com/GNOME/glib/blob/e7763678b56e3be073cc55d707a6e92fc2055ee0/glib/gstdio.h#L98-L115
*/
#if defined(WIN32) || HAVE_WINDOWS_H // somehow reliably mock G_OS_WIN32??
// Any effort from our side to reliably mock GStatBuf on Windows is in vain. E.g. glib-2.16 is broken as it uses struct stat rather than struct _stat32 on Win x86.
// Disable it (the user has been warned by cmake).
#undef fluid_stat
#define fluid_stat(_filename, _statbuf) (-1)
typedef struct _fluid_stat_buf_t{int st_mtime;} fluid_stat_buf_t;
#else
/* posix, OS/2, etc. */
typedef struct stat fluid_stat_buf_t;
#endif
#else
/* posix, OS/2, etc. */
typedef struct stat fluid_stat_buf_t;
typedef GStatBuf fluid_stat_buf_t;
#endif
#else
typedef GStatBuf fluid_stat_buf_t;
#endif
FILE* fluid_file_open(const char* filename, const char** errMsg);

View file

@ -29,10 +29,15 @@
#ifndef _FLUIDSYNTH_PRIV_H
#define _FLUIDSYNTH_PRIV_H
#include <glib.h>
#include "config.h"
#ifdef GLIB_SUPPORT
#include <glib.h>
#else
// Provide your own implementation of glib functionality
#include "glib_replacement.h"
#endif
#if HAVE_STDLIB_H
#include <stdlib.h> // malloc, free
#endif
@ -63,12 +68,11 @@ typedef double fluid_real_t;
#if defined(SUPPORTS_VLA)
# define FLUID_DECLARE_VLA(_type, _name, _len) \
_type _name[_len]
#else
#elif defined(GLIB_SUPPORT)
# define FLUID_DECLARE_VLA(_type, _name, _len) \
_type* _name = g_newa(_type, (_len))
_type* _name = g_newa(_type, (_len))
#endif
/** Atomic types */
typedef int fluid_atomic_int_t;
typedef unsigned int fluid_atomic_uint_t;
@ -290,8 +294,10 @@ do { strncpy(_dst,_src,_n-1); \
#define FLUID_ASSERT(a)
#endif
#ifdef GLIB_SUPPORT
#define FLUID_LIKELY G_LIKELY
#define FLUID_UNLIKELY G_UNLIKELY
#endif
/* Misc */
#if defined(__INTEL_COMPILER)