56 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| 
 | |
| import os
 | |
| import platform
 | |
| import re
 | |
| from SCons.Script import *
 | |
| 
 | |
| 
 | |
| def _git_cook(env: Environment, repo: dict) -> dict:
 | |
|     checkout_root = repo['checkout_root']
 | |
| 
 | |
|     if os.path.exists(os.path.join(repo['checkout_root'], 'cmake', 'GetGitRevisionDescription.cmake')):
 | |
|         try:
 | |
|             repo['repo'].git.apply('--unsafe-paths', '--directory', repo['checkout_root'], os.path.join(env['SPP_DIR'], 'recipes', 'SDL', 'fix_sdl3_from_worktree.patch'))
 | |
|         except:
 | |
|             # either already applied or not applicable anymore
 | |
|             pass
 | |
| 
 | |
|     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':
 | |
|             lib_names = ['SDL2-staticd', 'SDL3-static']
 | |
|         else:
 | |
|             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':
 | |
|             lib_names = ['SDL2d', 'SDL3']
 | |
|         else:
 | |
|             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 {
 | |
|         'CPPPATH': [os.path.join(build_result['install_dir'], (is_sdl3 and 'include' or 'include/SDL2'))], # SDL is really weird about include paths ...
 | |
|         'LIBS': libs
 | |
|     }
 | |
| 
 | |
| 
 | |
| env.GitRecipe(
 | |
|     globals = globals(),
 | |
|     repo_name = 'SDL',
 | |
|     repo_url = 'https://github.com/libsdl-org/SDL.git',
 | |
|     tag_pattern = re.compile(r'^release-([0-9]+)\.([0-9]+)\.([0-9]+)$'),
 | |
|     tag_fn = lambda version: f'release-{version[0]}.{version[1]}.{version[2]}',
 | |
|     cook_fn = _git_cook
 | |
| )
 | |
| 
 |