41 lines
1.7 KiB
Python

import os
import subprocess
import sys
from SCons.Script import *
def cook(env: Environment, git_ref: str = "main") -> dict:
repo = env.Cook('GitBranch', repo_name = 'SDL', remote_url = 'https://github.com/libsdl-org/SDL.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
config = env['BUILD_TYPE']
build_dir = os.path.join(checkout_root, f'build_{config}')
install_dir = os.path.join(checkout_root, f'install_{config}')
lib_fname = {
'debug': 'libSDL2d.a'
}.get(env['BUILD_TYPE'], 'libSDL2.a') # TODO: who cares about windows?
is_built = os.path.exists(os.path.join(build_dir, lib_fname)) # TODO!
if not is_built:
print(f'Building SDL, config {config}')
os.makedirs(build_dir, exist_ok=True)
build_type = {
'debug': 'Debug',
'release_debug': 'RelWithDebInfo',
'release': 'Release',
'profile': 'RelWithDebInfo'
}.get(env['BUILD_TYPE'], 'RelWithDebInfo')
subprocess.run(('cmake', '-G', 'Ninja', '-B', build_dir, f'-DCMAKE_BUILD_TYPE={build_type}', '-DSDL_STATIC=ON', '-DSDL_SHARED=OFF', f'-DCMAKE_INSTALL_PREFIX={install_dir}', checkout_root), stdout=sys.stdout, stderr=sys.stderr, check=True)
subprocess.run(('cmake', '--build', build_dir), stdout=sys.stdout, stderr=sys.stderr, check=True)
subprocess.run(('cmake', '--install', build_dir), stdout=sys.stdout, stderr=sys.stderr, check=True)
lib_name = {
'debug': 'SDL2d'
}.get(env['BUILD_TYPE'], 'SDL2')
return {
'LIBPATH': [os.path.join(install_dir, 'lib')],
'CPPPATH': [os.path.join(install_dir, 'include')],
'LIBS': [lib_name, 'm']
}