Skip to content

Commit

Permalink
Revert GLIB_SUPPORT macro and CMake related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
derselbst committed Dec 21, 2021
1 parent 9e9aa99 commit ca91ee1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 80 deletions.
54 changes: 22 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ 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" )
Expand Down Expand Up @@ -395,11 +394,6 @@ 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 )
Expand Down Expand Up @@ -495,37 +489,33 @@ endif(ASTYLE)

if(NOT enable-pkgconfig)

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()

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)
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()

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} )
else(NOT enable-pkgconfig)

find_package ( PkgConfig REQUIRED )

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 )
# 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)
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" )

include ( UnsetPkgConfig )

Expand Down
3 changes: 0 additions & 3 deletions src/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@
/* 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@

Expand Down
8 changes: 0 additions & 8 deletions src/utils/fluid_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,10 @@ 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.
Expand Down Expand Up @@ -410,7 +408,6 @@ 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)
{
Expand Down Expand Up @@ -449,7 +446,6 @@ fluid_utime(void)

return utime;
}
#endif



Expand Down Expand Up @@ -1016,7 +1012,6 @@ new_fluid_cond(void)

#endif

#ifdef GLIB_SUPPORT
static gpointer
fluid_thread_high_prio(gpointer data)
{
Expand Down Expand Up @@ -1109,7 +1104,6 @@ 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).
Expand All @@ -1126,15 +1120,13 @@ 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)
{
g_thread_join(thread);

return FLUID_OK;
}
#endif


static fluid_thread_return_t
Expand Down
45 changes: 16 additions & 29 deletions src/utils/fluid_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ 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
Expand All @@ -184,12 +182,10 @@ 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) \
Expand All @@ -204,15 +200,13 @@ 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
Expand Down Expand Up @@ -251,7 +245,6 @@ 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)
Expand Down Expand Up @@ -405,7 +398,6 @@ 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)
Expand All @@ -422,8 +414,7 @@ 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)
Expand All @@ -445,7 +436,6 @@ 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 */
Expand All @@ -463,7 +453,6 @@ 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
Expand Down Expand Up @@ -502,25 +491,23 @@ fluid_istream_t fluid_socket_get_istream(fluid_socket_t sock);
fluid_ostream_t fluid_socket_get_ostream(fluid_socket_t sock);

/* File access */
#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
#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
typedef GStatBuf fluid_stat_buf_t;
/* posix, OS/2, etc. */
typedef struct stat fluid_stat_buf_t;
#endif
#else
typedef GStatBuf fluid_stat_buf_t;
#endif

FILE* fluid_file_open(const char* filename, const char** errMsg);
Expand Down
9 changes: 1 addition & 8 deletions src/utils/fluidsynth_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@

#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
Expand Down Expand Up @@ -68,7 +63,7 @@ typedef double fluid_real_t;
#if defined(SUPPORTS_VLA)
# define FLUID_DECLARE_VLA(_type, _name, _len) \
_type _name[_len]
#elif defined(GLIB_SUPPORT)
#else
# define FLUID_DECLARE_VLA(_type, _name, _len) \
_type* _name = g_newa(_type, (_len))
#endif
Expand Down Expand Up @@ -294,10 +289,8 @@ 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)
Expand Down

0 comments on commit ca91ee1

Please sign in to comment.