From 899e1fbd94f697d95b9684e272de5410b08edc06 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Wed, 22 Nov 2017 22:47:57 +0100 Subject: [PATCH 1/2] Avoid duplicate definition of feature macro Feature macros need to be defined before #including any headers, preferably through the build system, but this is good enough. Fixes a compile error on my fork's Travis CI. --- src/core.c | 9 +++++---- src/gestures.h | 5 ++++- src/physac.h | 28 ++++++++++++++++------------ 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/core.c b/src/core.c index 97d8a74c9..c11c69ce0 100644 --- a/src/core.c +++ b/src/core.c @@ -88,6 +88,11 @@ #include "raylib.h" +#if (defined(__linux__) || defined(PLATFORM_WEB)) && _POSIX_S_SOURCE < 199309L + #undef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 199309L // Required for CLOCK_MONOTONIC if compiled with c99 without gnu ext. +#endif + #include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2 #include "utils.h" // Required for: fopen() Android mapping @@ -110,10 +115,6 @@ #include "external/rgif.h" // Support GIF recording #endif -#if defined(__linux__) || defined(PLATFORM_WEB) - #define _POSIX_C_SOURCE 199309L // Required for CLOCK_MONOTONIC if compiled with c99 without gnu ext. -#endif - #include // Standard input / output lib #include // Required for: malloc(), free(), rand(), atexit() #include // Required for: typedef unsigned long long int uint64_t, used by hi-res timer diff --git a/src/gestures.h b/src/gestures.h index f4d38dfb9..2e3431549 100644 --- a/src/gestures.h +++ b/src/gestures.h @@ -148,7 +148,10 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount); int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency); #elif defined(__linux__) - #define _POSIX_C_SOURCE 199309L // Required for CLOCK_MONOTONIC if compiled with c99 without gnu ext. + #if _POSIX_C_SOURCE < 199309L + #undef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 199309L // Required for CLOCK_MONOTONIC if compiled with c99 without gnu ext. + #endif #include // Required for: timespec #include // Required for: clock_gettime() #endif diff --git a/src/physac.h b/src/physac.h index 5ecd28151..ef78aab87 100644 --- a/src/physac.h +++ b/src/physac.h @@ -235,6 +235,22 @@ PHYSACDEF void ClosePhysics(void); #if defined(PHYSAC_IMPLEMENTATION) +#if defined(_WIN32) + // Functions required to query time on Windows + int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount); + int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency); +#elif (defined(__linux__) || defined(__APPLE__) || defined(PLATFORM_WEB)) + #if _POSIX_C_SOURCE < 199309L + #undef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 199309L // Required for CLOCK_MONOTONIC if compiled with c99 without gnu ext. + #endif + //#define _DEFAULT_SOURCE // Enables BSD function definitions and C99 POSIX compliance + #include // Required for: timespec + #include // Required for: clock_gettime() + #include +#endif + + #if !defined(PHYSAC_NO_THREADS) #include // Required for: pthread_t, pthread_create() #endif @@ -248,18 +264,6 @@ PHYSACDEF void ClosePhysics(void); #include "raymath.h" // Required for: Vector2Add(), Vector2Subtract() -#if defined(_WIN32) - // Functions required to query time on Windows - int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount); - int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency); -#elif defined(__linux__) || defined(__APPLE__) || defined(PLATFORM_WEB) - #define _POSIX_C_SOURCE 199309L // Required for CLOCK_MONOTONIC if compiled with c99 without gnu ext. - //#define _DEFAULT_SOURCE // Enables BSD function definitions and C99 POSIX compliance - #include // Required for: timespec - #include // Required for: clock_gettime() - #include -#endif - //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- From b2acff66dec7bce30e9704aa9b13070f7c3ffac1 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Wed, 22 Nov 2017 22:33:47 +0100 Subject: [PATCH 2/2] Fix macOS build of new rglfw.c approach There have been two problems: * GLFW itself was compiled with the definitions for compiling _against_ GLFW (fixed by removing requirement for external glfw) * rglfw.c was being compiled as C code, although it includes Objective C files. This _might_ break the Windows build, needs to be checked. Fixes #391, but as noted I'd prefer though a separate source directory and build script for GLFW. --- .travis.yml | 3 +-- src/CMakeLists.txt | 6 +++--- src/gestures.h | 6 +++--- src/rglfw.c | 2 +- utils.cmake | 7 ------- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7a5148ad1..8b122c475 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,9 +25,8 @@ before_install: libopenal-dev libxcursor-dev libxinerama-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev libglew-dev; - wget 'https://github.com/a3f/GLFW-3.2.1-Debian-binary-package/releases/download/v3.2.1/GLFW-3.2.1-Linux.deb' && sudo dpkg -i GLFW-3.2.1-Linux.deb; fi - - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; brew install glfw; export CC=clang; fi + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; brew install glfw; fi - "$CC --version" script: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a398d6656..f362b52f9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,6 +20,7 @@ set(OPENGL_VERSION "3.3" CACHE STRING "OpenGL Version to build raylib with") set_property(CACHE OPENGL_VERSION PROPERTY STRINGS "3.3" "2.1" "1.1" "ES 2.0") ### Config options ### +include_directories(external/glfw/include) # Translate the config options to what raylib wants if(${PLATFORM} MATCHES "Desktop") @@ -40,6 +41,8 @@ if(${PLATFORM} MATCHES "Desktop") # See: https://github.com/raysan5/raylib/issues/341 if(APPLE) set(GRAPHICS "GRAPHICS_API_OPENGL_33") + set_source_files_properties(rglfw.c PROPERTIES COMPILE_FLAGS "-x objective-c") + link_libraries("-framework CoreFoundation -framework Cocoa -framework IOKit -framework CoreVideo") endif() elseif(${PLATFORM} MATCHES "Web") set(PLATFORM "PLATFORM_WEB") @@ -93,9 +96,6 @@ if(${PLATFORM} MATCHES "PLATFORM_DESKTOP") target_link_libraries(${RAYLIB} GL) endif() - # Add in GLFW as a linking target - target_link_libraries(${RAYLIB} glfw) - # Library file & Header set_target_properties(${RAYLIB} PROPERTIES PUBLIC_HEADER "raylib.h") install( diff --git a/src/gestures.h b/src/gestures.h index 2e3431549..e2f004e2c 100644 --- a/src/gestures.h +++ b/src/gestures.h @@ -140,9 +140,6 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang #if defined(GESTURES_IMPLEMENTATION) -#include // Required for: atan2(), sqrt() -#include // Required for: uint64_t - #if defined(_WIN32) // Functions required to query time on Windows int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount); @@ -154,6 +151,9 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang #endif #include // Required for: timespec #include // Required for: clock_gettime() + + #include // Required for: atan2(), sqrt() + #include // Required for: uint64_t #endif //---------------------------------------------------------------------------------- diff --git a/src/rglfw.c b/src/rglfw.c index b1b4eed70..83e0021bf 100644 --- a/src/rglfw.c +++ b/src/rglfw.c @@ -86,5 +86,5 @@ #include "external/glfw/src/posix_thread.c" #include "external/glfw/src/nsgl_context.m" #include "external/glfw/src/egl_context.c" - #include "external/glfw/src/osmesa_context.c.m" + #include "external/glfw/src/osmesa_context.c" #endif diff --git a/utils.cmake b/utils.cmake index c902f60e3..f260fa5e5 100644 --- a/utils.cmake +++ b/utils.cmake @@ -6,10 +6,6 @@ if(UNIX AND NOT APPLE) set(LINUX TRUE) endif() -# Need GLFW 3.2.1 -find_package(glfw3 3.2.1 REQUIRED) - - # Linking for OS X -framework options # Will do nothing on other OSes function(link_os_x_frameworks binary) @@ -40,9 +36,6 @@ function(link_libraries_to_executable executable) # TODO windows endif() - # Add in GLFW as a linking target - target_link_libraries(${executable} glfw) - # And raylib target_link_libraries(${executable} raylib) endfunction()