Make it possible to build with hexchat's gtk

This commit is contained in:
Yevgen Muntyan 2016-10-02 21:37:59 -07:00
parent 01c7a3bd9e
commit 5f5b157e1c
6 changed files with 110 additions and 28 deletions

View File

@ -93,9 +93,10 @@ else()
set(MOO_OS_UNIX TRUE)
endif()
set(MOO_BUILD_FROM_MSVC FALSE CACHE BOOL "Create a win32 build from MSVC gtk build")
set(MOO_BUILD_FROM_MINGW ${MOO_OS_WIN32} CACHE BOOL "Create a win32 build from mingw gtk build")
if(NOT MOO_BUILD_FROM_MINGW)
if(NOT MOO_BUILD_FROM_MINGW AND NOT MOO_BUILD_FROM_MSVC)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED gtk+-2.0)
pkg_check_modules(GMODULE REQUIRED gmodule-2.0)
@ -119,9 +120,24 @@ if(NOT MOO_BUILD_FROM_MINGW)
pkg_check_modules(XLIB x11 xext xrender ice sm)
pkg_check_modules(LIBXML2 REQUIRED libxml-2.0)
else()
if(MOO_BUILD_FROM_MINGW)
set(MOO_GTK_DIR "C:/Projects/gtk/release/target" CACHE PATH "Gtk root dir")
set(MOO_GTK_DIST_DIR "C:/Projects/gtk/release/bdist" CACHE PATH "Gtk binary dir")
set(GTK_LIBRARIES libgtk-win32-2.0-0 libatk-1.0-0 libgdk-win32-2.0-0 libgdk_pixbuf-2.0-0
libpango-1.0-0 libpangocairo-1.0-0 libcairo-2
libgio-2.0-0 libgobject-2.0-0 libgmodule-2.0-0 libgthread-2.0-0 libglib-2.0-0 libintl-8)
set(LIBXML2_LIBRARIES "libxml2-2")
else()
set(MOO_GTK_DIR "C:/gtk-build/gtk/Win32" CACHE PATH "Gtk root dir")
set(MOO_GTK_DIST_DIR "C:/gtk-build/gtk/bdist" CACHE PATH "Gtk binary dir")
set(GTK_LIBRARIES atk-1.0 cairo gdk_pixbuf-2.0 gdk-win32-2.0 gio-2.0 glib-2.0 gmodule-2.0 gobject-2.0
gthread-2.0 gtk-win32-2.0 iconv intl libffi libpng16 pango-1.0 pangocairo-1.0 pixman-1 zlib1)
set(LIBXML2_LIBRARIES libxml2)
endif()
set(CMAKE_INSTALL_PREFIX ${MOO_GTK_DIR} CACHE PATH "CMake install prefix" FORCE)
include_directories(SYSTEM "${MOO_GTK_DIR}/include")
@ -136,10 +152,6 @@ else()
include_directories(SYSTEM "${MOO_GTK_DIR}/include/libxml2")
set(GTK_LIBRARY_DIRS "${MOO_GTK_DIR}/lib")
set(GTK_LIBRARIES libgtk-win32-2.0-0 libatk-1.0-0 libgdk-win32-2.0-0 libgdk_pixbuf-2.0-0
libpango-1.0-0 libpangocairo-1.0-0 libcairo-2
libgio-2.0-0 libgobject-2.0-0 libgmodule-2.0-0 libgthread-2.0-0 libglib-2.0-0 libintl-8)
set(LIBXML2_LIBRARIES "libxml2-2")
set(ENV{PATH} "ENV{PATH};${MOO_GTK_DIR}/bin")

View File

@ -134,8 +134,11 @@ if(MOO_USE_PCH)
SOURCE_CXX moo-pch.cpp)
endif()
if(MOO_BUILD_FROM_MINGW)
LIST(APPEND MEDIT_LIBS libmooglib-0)
endif()
target_link_libraries(medit
libmooglib-0
${GTK_LIBRARIES}
${GMODULE_LIBRARIES}
${LIBXML2_LIBRARIES}

View File

@ -21,7 +21,8 @@ const mgw_errno_t MGW_E_EXIST = { MGW_EEXIST };
static mgw_time_t convert_time_t (time_t t)
{
mgw_time_t result = { t };
mgw_time_t result;
result.value = t;
return result;
}
@ -34,8 +35,13 @@ static void convert_g_stat_buf (const GStatBuf* gbuf, MgwStatBuf* mbuf)
mbuf->size = gbuf->st_size;
#ifdef _MSC_VER
mbuf->isreg = (gbuf->st_mode & _S_IFREG) != 0;
mbuf->isdir = (gbuf->st_mode & _S_IFDIR) != 0;
#else
mbuf->isreg = S_ISREG (gbuf->st_mode);
mbuf->isdir = S_ISDIR (gbuf->st_mode);
#endif
#ifdef S_ISLNK
mbuf->islnk = S_ISLNK (gbuf->st_mode);
@ -69,6 +75,7 @@ static void convert_g_stat_buf (const GStatBuf* gbuf, MgwStatBuf* mbuf)
}
#ifndef _MSC_VER
#define call_with_errno(err__, func__, rtype__, ...) \
({ \
rtype__ result__; \
@ -78,6 +85,30 @@ static void convert_g_stat_buf (const GStatBuf* gbuf, MgwStatBuf* mbuf)
(err__)->value = errno; \
result__; \
})
#else // _MSC_VER
#define _call_with_errno(what__, result__) \
errno = 0; \
result__ = what__; \
if (err != NULL) \
err->value = errno; \
#define call_with_errno0(func__, result__) \
_call_with_errno((func__)(), result__)
#define call_with_errno1(func__, result__, a1__) \
_call_with_errno((func__)((a1__)), result__)
#define call_with_errno2(func__, result__, a1__, a2__) \
_call_with_errno((func__)((a1__), (a2__)), result__)
#define call_with_errno3(func__, result__, a1__, a2__, a3__) \
_call_with_errno((func__)((a1__), (a2__), (a3__)), result__)
#define call_with_errno4(func__, result__, a1__, a2__, a3__, a4__) \
_call_with_errno((func__)((a1__), (a2__), (a3__), (a4__)), result__)
#endif // _MSC_VER
const char *
@ -97,7 +128,8 @@ int
mgw_stat (const gchar *filename, MgwStatBuf *buf, mgw_errno_t *err)
{
GStatBuf gbuf = { 0 };
int result = call_with_errno (err, g_stat, int, filename, &gbuf);
int result;
call_with_errno2 (g_stat, result, filename, &gbuf);
convert_g_stat_buf (&gbuf, buf);
return result;
}
@ -106,7 +138,8 @@ int
mgw_lstat (const gchar *filename, MgwStatBuf *buf, mgw_errno_t *err)
{
GStatBuf gbuf = { 0 };
int result = call_with_errno (err, g_lstat, int, filename, &gbuf);
int result;
call_with_errno2 (g_lstat, result, filename, &gbuf);
convert_g_stat_buf (&gbuf, buf);
return result;
}
@ -136,14 +169,17 @@ const struct tm *
mgw_localtime_r (const mgw_time_t *timep, struct tm *result, mgw_errno_t *err)
{
time_t t = timep->value;
return call_with_errno (err, localtime_r, struct tm*, &t, result);
struct tm *ret;
call_with_errno2 (localtime_r, ret, &t, result);
return ret;
}
mgw_time_t
mgw_time (mgw_time_t *t, mgw_errno_t *err)
{
time_t t1;
mgw_time_t result = { call_with_errno (err, time, time_t, &t1) };
mgw_time_t result;
call_with_errno1 (time, result.value, &t1);
if (t != NULL)
t->value = t1;
return result;
@ -153,20 +189,26 @@ mgw_time (mgw_time_t *t, mgw_errno_t *err)
guint64
mgw_ascii_strtoull (const gchar *nptr, gchar **endptr, guint base, mgw_errno_t *err)
{
return call_with_errno (err, g_ascii_strtoull, guint64, nptr, endptr, base);
guint64 result;
call_with_errno3 (g_ascii_strtoull, result, nptr, endptr, base);
return result;
}
gdouble
mgw_ascii_strtod (const gchar *nptr, gchar **endptr, mgw_errno_t *err)
{
return call_with_errno (err, g_ascii_strtod, double, nptr, endptr);
double result;
call_with_errno2 (g_ascii_strtod, result, nptr, endptr);
return result;
}
MGW_FILE *
mgw_fopen (const char *filename, const char *mode, mgw_errno_t *err)
{
return (MGW_FILE*) call_with_errno (err, g_fopen, FILE*, filename, mode);
FILE* result;
call_with_errno2 (g_fopen, result, filename, mode);
return (MGW_FILE*) result;
}
int mgw_fclose (MGW_FILE *file)
@ -177,7 +219,9 @@ int mgw_fclose (MGW_FILE *file)
gsize
mgw_fread(void *ptr, gsize size, gsize nmemb, MGW_FILE *stream, mgw_errno_t *err)
{
return call_with_errno (err, fread, gsize, ptr, size, nmemb, (FILE*) stream);
gsize result;
call_with_errno4 (fread, result, ptr, size, nmemb, (FILE*) stream);
return result;
}
gsize
@ -202,7 +246,8 @@ mgw_fgets(char *s, int size, MGW_FILE *stream)
MgwFd
mgw_open (const char *filename, int flags, int mode)
{
MgwFd fd = { g_open (filename, flags, mode) };
MgwFd fd;
fd.value = g_open (filename, flags, mode);
return fd;
}
@ -244,31 +289,41 @@ mgw_perror (const char *s)
int
mgw_unlink (const char *path, mgw_errno_t *err)
{
return call_with_errno (err, g_unlink, int, path);
int result;
call_with_errno1 (g_unlink, result, path);
return result;
}
int
mgw_remove (const char *path, mgw_errno_t *err)
{
return call_with_errno (err, g_remove, int, path);
int result;
call_with_errno1 (g_remove, result, path);
return result;
}
int
mgw_rename (const char *oldpath, const char *newpath, mgw_errno_t *err)
{
return call_with_errno (err, g_rename, int, oldpath, newpath);
int result;
call_with_errno2 (g_rename, result, oldpath, newpath);
return result;
}
int
mgw_mkdir (const gchar *filename, int mode, mgw_errno_t *err)
{
return call_with_errno (err, g_mkdir, int, filename, mode);
int result;
call_with_errno2 (g_mkdir, result, filename, mode);
return result;
}
int
mgw_mkdir_with_parents (const gchar *pathname, gint mode, mgw_errno_t *err)
{
return call_with_errno (err, g_mkdir_with_parents, int, pathname, mode);
int result;
call_with_errno2 (g_mkdir_with_parents, result, pathname, mode);
return result;
}
int

View File

@ -5,6 +5,13 @@
G_BEGIN_DECLS
#define MOO_BUILTIN_MOO_GLIB 1
typedef struct mgw_errno_t mgw_errno_t;
typedef struct MGW_FILE MGW_FILE;
typedef struct MgwFd MgwFd;
typedef struct mgw_access_mode_t mgw_access_mode_t;
#ifndef __WIN32__
#define MGW_ERROR_IF_NOT_SHARED_LIBC
#else
@ -12,11 +19,6 @@ G_BEGIN_DECLS
#error "C libraries may not be shared between medit and glib"
#endif
typedef struct mgw_errno_t mgw_errno_t;
typedef struct MGW_FILE MGW_FILE;
typedef struct MgwFd MgwFd;
typedef struct mgw_access_mode_t mgw_access_mode_t;
enum mgw_errno_value_t
{
MGW_ENOERROR = 0,
@ -43,7 +45,7 @@ struct MgwFd
int value;
};
#ifdef __WIN32__
#if defined(__WIN32__) && !MOO_BUILTIN_MOO_GLIB
# ifdef MOO_GLIB_LIBRARY
# define MOO_GLIB_VAR __declspec(dllexport)
# else

View File

@ -67,7 +67,7 @@ struct _MooCmdClass
#ifdef MOO_PATCHED_G_SPAWN_WIN32_HIDDEN_CONSOLE
#define MOO_SPAWN_WIN32_HIDDEN_CONSOLE G_SPAWN_WIN32_HIDDEN_CONSOLE
#else
#define MOO_SPAWN_WIN32_HIDDEN_CONSOLE 0
#define MOO_SPAWN_WIN32_HIDDEN_CONSOLE ((GSpawnFlags)0)
#endif
GType _moo_cmd_get_type (void) G_GNUC_CONST;

View File

@ -173,6 +173,16 @@ LIST(APPEND built_mooutils_sources marshals.c)
SET(mooutils_win32_sources
mooutils/mooutils-win32.c
)
if(MOO_BUILD_FROM_MSVC)
LIST(APPEND mooutils_sources
mooglib/moo-stat.h
mooglib/moo-time.h
mooglib/moo-glib.c
mooglib/moo-glib.h
)
endif()
SET(mooutils_unittest_sources
mooutils/moo-test-utils.c
mooutils/moo-test-utils.h