From 72fef1d9a94dd41e875e77ae222b2665c7f191a3 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Fri, 3 Mar 2017 17:41:18 +0700 Subject: [PATCH] Fix compile and link on MAC_OS_X --- src/CMakeLists.txt | 15 ++++++++----- src/GLideNHQ/CMakeLists.txt | 25 +++++++++++++-------- src/GLideNHQ/TxInternal.h | 7 ++++-- src/GLideNHQ/TxUtil.cpp | 9 +++++--- src/Graphics/OpenGLContext/GLFunctions.cpp | 20 +++++++++++++++++ src/Graphics/OpenGLContext/GLFunctions.h | 5 +++++ src/Graphics/OpenGLContext/opengl_Utils.cpp | 2 +- src/Log.cpp | 1 + src/mupenplus/CommonAPIImpl_mupenplus.cpp | 10 ++++++++- 9 files changed, 73 insertions(+), 21 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ff8bb689..47fc5114 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -268,13 +268,18 @@ else(EGL) endif(NOT OPENGL_FOUND) endif(EGL) -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - #check for G++ 4.8+ +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + #check for compiler version execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE G++_VERSION) - if (G++_VERSION VERSION_LESS 4.8) - message(SEND_ERROR "You need at least G++ 4.8 to compile GLideN64!") + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND G++_VERSION VERSION_LESS 4.8) + message("Found compiler version " ${G++_VERSION}) + message(SEND_ERROR "You need at least G++ 4.8 to compile GLideN64!") + elseif(G++_VERSION VERSION_LESS 3.3) + message("Found compiler version " ${G++_VERSION}) + message(SEND_ERROR "You need at least Clang 3.3 to compile GLideN64!") endif() - SET(GCC_CPP11_COMPILE_FLAGS "-std=c++0x -static-libgcc") +# SET(GCC_CPP11_COMPILE_FLAGS "-std=c++0x -static-libgcc") + SET(GCC_CPP11_COMPILE_FLAGS "-std=c++0x") SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_CPP11_COMPILE_FLAGS}" ) SET(GCC_STATIC_LINK_FLAGS "-static-libgcc") SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_STATIC_LINK_FLAGS}" ) diff --git a/src/GLideNHQ/CMakeLists.txt b/src/GLideNHQ/CMakeLists.txt index 272d8314..3360ca92 100644 --- a/src/GLideNHQ/CMakeLists.txt +++ b/src/GLideNHQ/CMakeLists.txt @@ -34,10 +34,17 @@ if(GLES2) endif(GLES2) if(UNIX) - add_definitions( - -DNDEBUG - -DOS_LINUX - ) + if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + add_definitions( + -DOS_MAC_OS_X + ) + set(APPLE ON) + elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + add_definitions( + -DNDEBUG + -DOS_LINUX + ) + endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") endif(UNIX) if(WIN32) @@ -67,7 +74,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") add_definitions( -D__MSC__) endif() -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") SET(GCC_CPP11_COMPILE_FLAGS "-std=c++0x") if( NOT GHQCHK ) SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_CPP11_COMPILE_FLAGS} -static -fPIC " ) @@ -88,7 +95,7 @@ if( NOT GHQCHK ) set_target_properties(GLideNHQd PROPERTIES LINK_SEARCH_START_STATIC 1) set_target_properties(GLideNHQd PROPERTIES LINK_SEARCH_END_STATIC 1) - if(MINGW OR BCMHOST) + if(MINGW OR BCMHOST OR APPLE) FIND_PACKAGE( ZLIB REQUIRED ) FIND_PACKAGE( PNG REQUIRED ) target_link_libraries(GLideNHQd @@ -96,14 +103,14 @@ if( NOT GHQCHK ) ${ZLIB_LIBRARIES} osald ) - else(MINGW OR BCMHOST) + else(MINGW OR BCMHOST OR APPLE) target_link_libraries(GLideNHQd PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lib/libpng.a ${CMAKE_CURRENT_SOURCE_DIR}/lib/libz.a dl osald ) - endif(MINGW OR BCMHOST) + endif(MINGW OR BCMHOST OR APPLE) endif( CMAKE_BUILD_TYPE STREQUAL "Debug") if( CMAKE_BUILD_TYPE STREQUAL "Release") @@ -120,7 +127,7 @@ if( NOT GHQCHK ) /mnt/utmp/codeblocks/usr/lib/libz.a osal ) - elseif(BCMHOST OR MINGW) + elseif(BCMHOST OR MINGW OR APPLE) FIND_PACKAGE( ZLIB REQUIRED ) FIND_PACKAGE( PNG REQUIRED ) target_link_libraries(GLideNHQ diff --git a/src/GLideNHQ/TxInternal.h b/src/GLideNHQ/TxInternal.h index c10bac66..b46acfaf 100644 --- a/src/GLideNHQ/TxInternal.h +++ b/src/GLideNHQ/TxInternal.h @@ -53,8 +53,11 @@ #include #define GL_COLOR_INDEX8_EXT 0x80E5 #elif defined(OS_MAC_OS_X) -#include -#include +#include +#include +#ifndef GL_COLOR_INDEX8_EXT +#define GL_COLOR_INDEX8_EXT 0x80E5 +#endif #elif defined(OS_LINUX) #include #include diff --git a/src/GLideNHQ/TxUtil.cpp b/src/GLideNHQ/TxUtil.cpp index 2c5117c4..c72aea4f 100644 --- a/src/GLideNHQ/TxUtil.cpp +++ b/src/GLideNHQ/TxUtil.cpp @@ -24,14 +24,17 @@ #include "TxUtil.h" #include "TxDbg.h" #include -#include #include -#if defined (OS_MAC_OS_X) +#if defined (OS_WINDOWS) +#include +#elif defined (OS_MAC_OS_X) #include #include -#elif defined OS_LINUX +#include +#elif defined (OS_LINUX) #include +#include #endif /* diff --git a/src/Graphics/OpenGLContext/GLFunctions.cpp b/src/Graphics/OpenGLContext/GLFunctions.cpp index e010f0ba..02cfac45 100644 --- a/src/Graphics/OpenGLContext/GLFunctions.cpp +++ b/src/Graphics/OpenGLContext/GLFunctions.cpp @@ -32,6 +32,26 @@ typedef struct __GLXFBConfigRec *GLXFBConfig; #define glGetProcAddress glXGetProcAddress #define GL_GET_PROC_ADR(proc_type, proc_name) g_##proc_name = (proc_type) glGetProcAddress((const GLubyte*)#proc_name) +#elif defined(OS_MAC_OS_X) +#import +#import +#import +void * MyNSGLGetProcAddress (const char *name) +{ + NSSymbol symbol; + char *symbolName; + symbolName = (char*)malloc (strlen (name) + 2); // 1 + strcpy(symbolName + 1, name); // 2 + symbolName[0] = '_'; // 3 + symbol = NULL; + if (NSIsSymbolNameDefined (symbolName)) // 4 + symbol = NSLookupAndBindSymbol (symbolName); + free (symbolName); // 5 + return symbol ? NSAddressOfSymbol (symbol) : NULL; // 6 +} +#define glGetProcAddress MyNSGLGetProcAddress +#define GL_GET_PROC_ADR(proc_type, proc_name) g_##proc_name = (proc_type) glGetProcAddress(#proc_name) + #endif //GL Fucntions diff --git a/src/Graphics/OpenGLContext/GLFunctions.h b/src/Graphics/OpenGLContext/GLFunctions.h index 0ca468e6..b56175dd 100644 --- a/src/Graphics/OpenGLContext/GLFunctions.h +++ b/src/Graphics/OpenGLContext/GLFunctions.h @@ -10,6 +10,11 @@ #ifdef EGL #include +#elif defined(OS_MAC_OS_X) +#include +#include +#include +//#include #else #include #endif diff --git a/src/Graphics/OpenGLContext/opengl_Utils.cpp b/src/Graphics/OpenGLContext/opengl_Utils.cpp index 5620d284..01c43d6e 100644 --- a/src/Graphics/OpenGLContext/opengl_Utils.cpp +++ b/src/Graphics/OpenGLContext/opengl_Utils.cpp @@ -58,7 +58,7 @@ const char* GLErrorString(GLenum errorCode) { GL_INVALID_ENUM, "invalid enumerant" }, { GL_INVALID_VALUE, "invalid value" }, { GL_INVALID_OPERATION, "invalid operation" }, -#ifndef GLESX +#if !defined(GLESX) && !defined(OS_MAC_OS_X) { GL_STACK_OVERFLOW, "stack overflow" }, { GL_STACK_UNDERFLOW, "stack underflow" }, #endif diff --git a/src/Log.cpp b/src/Log.cpp index cf37c094..e2654a7f 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "Log.h" #include "PluginAPI.h" #include "wst.h" diff --git a/src/mupenplus/CommonAPIImpl_mupenplus.cpp b/src/mupenplus/CommonAPIImpl_mupenplus.cpp index f70463aa..b00ea6fb 100644 --- a/src/mupenplus/CommonAPIImpl_mupenplus.cpp +++ b/src/mupenplus/CommonAPIImpl_mupenplus.cpp @@ -1,9 +1,16 @@ #include "GLideN64_mupenplus.h" #include +#include +#include +#include #include #include "../PluginAPI.h" #include "../RSP.h" +#if defined(OS_MAC_OS_X) +#include +#endif + int PluginAPI::InitiateGFX(const GFX_INFO & _gfxInfo) { _initiateGFX(_gfxInfo); @@ -61,9 +68,10 @@ void PluginAPI::FindPluginPath(wchar_t * _strPath) _getWSPath(path, _strPath); } #elif defined(OS_MAC_OS_X) +#define MAXPATHLEN 256 char path[MAXPATHLEN]; uint32_t pathLen = MAXPATHLEN * 2; - if (_NSGetExecutablePath(path, pathLen) == 0) { + if (_NSGetExecutablePath(path, &pathLen) == 0) { _getWSPath(path, _strPath); } #elif defined(OS_ANDROID)