Merge pull request #110540 from akien-mga/linux-system-libturbojpeg

Linux: Allow unbundling libjpeg-turbo to use system package
This commit is contained in:
Thaddeus Crews 2025-09-18 21:02:31 -05:00
commit be11bf1d6b
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
2 changed files with 84 additions and 83 deletions

View file

@ -8,98 +8,96 @@ env_jpg = env_modules.Clone()
thirdparty_obj = [] thirdparty_obj = []
thirdparty_dir = "#thirdparty/libjpeg-turbo" if env["builtin_libjpeg_turbo"]:
thirdparty_dir = "#thirdparty/libjpeg-turbo"
thirdparty_sources_common = [ thirdparty_sources_common = [
"jaricom.c", "jaricom.c",
"jcapimin.c", "jcapimin.c",
"jcarith.c", "jcarith.c",
"jchuff.c", "jchuff.c",
"jcicc.c", "jcicc.c",
"jcinit.c", "jcinit.c",
"jcmarker.c", "jcmarker.c",
"jcmaster.c", "jcmaster.c",
"jcomapi.c", "jcomapi.c",
"jcparam.c", "jcparam.c",
"jcphuff.c", "jcphuff.c",
"jctrans.c", "jctrans.c",
"jdapimin.c", "jdapimin.c",
"jdarith.c", "jdarith.c",
"jdatadst.c", "jdatadst.c",
"jdatadst-tj.c", "jdatadst-tj.c",
"jdatasrc.c", "jdatasrc.c",
"jdatasrc-tj.c", "jdatasrc-tj.c",
"jdhuff.c", "jdhuff.c",
"jdicc.c", "jdicc.c",
"jdinput.c", "jdinput.c",
"jdmarker.c", "jdmarker.c",
"jdmaster.c", "jdmaster.c",
"jdphuff.c", "jdphuff.c",
"jdtrans.c", "jdtrans.c",
"jerror.c", "jerror.c",
"jfdctflt.c", "jfdctflt.c",
"jmemmgr.c", "jmemmgr.c",
"jmemnobs.c", "jmemnobs.c",
"jpeg_nbits.c", "jpeg_nbits.c",
"transupp.c", "transupp.c",
"turbojpeg.c", "turbojpeg.c",
] ]
thirdparty_sources_bit_dependent = [ thirdparty_sources_bit_dependent = [
"jcapistd.c", "jcapistd.c",
"jccoefct.c", "jccoefct.c",
"jccolor.c", "jccolor.c",
"jcdctmgr.c", "jcdctmgr.c",
"jcmainct.c", "jcmainct.c",
"jcprepct.c", "jcprepct.c",
"jcsample.c", "jcsample.c",
"jdcoefct.c", "jdcoefct.c",
"jdcolor.c", "jdcolor.c",
"jdapistd.c", "jdapistd.c",
"jddctmgr.c", "jddctmgr.c",
"jdmainct.c", "jdmainct.c",
"jdmerge.c", "jdmerge.c",
"jdpostct.c", "jdpostct.c",
"jdsample.c", "jdsample.c",
"jfdctfst.c", "jfdctfst.c",
"jfdctint.c", "jfdctint.c",
"jidctflt.c", "jidctflt.c",
"jidctfst.c", "jidctfst.c",
"jidctint.c", "jidctint.c",
"jidctred.c", "jidctred.c",
"jutils.c", "jutils.c",
"jquant1.c", "jquant1.c",
"jquant2.c", "jquant2.c",
] ]
thirdparty_sources_by_bits = { thirdparty_sources_by_bits = {
8: list(thirdparty_sources_bit_dependent), 8: list(thirdparty_sources_bit_dependent),
12: list(thirdparty_sources_bit_dependent), 12: list(thirdparty_sources_bit_dependent),
} }
def source_paths(files):
return [thirdparty_dir + "/src/" + f for f in files]
def source_paths(files): env_jpg.Prepend(CPPEXTPATH=[thirdparty_dir + "/src"])
return [thirdparty_dir + "/src/" + f for f in files]
def add_bit_depth(bit_depth: int):
env_bit_depth = env_jpg.Clone()
env_bit_depth.disable_warnings()
env_bit_depth["OBJSUFFIX"] = f"_{bit_depth}{env_bit_depth['OBJSUFFIX']}"
env_bit_depth.Append(CPPDEFINES=[f"BITS_IN_JSAMPLE={bit_depth}"])
env_bit_depth.add_source_files(thirdparty_obj, source_paths(thirdparty_sources_by_bits[bit_depth]))
env_jpg.Prepend(CPPEXTPATH=[thirdparty_dir + "/src"]) add_bit_depth(8)
add_bit_depth(12)
env_thirdparty = env_jpg.Clone()
env_thirdparty.disable_warnings()
env_thirdparty.add_source_files(thirdparty_obj, source_paths(thirdparty_sources_common))
env.modules_sources += thirdparty_obj
def add_bit_depth(bit_depth: int):
env_bit_depth = env_jpg.Clone()
env_bit_depth.disable_warnings()
env_bit_depth["OBJSUFFIX"] = f"_{bit_depth}{env_bit_depth['OBJSUFFIX']}"
env_bit_depth.Append(CPPDEFINES=[f"BITS_IN_JSAMPLE={bit_depth}"])
env_bit_depth.add_source_files(thirdparty_obj, source_paths(thirdparty_sources_by_bits[bit_depth]))
add_bit_depth(8)
add_bit_depth(12)
env_thirdparty = env_jpg.Clone()
env_thirdparty.disable_warnings()
env_thirdparty.add_source_files(thirdparty_obj, source_paths(thirdparty_sources_common))
env.modules_sources += thirdparty_obj
# Godot source files # Godot source files

View file

@ -278,6 +278,9 @@ def configure(env: "SConsEnvironment"):
if not env["builtin_libwebp"]: if not env["builtin_libwebp"]:
env.ParseConfig("pkg-config libwebp --cflags --libs") env.ParseConfig("pkg-config libwebp --cflags --libs")
if not env["builtin_libjpeg_turbo"]:
env.ParseConfig("pkg-config libturbojpeg --cflags --libs")
if not env["builtin_mbedtls"]: if not env["builtin_mbedtls"]:
# mbedTLS only provides a pkgconfig file since 3.6.0, but we still support 2.28.x, # mbedTLS only provides a pkgconfig file since 3.6.0, but we still support 2.28.x,
# so fallback to manually specifying LIBS if it fails. # so fallback to manually specifying LIBS if it fails.