Move some defines to only the source files where they are needed

This commit is contained in:
Kovid Goyal 2024-05-16 17:38:26 +05:30
parent f30652c24a
commit f979c24add
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 22 additions and 6 deletions

View file

@ -64,6 +64,11 @@ class Env:
vcs_rev: str = ''
binary_arch: BinaryArch = BinaryArch()
native_optimizations: bool = False
has_systemd: bool = False
primary_version: int = 0
secondary_version: int = 0
xt_version: str = ''
has_copy_file_range: bool = False
# glfw stuff
all_headers: List[str] = []
@ -118,6 +123,11 @@ class Env:
ans.vcs_rev = self.vcs_rev
ans.binary_arch = self.binary_arch
ans.native_optimizations = self.native_optimizations
ans.has_systemd = self.has_systemd
ans.primary_version = self.primary_version
ans.secondary_version = self.secondary_version
ans.xt_version = self.xt_version
ans.has_copy_file_range = self.has_copy_file_range
return ans

View file

@ -486,8 +486,6 @@ def init_env(
for el in extra_logging:
cppflags.append('-DDEBUG_{}'.format(el.upper().replace('-', '_')))
has_copy_file_range = test_compile(cc, src='#define _GNU_SOURCE 1\n#include <unistd.h>\nint main() { copy_file_range(1, NULL, 2, NULL, 0, 0); return 0; }')
if has_copy_file_range:
cppflags.append('-DHAS_COPY_FILE_RANGE')
werror = '' if ignore_compiler_warnings else '-pedantic-errors -Werror'
std = '' if is_openbsd else '-std=c11'
sanitize_flag = ' '.join(sanitize_args)
@ -587,6 +585,7 @@ def init_env(
cc, cppflags, cflags, ldflags, library_paths, binary_arch=ba, native_optimizations=native_optimizations,
ccver=ccver, ldpaths=ldpaths, vcs_rev=vcs_rev,
)
ans.has_copy_file_range = bool(has_copy_file_range)
if verbose:
print(ans.cc_version_string.strip())
print('Detected:', ans.compiler_type)
@ -600,9 +599,10 @@ def kitty_env(args: Options) -> Env:
cppflags = ans.cppflags
# We add 4000 to the primary version because vim turns on SGR mouse mode
# automatically if this version is high enough
cppflags.append(f'-DPRIMARY_VERSION={version[0] + 4000}')
cppflags.append(f'-DSECONDARY_VERSION={version[1]}')
cppflags.append('-DXT_VERSION="{}"'.format('.'.join(map(str, version))))
ans.primary_version = version[0] + 4000
ans.secondary_version = version[1]
ans.xt_version = '.'.join(map(str, version))
at_least_version('harfbuzz', 1, 5)
cflags.extend(pkg_config('libpng', '--cflags-only-I'))
cflags.extend(pkg_config('lcms2', '--cflags-only-I'))
@ -634,7 +634,7 @@ def kitty_env(args: Options) -> Env:
cflags.extend(pkg_config('libsystemd', '--cflags-only-I', fatal=False))
systemd_libs = pkg_config('libsystemd', '--libs')
platform_libs.extend(systemd_libs)
cppflags.append('-DKITTY_HAS_SYSTEMD')
ans.has_systemd = True
cflags.extend(pkg_config('harfbuzz', '--cflags-only-I'))
platform_libs.extend(pkg_config('harfbuzz', '--libs'))
pylib = get_python_flags(args, cflags)
@ -728,6 +728,12 @@ def get_source_specific_defines(env: Env, src: str) -> Tuple[str, List[str], Opt
return src, [], [f'KITTY_VCS_REV="{env.vcs_rev}"', f'WRAPPED_KITTENS="{wrapped_kittens()}"']
if src.startswith('3rdparty/base64/'):
return src, ['3rdparty/base64',], base64_defines(env.binary_arch.isa)
if src == 'kitty/screen.c':
return src, [], [f'PRIMARY_VERSION={env.primary_version}', f'SECONDARY_VERSION={env.secondary_version}', f'XT_VERSION="{env.xt_version}"']
if src == 'kitty/systemd.c':
return src, [], (['KITTY_HAS_SYSTEMD'] if env.has_systemd else None)
if src == 'kitty/fast-file-copy.c':
return src, [], (['HAS_COPY_FILE_RANGE'] if env.has_copy_file_range else None)
try:
return src, [], env.library_paths[src]
except KeyError: