Skip to content

Unbundle Patch - Add opt-in system-lib linking for vendoured sub-dependencies - #51

Merged
danoli3 merged 2 commits into
masterfrom
feat/unbundle-system-libs
Aug 16, 2026
Merged

Unbundle Patch - Add opt-in system-lib linking for vendoured sub-dependencies#51
danoli3 merged 2 commits into
masterfrom
feat/unbundle-system-libs

Conversation

@danoli3

@danoli3 danoli3 commented Aug 14, 2026

Copy link
Copy Markdown
Owner

Adds CMake support for linking FreeImage against system-installed copies of its vendored sub-dependencies instead of always compiling the bundled forks under Source/Lib*, following MSYS2's mingw-w64-freeimage package:
https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-freeimage

Library BUILD_X USE_SYSTEM_X
zlib BUILD_ZLIB USE_SYSTEM_ZLIB
libpng BUILD_LIBPNG USE_SYSTEM_LIBPNG
libtiff BUILD_LIBTIFF USE_SYSTEM_LIBTIFF
libjpeg BUILD_LIBJPEG USE_SYSTEM_LIBJPEG
openjpeg BUILD_LIBOPENJPEG USE_SYSTEM_LIBOPENJPEG
libwebp BUILD_WEBP USE_SYSTEM_WEBP
libraw BUILD_LIBRAWLITE USE_SYSTEM_LIBRAWLITE
OpenEXR/Imath BUILD_OPENEXR USE_SYSTEM_OPENEXR
jxrlib BUILD_JXR USE_SYSTEM_JXR

All USE_SYSTEM_* default OFF (bundled, unchanged default build); FREEIMAGE_USE_SYSTEM_LIBS=ON flips them all on at once. BUILD_X=OFF alone (no system replacement) only cleanly drops the feature for webp/libraw/OpenEXR/jxrlib - the other five need USE_SYSTEM_X=ON too, or the build breaks. Same gap as pre-PR51 (BUILD_LIBPNG=OFF without PNG_LIBRARY already broke; BUILD_LIBJPEG/BUILD_LIBOPENJPEG didn't exist as options).

FreeImage.h's public API stays unchanged - G3 fax loading and FreeImage_JPEGTransform* need libtiff/libjpeg private headers system packages don't ship, so they fall back to a clean "unsupported" result under USE_SYSTEM_LIBTIFF/USE_SYSTEM_LIBJPEG instead of being removed.

Re #35: 7 of those 25 CVEs (OpenEXR + OpenJPEG) live in bundled library code and are likely dodged by USE_SYSTEM_OPENEXR/USE_SYSTEM_LIBOPENJPEG: #35 (comment)

Fixes: #44
Fixes: #11

The old FreeImage.cmake convention (predating USE_SYSTEM_LIBPNG/
USE_SYSTEM_ZLIB) used BUILD_LIBPNG=OFF/BUILD_ZLIB=OFF together with
PNG_LIBRARY/ZLIB_LIBRARY to mean "link a system copy", not "no PNG/
zlib support at all". openFrameworks' apothecary FreeImage formula
still builds this way, and so did this repo's own new openFrameworks
CI job - both broke against this PR's new BUILD_X semantics.

Treat DEFINED PNG_LIBRARY/ZLIB_LIBRARY as implicitly enabling the
system-link branch even without BUILD_X or USE_SYSTEM_X set, and map
the old include-dir variable names (PNG_INCLUDE_DIR, ZLIB_INCLUDE_DIRS)
onto the ones find_package(PNG)/find_package(ZLIB) actually read as
hints (PNG_PNG_INCLUDE_DIR, ZLIB_INCLUDE_DIR) - confirmed via
FindPNG.cmake/FindZLIB.cmake source, they don't match the old names.

Verified: default build, USE_SYSTEM_LIBS=ON build, and the exact old
-DBUILD_LIBPNG=OFF -DPNG_LIBRARY=... convention all still build clean.
@danoli3
danoli3 force-pushed the feat/unbundle-system-libs branch from 97c3ca3 to 128b715 Compare August 16, 2026 10:25
@danoli3
danoli3 merged commit 28d9bc5 into master Aug 16, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Decoupling code from mingw-w64-freeimage patch Review Latest Sub-Dependancy Patches

1 participant