|
1 | | -diff --git a/codemp/rd-rend2/CMakeLists.txt b/codemp/rd-rend2/CMakeLists.txt |
2 | | -index 786cf25..44ecef9 100644 |
| 1 | +From: Batocera build system |
| 2 | +Subject: [PATCH] Allow cross-compiling: import a pre-built compact_glsl and |
| 3 | + keep its sources compilable without an OpenGL development package |
| 4 | + |
| 5 | +When cross-compiling, the rd-rend2 GLSL "compact_glsl" code-generator must run |
| 6 | +on the build host (not the target). Two source-level changes let the |
| 7 | +build system pre-compile compact_glsl with the host toolchain and hand the |
| 8 | +resulting binary to the CMake cross build: |
| 9 | + |
| 10 | + * codemp/rd-rend2/CMakeLists.txt: |
| 11 | + - If -Dcompact_glsl_EXECUTABLE=<path> is passed, declare compact_glsl |
| 12 | + as an IMPORTED GLOBAL executable target pointing at that path |
| 13 | + instead of compiling it for the target architecture. |
| 14 | + - The custom-command that invokes compact_glsl uses the bare target |
| 15 | + name (resolved by CMake to either the in-tree binary or the imported |
| 16 | + location) so the in-build relative path is no longer hard-coded; |
| 17 | + this is the same branch used on Win32 / Apple. |
| 18 | + |
| 19 | + * codemp/rd-rend2/qgl.h: |
| 20 | + - Wraps the entire body of the header in #if !defined(GLSL_BUILDTOOL). |
| 21 | + Under GLSL_BUILDTOOL we provide stubs for the seven GL types that |
| 22 | + tr_local.h actually references (GLuint, GLenum, GLint, GLsizei, |
| 23 | + GLfloat, GLboolean, GLsync) and the GL_UNSIGNED_INT macro, then |
| 24 | + short-circuit before the qgl* function-pointer wrappers and the PFN* |
| 25 | + extern declarations. This lets compact_glsl be compiled directly by |
| 26 | + the build system's HOSTCXX without an OpenGL development package on |
| 27 | + the build machine. |
| 28 | + |
3 | 29 | --- a/codemp/rd-rend2/CMakeLists.txt |
4 | 30 | +++ b/codemp/rd-rend2/CMakeLists.txt |
5 | | -@@ -193,7 +193,7 @@ if (NOT WIN32 AND NOT APPLE) |
6 | | - target_compile_definitions(compact_glsl PRIVATE "ARCH_STRING=\"${Architecture}\"") |
| 31 | +@@ -182,18 +182,25 @@ |
| 32 | + target_link_libraries(${MPRend2} ${MPRend2Libraries}) |
| 33 | + target_include_directories(${MPRend2} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
| 34 | + |
| 35 | +-# GLSL shader file generator |
| 36 | +-add_executable(compact_glsl |
| 37 | +- ${MPDir}/rd-rend2/glsl/compact.cpp |
| 38 | +- ${MPDir}/rd-rend2/tr_allocator.cpp |
| 39 | +- ${MPDir}/rd-rend2/tr_allocator.h |
| 40 | +- ${MPDir}/rd-rend2/tr_glsl_parse.cpp) |
| 41 | +-target_compile_definitions(compact_glsl PRIVATE "GLSL_BUILDTOOL" "NOMINMAX") |
| 42 | +-if (NOT WIN32 AND NOT APPLE) |
| 43 | +- target_compile_definitions(compact_glsl PRIVATE "ARCH_STRING=\"${Architecture}\"") |
| 44 | ++# GLSL shader file generator. When cross-compiling, the build system can |
| 45 | ++# supply a pre-built host binary via -Dcompact_glsl_EXECUTABLE=<path>, in |
| 46 | ++# which case we import it instead of building one for the target. |
| 47 | ++if(compact_glsl_EXECUTABLE) |
| 48 | ++ add_executable(compact_glsl IMPORTED GLOBAL) |
| 49 | ++ set_target_properties(compact_glsl PROPERTIES IMPORTED_LOCATION "${compact_glsl_EXECUTABLE}") |
| 50 | ++else() |
| 51 | ++ add_executable(compact_glsl |
| 52 | ++ ${MPDir}/rd-rend2/glsl/compact.cpp |
| 53 | ++ ${MPDir}/rd-rend2/tr_allocator.cpp |
| 54 | ++ ${MPDir}/rd-rend2/tr_allocator.h |
| 55 | ++ ${MPDir}/rd-rend2/tr_glsl_parse.cpp) |
| 56 | ++ target_compile_definitions(compact_glsl PRIVATE "GLSL_BUILDTOOL" "NOMINMAX") |
| 57 | ++ if (NOT WIN32 AND NOT APPLE) |
| 58 | ++ target_compile_definitions(compact_glsl PRIVATE "ARCH_STRING=\"${Architecture}\"") |
| 59 | ++ endif() |
| 60 | ++ target_include_directories(compact_glsl PRIVATE "${MPRend2IncludeDirectories}") |
7 | 61 | endif() |
8 | | - target_include_directories(compact_glsl PRIVATE "${MPRend2IncludeDirectories}") |
| 62 | +-target_include_directories(compact_glsl PRIVATE "${MPRend2IncludeDirectories}") |
9 | 63 | -if (WIN32 OR APPLE) |
10 | | -+if (WIN32 OR APPLE OR CMAKE_CROSSCOMPILING) |
| 64 | ++if (WIN32 OR APPLE OR compact_glsl_EXECUTABLE) |
11 | 65 | add_custom_command( |
12 | 66 | OUTPUT |
13 | 67 | ${CMAKE_CURRENT_BINARY_DIR}/glsl_shaders.cpp |
| 68 | +--- a/codemp/rd-rend2/qgl.h |
| 69 | ++++ b/codemp/rd-rend2/qgl.h |
| 70 | +@@ -1,5 +1,24 @@ |
| 71 | + #pragma once |
| 72 | + |
| 73 | ++#if defined(GLSL_BUILDTOOL) |
| 74 | ++// The compact_glsl code-generator only includes this header transitively via |
| 75 | ++// tr_local.h; it never calls OpenGL. Provide the minimal subset of GL types |
| 76 | ++// and macros referenced by tr_local.h so the tool can be compiled on a host |
| 77 | ++// that has no OpenGL development files installed, and stop here -- the rest |
| 78 | ++// of qgl.h (qgl* function-pointer wrappers and PFN externs) needs the full |
| 79 | ++// glext.h definitions and is unused by the tool. |
| 80 | ++typedef unsigned int GLenum; |
| 81 | ++typedef unsigned char GLboolean; |
| 82 | ++typedef unsigned int GLuint; |
| 83 | ++typedef int GLint; |
| 84 | ++typedef int GLsizei; |
| 85 | ++typedef float GLfloat; |
| 86 | ++typedef struct __GLsync *GLsync; |
| 87 | ++#ifndef GL_UNSIGNED_INT |
| 88 | ++#define GL_UNSIGNED_INT 0x1405 |
| 89 | ++#endif |
| 90 | ++#else // GLSL_BUILDTOOL |
| 91 | ++ |
| 92 | + #if defined( __LINT__ ) |
| 93 | + # include <GL/gl.h> |
| 94 | + #elif defined( _WIN32 ) |
| 95 | +@@ -614,3 +633,5 @@ |
| 96 | + extern PFNGLQUERYCOUNTERPROC qglQueryCounter; |
| 97 | + extern PFNGLGETQUERYOBJECTI64VPROC qglGetQueryObjecti64v; |
| 98 | + extern PFNGLGETQUERYOBJECTUI64VPROC qglGetQueryObjectui64v; |
| 99 | ++ |
| 100 | ++#endif // GLSL_BUILDTOOL |
0 commit comments