*/}}
1
0
Просмотр исходного кода

initial attempt to get it to build on macOS with GLFW3

this builds the library at least, but i have no idea if it actually
works yet ;-)

will definitely need to recheck lagui-config.cmake to make sure all
the paths are correct
Georg Gadinger 10 месяцев назад
Родитель
Сommit
204ed24d4d
9 измененных файлов с 90 добавлено и 8 удалено
  1. 3 0
      CMakeLists.txt
  2. 6 0
      la_5.h
  3. 14 0
      la_interface.h
  4. 13 2
      la_kernel.c
  5. 1 1
      la_tns.h
  6. 5 0
      la_tns_kernel.c
  7. 2 2
      la_util.c
  8. 13 3
      la_util.h
  9. 33 0
      lagui-config.cmake

+ 3 - 0
CMakeLists.txt

@@ -23,6 +23,9 @@ find_package(Freetype REQUIRED)
 find_package(GLEW REQUIRED)
 find_package(LuaJIT)
 find_package(PNG)
+if (APPLE)
+    find_package(GLFW3 REQUIRED)
+endif()
 set(CMAKE_CXX_STANDARD 17)
 
 SET(LAGUI_USE_LUAJIT true CACHE BOOL "Whether to use LuaJIT in LaGUI")

+ 6 - 0
la_5.h

@@ -23,6 +23,12 @@
 
 #define BYTE uint8_t
 
+#ifdef __APPLE__
+// on macOS require GL libraries as early as possible without C linkage, libc++ requires templates to have C++ linkage
+#include <GL/glew.h>
+#include <GL/gl.h>
+#endif
+
 #ifdef __cplusplus
     extern "C" {
 #endif

+ 14 - 0
la_interface.h

@@ -116,6 +116,20 @@
 #define XK_F11 11
 #define XK_F12 12
 #endif
+#ifdef __APPLE__ // TODO
+#define XK_F1  1
+#define XK_F2  2
+#define XK_F3  3
+#define XK_F4  4
+#define XK_F5  5
+#define XK_F6  6
+#define XK_F7  7
+#define XK_F8  8
+#define XK_F9  9
+#define XK_F10 10
+#define XK_F11 11
+#define XK_F12 12
+#endif
 #define LA_KEY_F1        XK_F1
 #define LA_KEY_F2        XK_F2
 #define LA_KEY_F3        XK_F3

+ 13 - 2
la_kernel.c

@@ -45,6 +45,9 @@
 #include <X11/cursorfont.h>
 #include <GL/glx.h>
 #endif
+#ifdef __APPLE__
+#include <execinfo.h>
+#endif
 #ifdef _WIN32
 #include <GL/wglew.h>
 #include <GL/wgl.h>
@@ -436,7 +439,7 @@ void la_DestroySystemWindowWin32(laWindow* w) {
 };
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__APPLE__)
 void la_HandlerSIGSEGV(int sig) {
     void *array[30];
     size_t sz;
@@ -527,6 +530,9 @@ int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
 #endif
 #ifdef _WIN32
     SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
+#endif
+#ifdef __APPLE__
+    SYSWINDOW hwnd = glfwCreateWindow(window->W, window->H, window->Title->Ptr, NULL, NULL);
 #endif
     window->win = hwnd;
     window->glc = glc;
@@ -884,7 +890,7 @@ void laProcessInitArguments(int argc, char* argv[],laInitArguments* ia) {
     }
 }
 int laGetReadyWith(laInitArguments* ia){
-#ifdef __linux__
+#if defined(__linux__) || defined(__APPLE__)
     signal(SIGSEGV,la_HandlerSIGSEGV);
 #endif
 
@@ -1134,6 +1140,9 @@ int laGetReadyWith(laInitArguments* ia){
 #endif
 #ifdef __linux__
     int dpi = la_GetDPI(DefaultRootWindow(MAIN.dpy));
+#endif
+#ifdef __APPLE__
+    int dpi = 72;
 #endif
     if((!dpi) || dpi<144){ dpi=144; } if(dpi>300){ dpi=300; }
     int UiSize=(int)(tnsLinearItp(16.0f,24.0f,tnsGetRatiod(96,144,dpi))+0.5);
@@ -1519,7 +1528,9 @@ int la_OnWindowDestroy(SYSWINDOW wnd){
 void la_MakeSpecialKeyBit(SYSWINDOW hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
     laListHandle *el = &wnd->EventList;
     laEvent* last_e=el->pLast;
+#ifndef __APPLE__ // TODO
     SYSWINDOW root_ret, win_ret; int rrx=0,rry=0,rx=e->x,ry=e->y,rmask=0;
+#endif
 #ifdef __linux__
     XQueryPointer(MAIN.dpy, wnd->win, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
     e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);

+ 1 - 1
la_tns.h

@@ -337,7 +337,7 @@ struct _tnsOffscreen
 #ifdef _WIN32
     SYSTEMDC FboDC;
 #endif
-#ifdef __linux__
+#if defined(__linux__) || defined(__APPLE__)
     SYSWINDOW FboWindow;
 #endif
 

+ 5 - 0
la_tns_kernel.c

@@ -137,6 +137,11 @@ void tnsContextMakeCurrent(SYSGLCONTEXT context, SYSTEMDC hdc,void* unused){
     tnsUnbindTexture(); tnsUseNoTexture();
 };
 #endif
+#ifdef __APPLE__
+void tnsContextMakeCurrent(SYSGLCONTEXT context, SYSWINDOW win, void* unused){
+    glfwMakeContextCurrent(context);
+};
+#endif
 #ifdef LA_USE_GLES
 void tnsContextMakeFBOCurrent(tnsOffscreen* off){
     tnsContextMakeCurrent(off->FboContext,off->FboWindow,off->FboSurface);

+ 2 - 2
la_util.c

@@ -62,7 +62,7 @@ struct tm *laGetFullTime(){
 }
 
 void laRecordTime(laTimeRecorder *tr){
-#ifdef __linux__
+#if defined(__linux__) || defined(__APPLE__)
     clock_gettime(CLOCK_REALTIME, &tr->ts);
 #endif
 #ifdef _WIN32
@@ -70,7 +70,7 @@ void laRecordTime(laTimeRecorder *tr){
 #endif
 }
 real laTimeElapsedSecondsf(laTimeRecorder *End, laTimeRecorder *Begin){
-#ifdef __linux__
+#if defined(__linux__) || defined(__APPLE__)
     real sec=End->ts.tv_sec-Begin->ts.tv_sec; sec+=((End->ts.tv_nsec-Begin->ts.tv_nsec)/1e9);
 #endif
 #ifdef _WIN32

+ 13 - 3
la_util.h

@@ -42,11 +42,13 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <ctype.h>
-#ifdef __linux__
+#if defined(__linux__) || defined(__APPLE__)
 #include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
 #include <wchar.h>
+#endif
+#ifdef __linux__
 #define SYSWINDOW Window
 #ifdef LA_USE_GLES
 	#define SYSGLCONTEXT EGLContext
@@ -69,6 +71,14 @@
 #define PATH_MAX 4096
 #define SYSLOCK CRITICAL_SECTION
 #endif
+#ifdef __APPLE__
+#include <os/lock.h>
+#include <GLFW/glfw3.h>
+#define SYSLOCK os_unfair_lock
+#define SYSGLCONTEXT GLFWwindow*
+#define SYSWINDOW GLFWwindow*
+#define SYSTEMDISPLAY uint32_t
+#endif
 
 #ifdef LA_WITH_LUAJIT
 
@@ -404,8 +414,8 @@ STRUCTURE(laAVLTreeReal64) {
 };
 
 STRUCTURE(laTimeRecorder) {
-#ifdef __linux__
-	struct timespec ts;
+#if defined(__linux__) || defined(__APPLE__)
+    struct timespec ts;
 #endif
 #ifdef _WIN32
 	LARGE_INTEGER tm;

+ 33 - 0
lagui-config.cmake

@@ -24,6 +24,9 @@ find_package(Freetype REQUIRED)
 find_package(GLEW REQUIRED)
 find_package(PNG)
 find_package(LuaJIT)
+if (APPLE)
+    find_package(GLFW3 REQUIRED)
+endif()
 
 set(CMAKE_THREAD_PREFER_PTHREAD ON)
 set(THREADS_PREFER_PTHREAD_FLAG ON)
@@ -73,6 +76,36 @@ if (CMAKE_SYSTEM_NAME MATCHES "Linux")
         list(APPEND LAGUI_SHARED_LIBS ${PNG_LIBRARY})
         list(APPEND LAGUI_INCLUDE_DIRS_ALL ${PNG_INCLUDE_DIR})
     endif()
+elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
+    set(LAGUI_SHARED_LIBS
+        ${OPENGL_LIBRARY}
+        ${GLEW_LIBRARIES}
+        ${LAGUI_GL_LIB}
+        ${FREETYPE_LIBRARIES}
+        m
+        ${GLFW3_LIBRARIES}
+        ${CMAKE_DL_LIBS}
+        Threads::Threads
+        ${LUA_LIBRARY}
+        lagui
+        CACHE INTERNAL "LaGUI shared libs"
+    )
+    set(LAGUI_INCLUDE_DIRS_ALL
+        ${OPENGL_LIBRARY}
+        ${CMAKE_SOURCE_DIR}
+        ${GLEW_INCLUDE_PATH}
+        ${FREETYPE_INCLUDE_DIRS}
+        ${LAGUI_INCLUDE_DIRS}
+        CACHE INTERNAL "Include dirs of LaGUI and dependencies"
+    )
+    if(${LuaJIT_FOUND})
+        list(APPEND LAGUI_SHARED_LIBS ${LUA_LIBRARY})
+        list(APPEND LAGUI_INCLUDE_DIRS_ALL ${LUA_INCLUDE_DIR})
+    endif()
+    if(${PNG_FOUND})
+        list(APPEND LAGUI_SHARED_LIBS ${PNG_LIBRARY})
+        list(APPEND LAGUI_INCLUDE_DIRS_ALL ${PNG_INCLUDE_DIR})
+    endif()
 elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
     set(LAGUI_SHARED_LIBS
         ${GLEW_LIBRARIES}