Skip to content

Commit

Permalink
build: raise libtiff min to 4.0 + self-build for libtiff (and libdefl…
Browse files Browse the repository at this point in the history
…ate)

Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz committed Jun 16, 2024
1 parent 59b5458 commit 6fe9f62
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 13 deletions.
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ NEW or CHANGED MINIMUM dependencies since the last major release are **bold**.
* **CMake >= 3.15** (tested through 3.29)
* **OpenEXR/Imath >= 3.1** (tested through 3.2
and main)
* libTIFF >= 3.9 (recommended: 4.0+; tested through 4.6)
* **libTIFF >= 4.0** (tested through 4.6)
* libjpeg >= 8 (tested through jpeg9e), or **libjpeg-turbo >= 2.1** (tested
through 3.0)
* **[fmtlib](https://github.com/fmtlib/fmt) >= 7.0** (tested through 10.2).
Expand Down
47 changes: 47 additions & 0 deletions src/cmake/build_TIFF.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

######################################################################
# TIFF by hand!
######################################################################

set_cache (TIFF_BUILD_VERSION 4.6.0 "TIFF version for local builds")
set (TIFF_GIT_REPOSITORY "https://gitlab.com/libtiff/libtiff.git")
set (TIFF_GIT_TAG "v${TIFF_BUILD_VERSION}")
set_cache (TIFF_BUILD_SHARED_LIBS ${LOCAL_BUILD_SHARED_LIBS_DEFAULT}
DOC "Should a local TIFF build, if necessary, build shared libraries" ADVANCED)

# We need libdeflate to build libtiff
checked_find_package (libdeflate REQUIRED
VERSION_MIN 1.18)
alias_library_if_not_exists (Deflate::Deflate libdeflate::libdeflate_static)

build_dependency_with_cmake(TIFF
VERSION ${TIFF_BUILD_VERSION}
GIT_REPOSITORY ${TIFF_GIT_REPOSITORY}
GIT_TAG ${TIFF_GIT_TAG}
CMAKE_ARGS
-D BUILD_SHARED_LIBS=${TIFF_BUILD_SHARED_LIBS}
-D CMAKE_POSITION_INDEPENDENT_CODE=ON
-D CMAKE_INSTALL_LIBDIR=lib
-D tiff-tools=OFF
-D tiff-contrib=OFF
-D tiff-tests=OFF
-D tiff-docs=OFF
-D libdeflate=ON
-D lzma=OFF
-D zstd=OFF
)

# Set some things up that we'll need for a subsequent find_package to work

set (TIFF_ROOT ${TIFF_LOCAL_INSTALL_DIR})

# Signal to caller that we need to find again at the installed location
set (TIFF_REFIND TRUE)
set (TIFF_REFIND_ARGS CONFIG)

if (TIFF_BUILD_SHARED_LIBS)
install_local_dependency_libs (TIFF TIFF)
endif ()
38 changes: 38 additions & 0 deletions src/cmake/build_libdeflate.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

######################################################################
# libdeflate by hand!
######################################################################

set_cache (libdeflate_BUILD_VERSION 1.20 "libdeflate version for local builds")
set (libdeflate_GIT_REPOSITORY "https://github.com/ebiggers/libdeflate")
set (libdeflate_GIT_TAG "v${libdeflate_BUILD_VERSION}")
set_cache (libdeflate_BUILD_SHARED_LIBS ${LOCAL_BUILD_SHARED_LIBS_DEFAULT}
DOC "Should a local libdeflate build, if necessary, build shared libraries" ADVANCED)

string (MAKE_C_IDENTIFIER ${libdeflate_BUILD_VERSION} libdeflate_VERSION_IDENT)

build_dependency_with_cmake(libdeflate
VERSION ${libdeflate_BUILD_VERSION}
GIT_REPOSITORY ${libdeflate_GIT_REPOSITORY}
GIT_TAG ${libdeflate_GIT_TAG}
CMAKE_ARGS
-D BUILD_SHARED_LIBS=${libdeflate_BUILD_SHARED_LIBS}
-D CMAKE_POSITION_INDEPENDENT_CODE=ON
-D CMAKE_INSTALL_LIBDIR=lib
-D LIBDEFLATE_BUILD_GZIP=OFF
)

# Set some things up that we'll need for a subsequent find_package to work

set (libdeflate_ROOT ${libdeflate_LOCAL_INSTALL_DIR})

# Signal to caller that we need to find again at the installed location
set (libdeflate_REFIND TRUE)
set (libdeflate_REFIND_ARGS CONFIG)

if (libdeflate_BUILD_SHARED_LIBS)
install_local_dependency_libs (libdeflate libdeflate)
endif ()
9 changes: 9 additions & 0 deletions src/cmake/dependency_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -572,3 +572,12 @@ macro (install_local_dependency_libs pkgname libname)
endif ()
unset (_lib_files)
endmacro ()


# If the target `newalias` doesn't yet exist but `realtarget` does, create an
# alias for `newalias` to mean the real target.
macro (alias_library_if_not_exists newalias realtarget)
if (NOT TARGET ${newalias} AND TARGET ${realtarget})
add_library(${newalias} ALIAS ${realtarget})
endif ()
endmacro ()
16 changes: 10 additions & 6 deletions src/cmake/externalpackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ if (NOT TARGET CMath::CMath)
endif ()
endif ()

checked_find_package (TIFF REQUIRED
VERSION_MIN 3.9
RECOMMEND_MIN 4.0
RECOMMEND_MIN_REASON "to support >4GB files")

# IlmBase & OpenEXR
checked_find_package (Imath REQUIRED
VERSION_MIN 3.1
Expand Down Expand Up @@ -81,10 +76,19 @@ set (OPENIMAGEIO_CONFIG_DO_NOT_FIND_IMATH OFF CACHE BOOL
checked_find_package (libjpeg-turbo
VERSION_MIN 2.1
DEFINITIONS USE_JPEG_TURBO=1)
if (NOT TARGET libjpeg-turbo::jpeg) # Try to find the non-turbo version
if (TARGET libjpeg-turbo::jpeg) # Try to find the non-turbo version
# Doctor it so libjpeg-turbo is aliased as JPEG::JPEG
alias_library_if_not_exists (JPEG::JPEG libjpeg-turbo::jpeg)
else ()
# Try to find the non-turbo version
checked_find_package (JPEG REQUIRED)
endif ()


checked_find_package (TIFF REQUIRED
VERSION_MIN 4.0)
alias_library_if_not_exists (TIFF::TIFF TIFF::tiff)

# JPEG XL
option (USE_JXL "Enable JPEG XL support" ON)
checked_find_package (JXL
Expand Down
4 changes: 1 addition & 3 deletions src/tiff.imageio/tiffinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@
# define OIIO_TIFFLIB_VERSION 40003
#elif TIFFLIB_VERSION >= 20111221
# define OIIO_TIFFLIB_VERSION 40000
#elif TIFFLIB_VERSION >= 20090820
# define OIIO_TIFFLIB_VERSION 30900
#else
# error "libtiff 3.9.0 or later is required"
# error "libtiff 4.0.0 or later is required"
#endif
// clang-format on

Expand Down
4 changes: 1 addition & 3 deletions src/tiff.imageio/tiffoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@
# define OIIO_TIFFLIB_VERSION 40003
#elif TIFFLIB_VERSION >= 20111221
# define OIIO_TIFFLIB_VERSION 40000
#elif TIFFLIB_VERSION >= 20090820
# define OIIO_TIFFLIB_VERSION 30900
#else
# error "libtiff 3.9.0 or later is required"
# error "libtiff 4.0.0 or later is required"
#endif
// clang-format on

Expand Down

0 comments on commit 6fe9f62

Please sign in to comment.