From 941f94a7b6ad9242ee1404663dfd855dcf203817 Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Wed, 11 Sep 2024 09:00:26 +0200 Subject: [PATCH] Adjusted SDL build script to work with SDL3 (kind of). --- recipes/SDL/fix_sdl3_from_worktree.patch | 13 +++++++++++++ recipes/SDL/recipe.py | 22 ++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 recipes/SDL/fix_sdl3_from_worktree.patch diff --git a/recipes/SDL/fix_sdl3_from_worktree.patch b/recipes/SDL/fix_sdl3_from_worktree.patch new file mode 100644 index 0000000..fd28285 --- /dev/null +++ b/recipes/SDL/fix_sdl3_from_worktree.patch @@ -0,0 +1,13 @@ +diff --git a/cmake/GetGitRevisionDescription.cmake b/cmake/GetGitRevisionDescription.cmake +index a08895c64..d3873387d 100644 +--- a/cmake/GetGitRevisionDescription.cmake ++++ b/cmake/GetGitRevisionDescription.cmake +@@ -143,7 +143,7 @@ function(get_git_head_revision _refspecvar _hashvar) + string(REGEX REPLACE "gitdir: (.*)$" "\\1" git_worktree_dir + ${worktree_ref}) + string(STRIP ${git_worktree_dir} git_worktree_dir) +- _git_find_closest_git_dir("${git_worktree_dir}" GIT_DIR) ++ set(GIT_DIR "${git_worktree_dir}") + set(HEAD_SOURCE_FILE "${git_worktree_dir}/HEAD") + endif() + else() diff --git a/recipes/SDL/recipe.py b/recipes/SDL/recipe.py index f473ed6..69f42a7 100644 --- a/recipes/SDL/recipe.py +++ b/recipes/SDL/recipe.py @@ -6,22 +6,32 @@ from SCons.Script import * def _git_cook(env: Environment, repo: dict) -> dict: checkout_root = repo['checkout_root'] + build_result = env.CMakeProject(project_root=checkout_root, generate_args = ['-DSDL_STATIC=ON', '-DSDL_SHARED=OFF']) libs = [] if platform.system() == 'Windows': if env['BUILD_TYPE'] == 'debug': - libs.append('SDL2-staticd') + lib_names = ['SDL2-staticd', 'SDL3-staticd'] else: - libs.append('SDL2-static') + lib_names = ['SDL2-static', 'SDL3-static'] libs.extend(('kernel32', 'user32', 'gdi32', 'winmm', 'imm32', 'ole32', 'oleaut32', 'version', 'uuid', 'advapi32', 'setupapi', 'shell32', 'dinput8')) else: if env['BUILD_TYPE'] == 'debug': - libs.append('SDL2d') + lib_names = ['SDL2d', 'SDL3'] else: - libs.append('SDL2') + lib_names = ['SDL2', 'SDL3'] + lib_file = None + is_sdl3 = False + for lib_name in lib_names: + lib_file = env.FindLib(lib_name, paths=build_result['LIBPATH'], allow_fail=True) + if lib_file: + is_sdl3 = "SDL3" in lib_name + break + if not lib_file: + env.Error('Could not find SDL lib file.') + libs.insert(0, lib_file) return { - 'LIBPATH': build_result['LIBPATH'], - 'CPPPATH': [os.path.join(build_result['install_dir'], 'include/SDL2')], # SDL is really weird about include paths ... + 'CPPPATH': [os.path.join(build_result['install_dir'], (is_sdl3 and 'include' or 'include/SDL2'))], # SDL is really weird about include paths ... 'LIBS': libs }