34 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
 | 
						|
import os
 | 
						|
import pathlib
 | 
						|
import subprocess
 | 
						|
import sys
 | 
						|
from SCons.Script import *
 | 
						|
 | 
						|
_BUILT_STAMPFILE = '.spp_built'
 | 
						|
 | 
						|
def cook(env: Environment, project_root: str, generate_args: 'list[str]' = [], build_args : 'list[str]' = [], install_args : 'list[str]' = []) -> dict:
 | 
						|
    config = env['BUILD_TYPE']
 | 
						|
    build_dir = os.path.join(project_root, f'build_{config}')
 | 
						|
    install_dir = os.path.join(project_root, f'install_{config}')
 | 
						|
    is_built = os.path.exists(os.path.join(install_dir, _BUILT_STAMPFILE))
 | 
						|
    if not is_built or env['UPDATE_REPOSITORIES']:
 | 
						|
        print(f'Building {project_root}, 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}', f'-DCMAKE_INSTALL_PREFIX={install_dir}', *generate_args, project_root), stdout=sys.stdout, stderr=sys.stderr, check=True)
 | 
						|
        subprocess.run(('cmake', '--build', *build_args, build_dir), stdout=sys.stdout, stderr=sys.stderr, check=True)
 | 
						|
        subprocess.run(('cmake', '--install', *install_args, build_dir), stdout=sys.stdout, stderr=sys.stderr, check=True)
 | 
						|
        pathlib.Path(install_dir, _BUILT_STAMPFILE).touch()
 | 
						|
 | 
						|
    return {
 | 
						|
        'LIBPATH': [os.path.join(install_dir, 'lib')],
 | 
						|
        'CPPPATH': [os.path.join(install_dir, 'include')]
 | 
						|
    }
 | 
						|
 |