From d50da75fbe7710a1627d88bc1c8d361334cc01ae Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Tue, 7 Jan 2020 00:17:31 -0800 Subject: [PATCH] Use external libsquish if found (#2451) This patch checks for libsquish already on the system, and if found, uses it. If not found on the system, it falls back on the embedded version in src/dds.imageio/squish. CMake option USE_EMBEDDED_LIBSQUISH can be used to force use of the embedded version even if found on the system. Background: Our DDS support (by Leszek Godlewski in 2010, as a GSoC student) relies on an embedded copy of libsquish (MIT license) for DXT compression. Embedding was a reasonable choice at the time, but in 2020 it's easily installed an Ubuntu, Homebrew, Vcpkg. Furthermore, it's also a Debian package and runs up against their rule that we should never embed code that is available from other Debian packages that can be used as dependencies. This is all I want to do in this patch -- comply with Debian rules, and also reduce OIIO build time by relying on a prebuilt libsquish if found on the system. This won't break anybody's builds at this time if they don't have libsquish already installed, and should be safe to backport to 2.1 for Debian compliance. But in the future, we might make it a purely external dependency -- expect it on the system, and if not found, simply disable DDS support (like we do with many other optional dependency such as libwebp or libheif). --- INSTALL.md | 3 ++ src/build-scripts/gh-win-installdeps.bash | 1 + src/build-scripts/install_homebrew_deps.bash | 3 +- src/cmake/externalpackages.cmake | 10 ++++ src/cmake/modules/FindLibsquish.cmake | 50 ++++++++++++++++++++ src/dds.imageio/CMakeLists.txt | 13 ++++- src/dds.imageio/ddsinput.cpp | 2 +- 7 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 src/cmake/modules/FindLibsquish.cmake diff --git a/INSTALL.md b/INSTALL.md index 78212ef1b1..13b69330c9 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -63,6 +63,9 @@ NEW or CHANGED MINIMUM dependencies since the last major release are **bold**. * If you want support for HEIF/HEIC images: * libheif >= 1.3 (tested through 1.6; older versions may also work, we haven't tested) +* If you want support for DDS files: + * libsquish >= 1.13 + * But... if not found on the system, an embedded version will be used. Dependency control and disabling components diff --git a/src/build-scripts/gh-win-installdeps.bash b/src/build-scripts/gh-win-installdeps.bash index eb69e59adb..7ccdc87707 100755 --- a/src/build-scripts/gh-win-installdeps.bash +++ b/src/build-scripts/gh-win-installdeps.bash @@ -43,6 +43,7 @@ vcpkg install freetype:x64-windows vcpkg install libraw:x64-windows vcpkg install openjpeg:x64-windows +vcpkg install libsquish:x64-windows # vcpkg install ffmpeg:x64-windows # takes FOREVER! # vcpkg install webp:x64-windows # No such vcpkg package?a diff --git a/src/build-scripts/install_homebrew_deps.bash b/src/build-scripts/install_homebrew_deps.bash index 6362a2b077..a9a6f7f744 100755 --- a/src/build-scripts/install_homebrew_deps.bash +++ b/src/build-scripts/install_homebrew_deps.bash @@ -40,7 +40,8 @@ else brew install --display-times libtiff ilmbase openexr opencolorio brew install --display-times libpng giflib webp jpeg-turbo openjpeg brew install --display-times freetype libraw dcmtk pybind11 numpy - brew install --display-times field3d ffmpeg libheif openvdb tbb + brew install --display-times field3d ffmpeg libheif libsquish + brew install --display-times openvdb tbb brew install --display-times opencv qt ptex fi diff --git a/src/cmake/externalpackages.cmake b/src/cmake/externalpackages.cmake index 482cd340d5..fc30448203 100644 --- a/src/cmake/externalpackages.cmake +++ b/src/cmake/externalpackages.cmake @@ -301,3 +301,13 @@ macro (find_or_download_robin_map) endif () checked_find_package (Robinmap REQUIRED) endmacro() + + +########################################################################### +# libsquish + +option (USE_EMBEDDED_LIBSQUISH + "Force use of embedded Libsquish, even if external is found" OFF) +if (NOT USE_EMBEDDED_LIBSQUISH) + checked_find_package (Libsquish) +endif () diff --git a/src/cmake/modules/FindLibsquish.cmake b/src/cmake/modules/FindLibsquish.cmake new file mode 100644 index 0000000000..da6438b89a --- /dev/null +++ b/src/cmake/modules/FindLibsquish.cmake @@ -0,0 +1,50 @@ +# Module to find Libsquish +# +# This module will first look into the directories defined by the variables: +# - Libsquish_ROOT, LIBSQUISH_INCLUDE_PATH, LIBSQUISH_LIBRARY_PATH +# +# This module defines the following variables: +# +# LIBSQUISH_FOUND True if Libsquish was found. +# LIBSQUISH_INCLUDES Where to find Libsquish headers +# LIBSQUISH_LIBRARIES List of libraries to link against when using Libsquish +# LIBSQUISH_VERSION Version of Libsquish (e.g., 3.6.2) + +include (FindPackageHandleStandardArgs) + +find_path (LIBSQUISH_INCLUDE_DIR squish.h + HINTS + ${LIBSQUISH_INCLUDE_PATH} + ENV LIBSQUISH_INCLUDE_PATH + DOC "The directory where Libsquish headers reside") + +find_library (LIBSQUISH_LIBRARY squish + HINTS + ${LIBSQUISH_LIBRARY_PATH} + ENV LIBSQUISH_LIBRARY_PATH + DOC "The Libsquish libraries") + +find_package_handle_standard_args (LIBSQUISH + REQUIRED_VARS + LIBSQUISH_INCLUDE_DIR + LIBSQUISH_LIBRARY + ) + +if (LIBSQUISH_FOUND) + set (LIBSQUISH_INCLUDES ${LIBSQUISH_INCLUDE_DIR}) + set (LIBSQUISH_LIBRARIES ${LIBSQUISH_LIBRARY}) + + if (NOT TARGET Libsquish::Libsquish) + add_library(Libsquish::Libsquish UNKNOWN IMPORTED) + set_target_properties(Libsquish::Libsquish PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LIBSQUISH_INCLUDES}") + + set_property(TARGET Libsquish::Libsquish APPEND PROPERTY + IMPORTED_LOCATION "${LIBSQUISH_LIBRARIES}") + endif () +endif () + +mark_as_advanced ( + LIBSQUISH_INCLUDE_DIR + LIBSQUISH_LIBRARY + ) diff --git a/src/dds.imageio/CMakeLists.txt b/src/dds.imageio/CMakeLists.txt index f4e63695e0..546f683caf 100644 --- a/src/dds.imageio/CMakeLists.txt +++ b/src/dds.imageio/CMakeLists.txt @@ -2,7 +2,16 @@ # SPDX-License-Identifier: BSD-3-Clause # https://github.com/OpenImageIO/oiio/blob/master/LICENSE.md -add_oiio_plugin (ddsinput.cpp squish/alpha.cpp squish/clusterfit.cpp +if (LIBSQUISH_FOUND) + # External libsquish was found -- use it + add_oiio_plugin (ddsinput.cpp + LINK_LIBRARIES Libsquish::Libsquish + ) +else () + # No external libsquish was found -- use the embedded version. + add_oiio_plugin (ddsinput.cpp squish/alpha.cpp squish/clusterfit.cpp squish/colourblock.cpp squish/colourfit.cpp squish/colourset.cpp squish/maths.cpp squish/rangefit.cpp squish/singlecolourfit.cpp - squish/squish.cpp) + squish/squish.cpp + INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/squish") +endif () diff --git a/src/dds.imageio/ddsinput.cpp b/src/dds.imageio/ddsinput.cpp index f1285cb914..848acee536 100644 --- a/src/dds.imageio/ddsinput.cpp +++ b/src/dds.imageio/ddsinput.cpp @@ -13,7 +13,7 @@ #include #include -#include "squish/squish.h" +#include "squish.h" OIIO_PLUGIN_NAMESPACE_BEGIN