Added imgui and an option to inject source files into dependant projects.

This commit is contained in:
Patrick 2023-11-28 01:36:23 +01:00
parent d15baed4c4
commit 30e7e348c6
3 changed files with 37 additions and 3 deletions

View File

@ -30,15 +30,17 @@ def _inject_list(kwargs: dict, dependency: dict, list_name: str) -> None:
kwargs[list_name] = []
kwargs[list_name].extend(dependency[list_name]) # TODO: eliminiate duplicates?
def _inject_dependency(dependency, kwargs: dict) -> None:
def _inject_dependency(dependency, kwargs: dict, add_sources: bool = True) -> None:
if isinstance(dependency, dict):
_inject_list(kwargs, dependency, 'CPPPATH')
_inject_list(kwargs, dependency, 'CPPDEFINES')
_inject_list(kwargs, dependency, 'LIBPATH')
_inject_list(kwargs, dependency, 'LIBS')
if add_sources and 'ADDITIONAL_SOURCES' in dependency:
kwargs['source'].extend(dependency['ADDITIONAL_SOURCES'])
if 'DEPENDENCIES' in dependency:
for inner_dependency in dependency['DEPENDENCIES']:
_inject_dependency(inner_dependency, kwargs)
_inject_dependency(inner_dependency, kwargs, False)
def _rglob(env: Environment, root_path: str, pattern: str, **kwargs):
result_nodes = []
@ -70,6 +72,7 @@ def _wrap_builder(builder, is_lib: bool = False):
'CPPDEFINES': kwargs.get('CPPDEFINES', []),
'LIBPATH': kwargs.get('LIBPATH', []),
'LIBS': result + kwargs.get('LIBS', []),
'ADDITIONAL_SOURCES': kwargs.get('add_source', []),
'_target': result
}
return result

View File

@ -1,4 +1,5 @@
import os
from SCons.Script import *
def cook(env: Environment, git_ref: str = "main") -> dict:
@ -10,7 +11,7 @@ def cook(env: Environment, git_ref: str = "main") -> dict:
}.get(env['BUILD_TYPE'], 'SDL2')
return {
'LIBPATH': build_result['LIBPATH'],
'CPPPATH': build_result['CPPPATH'],
'CPPPATH': [os.path.join(build_result['install_dir'], 'include/SDL2')], # SDL is really weird about include paths ...
'LIBS': [lib_name]
}

30
recipes/imgui/recipe.py Normal file
View File

@ -0,0 +1,30 @@
from SCons.Script import *
import os
def cook(env: Environment, backends: list = [], git_ref: str = '') -> dict:
repo = env.Cook('GitBranch', repo_name = 'imgui', remote_url = 'https://github.com/ocornut/imgui.git', git_ref = git_ref or 'master')
imgui_source_files = [
os.path.join(repo['checkout_root'], 'imgui.cpp'),
os.path.join(repo['checkout_root'], 'imgui_draw.cpp'),
os.path.join(repo['checkout_root'], 'imgui_tables.cpp'),
os.path.join(repo['checkout_root'], 'imgui_widgets.cpp')
]
imgui_add_sources = []
backend_sources = {
'vulkan': os.path.join(repo['checkout_root'], 'backends/imgui_impl_vulkan.cpp'),
'sdl2': os.path.join(repo['checkout_root'], 'backends/imgui_impl_sdl2.cpp')
}
for backend in backends:
imgui_add_sources.append(backend_sources[backend])
lib_imgui = env.StaticLibrary(
CPPPATH = [repo['checkout_root']],
CPPDEFINES = ['IMGUI_IMPL_VULKAN_NO_PROTOTYPES=1'],
target = env['LIB_DIR'] + '/imgui',
source = imgui_source_files,
add_source = imgui_add_sources
)
return lib_imgui