diff options
Diffstat (limited to 'platform/linuxbsd/detect.py')
-rw-r--r-- | platform/linuxbsd/detect.py | 141 |
1 files changed, 47 insertions, 94 deletions
diff --git a/platform/linuxbsd/detect.py b/platform/linuxbsd/detect.py index f5f7e65417..36e149f2b4 100644 --- a/platform/linuxbsd/detect.py +++ b/platform/linuxbsd/detect.py @@ -4,6 +4,11 @@ import sys from methods import get_compiler_version, using_gcc from platform_methods import detect_arch +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from SCons import Environment + def is_active(): return True @@ -31,7 +36,6 @@ def get_opts(): return [ EnumVariable("linker", "Linker program", "default", ("default", "bfd", "gold", "lld", "mold")), BoolVariable("use_llvm", "Use the LLVM compiler", False), - BoolVariable("use_thinlto", "Use ThinLTO (LLVM only, requires linker=lld, implies use_lto=yes)", False), BoolVariable("use_static_cpp", "Link libgcc and libstdc++ statically for better portability", True), BoolVariable("use_coverage", "Test Godot coverage", False), BoolVariable("use_ubsan", "Use LLVM/GCC compiler undefined behavior sanitizer (UBSAN)", False), @@ -39,14 +43,13 @@ def get_opts(): BoolVariable("use_lsan", "Use LLVM/GCC compiler leak sanitizer (LSAN)", False), BoolVariable("use_tsan", "Use LLVM/GCC compiler thread sanitizer (TSAN)", False), BoolVariable("use_msan", "Use LLVM compiler memory sanitizer (MSAN)", False), - BoolVariable("pulseaudio", "Detect and use PulseAudio", True), - BoolVariable("dbus", "Detect and use D-Bus to handle screensaver and portal desktop settings", True), - BoolVariable("speechd", "Detect and use Speech Dispatcher for Text-to-Speech support", True), - BoolVariable("fontconfig", "Detect and use fontconfig for system fonts support", True), + BoolVariable("alsa", "Use ALSA", True), + BoolVariable("pulseaudio", "Use PulseAudio", True), + BoolVariable("dbus", "Use D-Bus to handle screensaver and portal desktop settings", True), + BoolVariable("speechd", "Use Speech Dispatcher for Text-to-Speech support", True), + BoolVariable("fontconfig", "Use fontconfig for system fonts support", True), BoolVariable("udev", "Use udev for gamepad connection callbacks", True), BoolVariable("x11", "Enable X11 display", True), - BoolVariable("debug_symbols", "Add debugging symbols to release/release_debug builds", True), - BoolVariable("separate_debug_symbols", "Create a separate file containing debugging symbols", False), BoolVariable("touch", "Enable touch events", True), BoolVariable("execinfo", "Use libexecinfo on systems where glibc is not available", False), ] @@ -58,7 +61,7 @@ def get_flags(): ] -def configure(env): +def configure(env: "Environment"): # Validate arch. supported_arches = ["x86_32", "x86_64", "arm32", "arm64", "rv64", "ppc32", "ppc64"] if env["arch"] not in supported_arches: @@ -70,26 +73,9 @@ def configure(env): ## Build type - if env["target"] == "release": - if env["optimize"] == "speed": # optimize for speed (default) - env.Prepend(CCFLAGS=["-O3"]) - elif env["optimize"] == "size": # optimize for size - env.Prepend(CCFLAGS=["-Os"]) - - if env["debug_symbols"]: - env.Prepend(CCFLAGS=["-g2"]) - - elif env["target"] == "release_debug": - if env["optimize"] == "speed": # optimize for speed (default) - env.Prepend(CCFLAGS=["-O2"]) - elif env["optimize"] == "size": # optimize for size - env.Prepend(CCFLAGS=["-Os"]) - - if env["debug_symbols"]: - env.Prepend(CCFLAGS=["-g2"]) - - elif env["target"] == "debug": - env.Prepend(CCFLAGS=["-g3"]) + if env.dev_build: + # This is needed for our crash handler to work properly. + # gdb works fine without it though, so maybe our crash handler could too. env.Append(LINKFLAGS=["-rdynamic"]) # CPU architecture flags. @@ -129,13 +115,6 @@ def configure(env): else: env.Append(LINKFLAGS=["-fuse-ld=%s" % env["linker"]]) - if env["use_thinlto"]: - if not env["use_llvm"] or env["linker"] != "lld": - print("ThinLTO is only compatible with LLVM and the LLD linker, use `use_llvm=yes linker=lld`.") - sys.exit(255) - else: - env["use_lto"] = True # ThinLTO implies LTO - if env["use_coverage"]: env.Append(CCFLAGS=["-ftest-coverage", "-fprofile-arcs"]) env.Append(LINKFLAGS=["-ftest-coverage", "-fprofile-arcs"]) @@ -178,8 +157,16 @@ def configure(env): env.Append(CCFLAGS=["-fsanitize-recover=memory"]) env.Append(LINKFLAGS=["-fsanitize=memory"]) - if env["use_lto"]: - if env["use_thinlto"]: + # LTO + + if env["lto"] == "auto": # Full LTO for production. + env["lto"] = "full" + + if env["lto"] != "none": + if env["lto"] == "thin": + if not env["use_llvm"]: + print("ThinLTO is only compatible with LLVM, use `use_llvm=yes` or `lto=full`.") + sys.exit(255) env.Append(CCFLAGS=["-flto=thin"]) env.Append(LINKFLAGS=["-flto=thin"]) elif not env["use_llvm"] and env.GetOption("num_jobs") > 1: @@ -197,15 +184,6 @@ def configure(env): ## Dependencies - if env["x11"]: - env.ParseConfig("pkg-config x11 --cflags --libs") - env.ParseConfig("pkg-config xcursor --cflags --libs") - env.ParseConfig("pkg-config xinerama --cflags --libs") - env.ParseConfig("pkg-config xext --cflags --libs") - env.ParseConfig("pkg-config xrandr --cflags --libs") - env.ParseConfig("pkg-config xrender --cflags --libs") - env.ParseConfig("pkg-config xi --cflags --libs") - if env["touch"]: env.Append(CPPDEFINES=["TOUCH_ENABLED"]) @@ -284,7 +262,7 @@ def configure(env): env.Append(LIBS=["miniupnpc"]) # On Linux wchar_t should be 32-bits - # 16-bit library shouldn't be required due to compiler optimisations + # 16-bit library shouldn't be required due to compiler optimizations if not env["builtin_pcre2"]: env.ParseConfig("pkg-config libpcre2-32 --cflags --libs") @@ -295,53 +273,24 @@ def configure(env): ## Flags if env["fontconfig"]: - if os.system("pkg-config --exists fontconfig") == 0: # 0 means found - env.Append(CPPDEFINES=["FONTCONFIG_ENABLED"]) - env.ParseConfig("pkg-config fontconfig --cflags") # Only cflags, we dlopen the library. - else: - env["fontconfig"] = False - print("Warning: fontconfig libraries not found. Disabling the system fonts support.") + env.Append(CPPDEFINES=["FONTCONFIG_ENABLED"]) - if os.system("pkg-config --exists alsa") == 0: # 0 means found - env["alsa"] = True + if env["alsa"]: env.Append(CPPDEFINES=["ALSA_ENABLED", "ALSAMIDI_ENABLED"]) - env.ParseConfig("pkg-config alsa --cflags") # Only cflags, we dlopen the library. - else: - print("Warning: ALSA libraries not found. Disabling the ALSA audio driver.") if env["pulseaudio"]: - if os.system("pkg-config --exists libpulse") == 0: # 0 means found - env.Append(CPPDEFINES=["PULSEAUDIO_ENABLED"]) - env.ParseConfig("pkg-config libpulse --cflags") # Only cflags, we dlopen the library. - else: - env["pulseaudio"] = False - print("Warning: PulseAudio development libraries not found. Disabling the PulseAudio audio driver.") + env.Append(CPPDEFINES=["PULSEAUDIO_ENABLED", "_REENTRANT"]) if env["dbus"]: - if os.system("pkg-config --exists dbus-1") == 0: # 0 means found - env.Append(CPPDEFINES=["DBUS_ENABLED"]) - env.ParseConfig("pkg-config dbus-1 --cflags") # Only cflags, we dlopen the library. - else: - env["dbus"] = False - print("Warning: D-Bus development libraries not found. Disabling screensaver prevention.") + env.Append(CPPDEFINES=["DBUS_ENABLED"]) if env["speechd"]: - if os.system("pkg-config --exists speech-dispatcher") == 0: # 0 means found - env.Append(CPPDEFINES=["SPEECHD_ENABLED"]) - env.ParseConfig("pkg-config speech-dispatcher --cflags") # Only cflags, we dlopen the library. - else: - env["speechd"] = False - print("Warning: Speech Dispatcher development libraries not found. Disabling Text-to-Speech support.") + env.Append(CPPDEFINES=["SPEECHD_ENABLED"]) if platform.system() == "Linux": env.Append(CPPDEFINES=["JOYDEV_ENABLED"]) if env["udev"]: - if os.system("pkg-config --exists libudev") == 0: # 0 means found - env.Append(CPPDEFINES=["UDEV_ENABLED"]) - env.ParseConfig("pkg-config libudev --cflags") # Only cflags, we dlopen the library. - else: - env["udev"] = False - print("Warning: libudev development libraries not found. Disabling controller hotplugging support.") + env.Append(CPPDEFINES=["UDEV_ENABLED"]) else: env["udev"] = False # Linux specific @@ -349,17 +298,19 @@ def configure(env): if not env["builtin_zlib"]: env.ParseConfig("pkg-config zlib --cflags --libs") - env.Prepend(CPPPATH=["#platform/linuxbsd"]) + env.Prepend(CPPPATH=["#platform/linuxbsd", "#thirdparty/linuxbsd_headers"]) + + env.Append( + CPPDEFINES=[ + "LINUXBSD_ENABLED", + "UNIX_ENABLED", + ("_FILE_OFFSET_BITS", 64), + ] + ) if env["x11"]: - if not env["vulkan"]: - print("Error: X11 support requires vulkan=yes") - env.Exit(255) env.Append(CPPDEFINES=["X11_ENABLED"]) - env.Append(CPPDEFINES=["UNIX_ENABLED"]) - env.Append(CPPDEFINES=[("_FILE_OFFSET_BITS", 64)]) - if env["vulkan"]: env.Append(CPPDEFINES=["VULKAN_ENABLED"]) if not env["use_volk"]: @@ -370,20 +321,22 @@ def configure(env): if env["opengl3"]: env.Append(CPPDEFINES=["GLES3_ENABLED"]) - env.ParseConfig("pkg-config gl --cflags --libs") env.Append(LIBS=["pthread"]) if platform.system() == "Linux": env.Append(LIBS=["dl"]) - if platform.system().find("BSD") >= 0: + if not env["execinfo"] and platform.libc_ver()[0] != "glibc": + # The default crash handler depends on glibc, so if the host uses + # a different libc (BSD libc, musl), fall back to libexecinfo. + print("Note: Using `execinfo=yes` for the crash handler as required on platforms where glibc is missing.") env["execinfo"] = True if env["execinfo"]: env.Append(LIBS=["execinfo"]) - if not env["tools"]: + if not env.editor_build: import subprocess import re @@ -414,9 +367,9 @@ def configure(env): # Link those statically for portability if env["use_static_cpp"]: env.Append(LINKFLAGS=["-static-libgcc", "-static-libstdc++"]) - if env["use_llvm"]: + if env["use_llvm"] and platform.system() != "FreeBSD": env["LINKCOM"] = env["LINKCOM"] + " -l:libatomic.a" else: - if env["use_llvm"]: + if env["use_llvm"] and platform.system() != "FreeBSD": env.Append(LIBS=["atomic"]) |