Added MSVC/Windows compatibility to a few recipes (and the main script).

This commit is contained in:
2024-06-26 10:14:57 +02:00
parent c8554282f9
commit 3171d112ce
5 changed files with 49 additions and 18 deletions

View File

@@ -1,6 +1,7 @@
import copy
import os
import sys
def _cook(env: Environment, recipe_name: str, *args, **kwargs):
import importlib.util
@@ -53,6 +54,10 @@ def _rglob(env: Environment, root_path: str, pattern: str, **kwargs):
result_nodes.extend(env.Glob(f'{path}/{pattern}', **kwargs))
return sorted(result_nodes)
def _error(env: Environment, message: str):
print(message, file=sys.stderr)
env.Exit(1)
def _wrap_builder(builder, is_lib: bool = False):
def _wrapped(env, dependencies = [], *args, **kwargs):
if 'CPPPATH' not in kwargs:
@@ -219,7 +224,7 @@ tools = ['default', 'compilation_db', 'unity_build']
if 'TOOLS' in config:
tools.extend(config['TOOLS'])
env = Environment(tools = tools, variables = vars)
env = Environment(tools = tools, variables = vars, ENV = os.environ)
env['RECIPES_FOLDERS'] = [Dir('recipes')]
env['SYSTEM_CACHE_DIR'] = os.path.join(_find_system_cache_dir(), 'spp_cache')
env['CLONE_DIR'] = os.path.join(env['SYSTEM_CACHE_DIR'], 'cloned')
@@ -272,7 +277,7 @@ if not os.path.exists(cache_gitignore):
os.makedirs(env['CLONE_DIR'], exist_ok=True)
# try to detect what compiler we are using
compiler_exe = os.path.basename(env['CC'])
compiler_exe = os.path.basename(env.subst(env['CC']))
if 'gcc' in compiler_exe:
env['COMPILER_FAMILY'] = 'gcc'
elif 'clang' in compiler_exe:
@@ -329,10 +334,14 @@ if env['COMPILER_FAMILY'] == 'gcc' or env['COMPILER_FAMILY'] == 'clang':
elif env['COMPILER_FAMILY'] == 'cl':
# C4201: nonstandard extension used : nameless struct/union - I use it and want to continue using it
# C4127: conditional expression is constant - some libs (CRC, format) don't compile with this enabled # TODO: fix?
env.Append(CCFLAGS = ['/W4', '/WX', '/wd4201', '/wd4127', f'/std:{config["CXX_STANDARD"]}', '/permissive-', '/EHsc', '/FS', '/Zc:char8_t'])
# C4702: unreachable code, issued after MIJIN_FATAL macro
# C4251: missing dll-interface of some std types, yaml-cpp doesn't compile with this enabled
# C4275: same as above
env.Append(CCFLAGS = ['/W4', '/WX', '/wd4201', '/wd4127', '/wd4702', '/wd4251', '/wd4275', '/bigobj', f'/std:{config["CXX_STANDARD"]}', '/permissive-', '/EHsc', '/FS', '/Zc:char8_t'])
env.Append(CPPDEFINES = ['_CRT_SECURE_NO_WARNINGS']) # I'd like to not use MSVC specific versions of functions because they are "safer" ...
if build_type == 'debug':
env.Append(CCFLAGS = ['/Od', '/Zi'], LINKFLAGS = ' /DEBUG')
env.Append(CCFLAGS = ['/Od', '/Zi', '/MDd'], LINKFLAGS = ' /DEBUG')
env.Append(CPPDEFINES = ['_DEBUG', '_ITERATOR_DEBUG_LEVEL=2'])
elif build_type == 'release_debug' or build_type == 'profile':
env.Append(CCFLAGS = ['/O2', '/Zi'], LINKFLAGS = ' /DEBUG')
else:
@@ -346,6 +355,7 @@ elif env['COMPILER_FAMILY'] == 'clang':
env.AddMethod(_cook, 'Cook')
env.AddMethod(_parse_lib_conf, 'ParseLibConf')
env.AddMethod(_rglob, 'RGlob')
env.AddMethod(_error, 'Error')
env.AddMethod(_wrap_builder(env.Library, is_lib = True), 'Library')
env.AddMethod(_wrap_builder(env.StaticLibrary, is_lib = True), 'StaticLibrary')
env.AddMethod(_wrap_builder(env.SharedLibrary, is_lib = True), 'SharedLibrary')