Compare commits
2 commits
master
...
env-vars-f
Author | SHA1 | Date | |
---|---|---|---|
|
c1e3fa2eca | ||
|
f6b6942292 |
1 changed files with 68 additions and 25 deletions
|
@ -15,36 +15,50 @@
|
||||||
# Assumes raylib, GL, etc are all already installed as system libraries. We dont distribute them.
|
# Assumes raylib, GL, etc are all already installed as system libraries. We dont distribute them.
|
||||||
# Raylib must be installed and compiled with: cmake -DWITH_PIC=ON -DSHARED=ON -DSTATIC=ON ..
|
# Raylib must be installed and compiled with: cmake -DWITH_PIC=ON -DSHARED=ON -DSTATIC=ON ..
|
||||||
|
|
||||||
# We use /usr/local/lib/libraylib.a to ensure we link to static version
|
|
||||||
import re
|
|
||||||
|
|
||||||
|
import re
|
||||||
from cffi import FFI
|
from cffi import FFI
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import sys
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
# Environment variables you can set before build
|
||||||
|
#
|
||||||
|
# RAYLIB_PLATFORM: Any one of: Desktop, SDL, DRM, PLATFORM_COMMA
|
||||||
|
# RAYLIB_LINK_ARGS: Arguments to pass to the linker rather than getting them from pkg-config.
|
||||||
|
# e.g.: -L/usr/local/lib -lraylib
|
||||||
|
# RAYLIB_INCLUDE_PATH: Directory to find raylib.h rather than getting from pkg-config.
|
||||||
|
# e.g.: /usr/local/include
|
||||||
|
# RAYGUI_INCLUDE_PATH: Directory to find raygui.h
|
||||||
|
# e.g.: /usr/local/include
|
||||||
|
# GLFW_INCLUDE_PATH: Directory to find glfw3.h
|
||||||
|
# e.g.: /usr/local/include/GLFW
|
||||||
|
# PHYSAC_INCLUDE_PATH: Directory to find physac.h
|
||||||
|
# e.g.: /usr/local/include
|
||||||
|
# LIBFFI_INCLUDE_PATH:
|
||||||
|
# e.g.: /usr/local/include
|
||||||
|
|
||||||
RAYLIB_PLATFORM = os.getenv("RAYLIB_PLATFORM", "Desktop")
|
RAYLIB_PLATFORM = os.getenv("RAYLIB_PLATFORM", "Desktop")
|
||||||
|
|
||||||
def check_raylib_installed():
|
def check_raylib_pkgconfig_installed():
|
||||||
return subprocess.run(['pkg-config', '--exists', 'raylib'], text=True, stdout=subprocess.PIPE).returncode == 0
|
return subprocess.run(['pkg-config', '--exists', 'raylib'], text=True, stdout=subprocess.PIPE).returncode == 0
|
||||||
|
|
||||||
def check_SDL_installed():
|
def check_sdl_pkgconfig_installed():
|
||||||
return subprocess.run(['pkg-config', '--exists', 'sdl2'], text=True, stdout=subprocess.PIPE).returncode == 0
|
return subprocess.run(['pkg-config', '--exists', 'sdl2'], text=True, stdout=subprocess.PIPE).returncode == 0
|
||||||
|
|
||||||
def get_the_include_path():
|
def get_the_include_path_from_pkgconfig():
|
||||||
return subprocess.run(['pkg-config', '--variable=includedir', 'raylib'], text=True,
|
return subprocess.run(['pkg-config', '--variable=includedir', 'raylib'], text=True,
|
||||||
stdout=subprocess.PIPE).stdout.strip()
|
stdout=subprocess.PIPE).stdout.strip()
|
||||||
|
|
||||||
|
|
||||||
def get_the_lib_path():
|
def get_the_lib_path_from_pkgconfig():
|
||||||
return subprocess.run(['pkg-config', '--variable=libdir', 'raylib'], text=True,
|
return subprocess.run(['pkg-config', '--variable=libdir', 'raylib'], text=True,
|
||||||
stdout=subprocess.PIPE).stdout.strip()
|
stdout=subprocess.PIPE).stdout.strip()
|
||||||
|
|
||||||
def get_lib_flags():
|
def get_lib_flags_from_pkgconfig():
|
||||||
return subprocess.run(['pkg-config', '--libs', 'raylib'], text=True,
|
return subprocess.run(['pkg-config', '--libs', 'raylib'], text=True,
|
||||||
stdout=subprocess.PIPE).stdout.strip().split()
|
stdout=subprocess.PIPE).stdout.strip()
|
||||||
|
|
||||||
def pre_process_header(filename, remove_function_bodies=False):
|
def pre_process_header(filename, remove_function_bodies=False):
|
||||||
print("Pre-processing " + filename)
|
print("Pre-processing " + filename)
|
||||||
|
@ -104,24 +118,29 @@ def check_header_exists(file):
|
||||||
|
|
||||||
|
|
||||||
def build_unix():
|
def build_unix():
|
||||||
if not check_raylib_installed():
|
if os.getenv("RAYLIB_LINK_ARGS") is None and not check_raylib_pkgconfig_installed():
|
||||||
raise Exception("ERROR: raylib not found by pkg-config. Please install pkg-config and Raylib.")
|
raise Exception("ERROR: raylib not found by pkg-config. Please install pkg-config and Raylib"
|
||||||
|
"or else set RAYLIB_LINK_ARGS env variable.")
|
||||||
|
|
||||||
if RAYLIB_PLATFORM=="SDL" and not check_SDL_installed():
|
if RAYLIB_PLATFORM=="SDL" and os.getenv("RAYLIB_LINK_ARGS") is None and not check_sdl_pkgconfig_installed():
|
||||||
raise Exception("ERROR: SDL2 not found by pkg-config. Please install pkg-config and SDL2.")
|
raise Exception("ERROR: SDL2 not found by pkg-config. Please install pkg-config and SDL2."
|
||||||
|
"or else set RAYLIB_LINK_ARGS env variable.")
|
||||||
|
|
||||||
raylib_h = get_the_include_path() + "/raylib.h"
|
raylib_include_path = os.getenv("RAYLIB_INCLUDE_PATH")
|
||||||
rlgl_h = get_the_include_path() + "/rlgl.h"
|
if raylib_include_path is None:
|
||||||
raymath_h = get_the_include_path() + "/raymath.h"
|
raylib_include_path = get_the_include_path_from_pkgconfig()
|
||||||
|
raylib_h = raylib_include_path + "/raylib.h"
|
||||||
|
rlgl_h = raylib_include_path + "/rlgl.h"
|
||||||
|
raymath_h = raylib_include_path + "/raymath.h"
|
||||||
|
|
||||||
if not os.path.isfile(raylib_h):
|
if not os.path.isfile(raylib_h):
|
||||||
raise Exception("ERROR: " + raylib_h + " not found. Please install Raylib.")
|
raise Exception("ERROR: " + raylib_h + " not found. Please install Raylib or set RAYLIB_INCLUDE_PATH.")
|
||||||
|
|
||||||
if not os.path.isfile(rlgl_h):
|
if not os.path.isfile(rlgl_h):
|
||||||
raise Exception("ERROR: " + rlgl_h + " not found. Please install Raylib.")
|
raise Exception("ERROR: " + rlgl_h + " not found. Please install Raylib or set RAYLIB_INCLUDE_PATH.")
|
||||||
|
|
||||||
if not os.path.isfile(raymath_h):
|
if not os.path.isfile(raymath_h):
|
||||||
raise Exception("ERROR: " + raylib_h + " not found. Please install Raylib.")
|
raise Exception("ERROR: " + raylib_h + " not found. Please install Raylib or set RAYLIB_INCLUDE_PATH.")
|
||||||
|
|
||||||
ffi_includes = """
|
ffi_includes = """
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
@ -129,13 +148,19 @@ def build_unix():
|
||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
glfw3_h = get_the_include_path() + "/GLFW/glfw3.h"
|
glfw_include_path = os.getenv("GLFW_INCLUDE_PATH")
|
||||||
|
if glfw_include_path is None:
|
||||||
|
glfw_include_path = get_the_include_path_from_pkgconfig()
|
||||||
|
glfw3_h = glfw_include_path + "/GLFW/glfw3.h"
|
||||||
if RAYLIB_PLATFORM=="Desktop" and check_header_exists(glfw3_h):
|
if RAYLIB_PLATFORM=="Desktop" and check_header_exists(glfw3_h):
|
||||||
ffi_includes += """
|
ffi_includes += """
|
||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raygui_h = get_the_include_path() + "/raygui.h"
|
raygui_include_path = os.getenv("RAYGUI_INCLUDE_PATH")
|
||||||
|
if raygui_include_path is None:
|
||||||
|
raygui_include_path = get_the_include_path_from_pkgconfig()
|
||||||
|
raygui_h = raygui_include_path + "/raygui.h"
|
||||||
if check_header_exists(raygui_h):
|
if check_header_exists(raygui_h):
|
||||||
ffi_includes += """
|
ffi_includes += """
|
||||||
#define RAYGUI_IMPLEMENTATION
|
#define RAYGUI_IMPLEMENTATION
|
||||||
|
@ -143,13 +168,20 @@ def build_unix():
|
||||||
#include "raygui.h"
|
#include "raygui.h"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
physac_h = get_the_include_path() + "/physac.h"
|
physac_include_path = os.getenv("PHYSAC_INCLUDE_PATH")
|
||||||
|
if physac_include_path is None:
|
||||||
|
physac_include_path = get_the_include_path_from_pkgconfig()
|
||||||
|
physac_h = physac_include_path + "/physac.h"
|
||||||
if check_header_exists(physac_h):
|
if check_header_exists(physac_h):
|
||||||
ffi_includes += """
|
ffi_includes += """
|
||||||
#define PHYSAC_IMPLEMENTATION
|
#define PHYSAC_IMPLEMENTATION
|
||||||
#include "physac.h"
|
#include "physac.h"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
libffi_include_path = os.getenv("LIBFFI_INCLUDE_PATH")
|
||||||
|
if libffi_include_path is None:
|
||||||
|
libffi_include_path = get_the_include_path_from_pkgconfig()
|
||||||
|
|
||||||
ffibuilder.cdef(pre_process_header(raylib_h))
|
ffibuilder.cdef(pre_process_header(raylib_h))
|
||||||
ffibuilder.cdef(pre_process_header(rlgl_h))
|
ffibuilder.cdef(pre_process_header(rlgl_h))
|
||||||
ffibuilder.cdef(pre_process_header(raymath_h, True))
|
ffibuilder.cdef(pre_process_header(raymath_h, True))
|
||||||
|
@ -164,7 +196,11 @@ def build_unix():
|
||||||
|
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
print("BUILDING FOR MAC")
|
print("BUILDING FOR MAC")
|
||||||
extra_link_args = [get_the_lib_path() + '/libraylib.a', '-framework', 'OpenGL', '-framework', 'Cocoa',
|
flags = os.getenv("RAYLIB_LINK_ARGS")
|
||||||
|
if flags is None:
|
||||||
|
flags = get_the_lib_path_from_pkgconfig() + '/libraylib.a'
|
||||||
|
# We use /usr/local/lib/libraylib.a to ensure we link to static version
|
||||||
|
extra_link_args = flags.split() + ['-framework', 'OpenGL', '-framework', 'Cocoa',
|
||||||
'-framework', 'IOKit', '-framework', 'CoreFoundation', '-framework',
|
'-framework', 'IOKit', '-framework', 'CoreFoundation', '-framework',
|
||||||
'CoreVideo']
|
'CoreVideo']
|
||||||
if RAYLIB_PLATFORM=="SDL":
|
if RAYLIB_PLATFORM=="SDL":
|
||||||
|
@ -174,12 +210,18 @@ def build_unix():
|
||||||
extra_compile_args = ["-Wno-error=incompatible-function-pointer-types", "-D_CFFI_NO_LIMITED_API"]
|
extra_compile_args = ["-Wno-error=incompatible-function-pointer-types", "-D_CFFI_NO_LIMITED_API"]
|
||||||
else: #platform.system() == "Linux":
|
else: #platform.system() == "Linux":
|
||||||
print("BUILDING FOR LINUX")
|
print("BUILDING FOR LINUX")
|
||||||
extra_link_args = get_lib_flags() + [ '-lm', '-lpthread', '-lGL',
|
flags = os.getenv("RAYLIB_LINK_ARGS")
|
||||||
|
if flags is None:
|
||||||
|
flags = get_lib_flags_from_pkgconfig()
|
||||||
|
extra_link_args = flags.split() + [ '-lm', '-lpthread', '-lGL',
|
||||||
'-lrt', '-lm', '-ldl', '-lpthread', '-latomic']
|
'-lrt', '-lm', '-ldl', '-lpthread', '-latomic']
|
||||||
if RAYLIB_PLATFORM=="SDL":
|
if RAYLIB_PLATFORM=="SDL":
|
||||||
extra_link_args += ['-lX11','-lSDL2']
|
extra_link_args += ['-lX11','-lSDL2']
|
||||||
elif RAYLIB_PLATFORM=="DRM":
|
elif RAYLIB_PLATFORM=="DRM":
|
||||||
extra_link_args += ['-lEGL', '-lgbm']
|
extra_link_args += ['-lEGL', '-lgbm']
|
||||||
|
elif RAYLIB_PLATFORM=="PLATFORM_COMMA":
|
||||||
|
extra_link_args.remove('-lGL')
|
||||||
|
extra_link_args += ['-lGLESv2', '-lEGL', '-lwayland-client', '-lwayland-egl']
|
||||||
else:
|
else:
|
||||||
extra_link_args += ['-lX11']
|
extra_link_args += ['-lX11']
|
||||||
extra_compile_args = ["-Wno-incompatible-pointer-types", "-D_CFFI_NO_LIMITED_API"]
|
extra_compile_args = ["-Wno-incompatible-pointer-types", "-D_CFFI_NO_LIMITED_API"]
|
||||||
|
@ -192,7 +234,8 @@ def build_unix():
|
||||||
ffibuilder.set_source("raylib._raylib_cffi",
|
ffibuilder.set_source("raylib._raylib_cffi",
|
||||||
ffi_includes,
|
ffi_includes,
|
||||||
py_limited_api=False,
|
py_limited_api=False,
|
||||||
include_dirs=[get_the_include_path()],
|
include_dirs=[raylib_include_path, raygui_include_path, physac_include_path, glfw_include_path,
|
||||||
|
libffi_include_path],
|
||||||
extra_link_args=extra_link_args,
|
extra_link_args=extra_link_args,
|
||||||
extra_compile_args=extra_compile_args,
|
extra_compile_args=extra_compile_args,
|
||||||
libraries=libraries)
|
libraries=libraries)
|
||||||
|
|
Reference in a new issue