Skip to content

Commit

Permalink
(conan-io#13109) libtiff: conan v2 support
Browse files Browse the repository at this point in the history
* conan v2 support

* bump dependencies

* more robust injection of libjpeg-turbo CMakeDeps info
  • Loading branch information
SpaceIm authored and marc-mw committed Oct 7, 2022
1 parent 94a26df commit 7f96bef
Show file tree
Hide file tree
Showing 20 changed files with 597 additions and 341 deletions.
7 changes: 0 additions & 7 deletions recipes/libtiff/all/CMakeLists.txt

This file was deleted.

38 changes: 26 additions & 12 deletions recipes/libtiff/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,34 @@ sources:
sha256: "59d7a5a8ccd92059913f246877db95a2918e6c04fb9d43fd74e5c3390dac2910"
patches:
"4.4.0":
- patch_file: "patches/4.4.0-0001-cmake-add-libjpeg-turbo.patch"
base_path: "source_subfolder"
- patch_file: "patches/4.4.0-0001-cmake-dependencies.patch"
patch_description: "CMake: robust handling of dependencies"
patch_type: "conan"
"4.3.0":
- patch_file: "patches/4.3.0-0001-cmake-add-libjpeg-turbo.patch"
base_path: "source_subfolder"
- patch_file: "patches/4.3.0-0001-cmake-dependencies.patch"
patch_description: "CMake: robust handling of dependencies"
patch_type: "conan"
"4.2.0":
- patch_file: "patches/4.2.0-0001-cmake-add-libjpeg-turbo.patch"
base_path: "source_subfolder"
- patch_file: "patches/4.2.0-0001-cmake-dependencies.patch"
patch_description: "CMake: robust handling of dependencies"
patch_type: "conan"
"4.1.0":
- patch_file: "patches/4.1.0-0001-cmake-add-libjpeg-turbo.patch"
base_path: "source_subfolder"
- patch_file: "patches/4.1.0-0001-cmake-dependencies.patch"
patch_description: "CMake: robust handling of dependencies"
patch_type: "conan"
- patch_file: "patches/4.1.0-0002-no-libm-mingw.patch"
patch_source: "https://gitlab.com/libtiff/libtiff/-/merge_requests/73"
"4.0.9":
- patch_file: "patches/4.0.8-0001-cmake-add-libjpeg-turbo.patch"
base_path: "source_subfolder"
- patch_file: "patches/4.0.8-0001-cmake-dependencies.patch"
patch_description: "CMake: robust handling of dependencies"
patch_type: "conan"
- patch_file: "patches/4.0.8-0002-no-libm-mingw.patch"
patch_source: "https://gitlab.com/libtiff/libtiff/-/merge_requests/73"
"4.0.8":
- patch_file: "patches/4.0.8-0001-cmake-add-libjpeg-turbo.patch"
base_path: "source_subfolder"
- patch_file: "patches/4.0.8-0001-cmake-dependencies.patch"
patch_description: "CMake: robust handling of dependencies"
patch_type: "conan"
- patch_file: "patches/4.0.8-0002-no-libm-mingw.patch"
patch_source: "https://gitlab.com/libtiff/libtiff/-/merge_requests/73"
- patch_file: "patches/4.0.8-0003-file-offsets-bits-mingw.patch"
patch_source: "https://gitlab.com/libtiff/libtiff/-/commit/f2a3b020402943f90957552a884788e70ece6cd7"
175 changes: 82 additions & 93 deletions recipes/libtiff/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from conan.tools.files import get, rename, rmdir
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rmdir
from conan.tools.microsoft import is_msvc
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conans.tools import Version
from conan.tools.scm import Version
import os

required_conan_version = ">=1.47.0"
required_conan_version = ">=1.52.0"


class LibtiffConan(ConanFile):
Expand Down Expand Up @@ -42,17 +43,6 @@ class LibtiffConan(ConanFile):
"cxx": True,
}

generators = "cmake", "cmake_find_package"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

@property
def _has_webp_option(self):
return Version(self.version) >= "4.0.10"
Expand All @@ -66,9 +56,7 @@ def _has_libdeflate_option(self):
return Version(self.version) >= "4.2.0"

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
Expand All @@ -82,10 +70,22 @@ def config_options(self):

def configure(self):
if self.options.shared:
del self.options.fPIC
try:
del self.options.fPIC
except Exception:
pass
if not self.options.cxx:
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
try:
del self.settings.compiler.libcxx
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
if self.options.zlib:
Expand All @@ -95,93 +95,85 @@ def requirements(self):
if self.options.lzma:
self.requires("xz_utils/5.2.5")
if self.options.jpeg == "libjpeg":
self.requires("libjpeg/9d")
self.requires("libjpeg/9e")
if self.options.jpeg == "libjpeg-turbo":
self.requires("libjpeg-turbo/2.1.3")
self.requires("libjpeg-turbo/2.1.4")
if self.options.jbig:
self.requires("jbig/20160605")
if self.options.get_safe("zstd"):
self.requires("zstd/1.5.2")
if self.options.get_safe("webp"):
self.requires("libwebp/1.2.3")
self.requires("libwebp/1.2.4")

def validate(self):
if self.options.get_safe("libdeflate") and not self.options.zlib:
if self.info.options.get_safe("libdeflate") and not self.info.options.zlib:
raise ConanInvalidConfiguration("libtiff:libdeflate=True requires libtiff:zlib=True")

def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
destination=self.source_folder, strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["lzma"] = self.options.lzma
tc.variables["jpeg"] = bool(self.options.jpeg)
tc.variables["jpeg12"] = False
tc.variables["jbig"] = self.options.jbig
tc.variables["zlib"] = self.options.zlib
if self._has_libdeflate_option:
tc.variables["libdeflate"] = self.options.libdeflate
if self._has_zstd_option:
tc.variables["zstd"] = self.options.zstd
if self._has_webp_option:
tc.variables["webp"] = self.options.webp
if Version(self.version) >= "4.3.0":
tc.variables["lerc"] = False # TODO: add lerc support for libtiff versions >= 4.3.0
tc.variables["cxx"] = self.options.cxx
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
apply_conandata_patches(self)

# Rename the generated Findjbig.cmake and Findzstd.cmake to avoid case insensitive conflicts with FindJBIG.cmake and FindZSTD.cmake on Windows
if Version(self.version) >= "4.3.0":
if self.options.jbig:
rename(self, "Findjbig.cmake", "ConanFindjbig.cmake")
else:
os.remove(os.path.join(self.build_folder, self._source_subfolder, "cmake", "FindJBIG.cmake"))
if self.options.zstd:
rename(self, "Findzstd.cmake", "ConanFindzstd.cmake")
top_cmakelists = os.path.join(self.source_folder, "CMakeLists.txt")
libtiff_cmakelists = os.path.join(self.source_folder, "libtiff", "CMakeLists.txt")

# Handle libjpeg-turbo
if self.options.jpeg == "libjpeg-turbo":
if Version(self.version) < "4.3.0":
file_find_package_jpeg = top_cmakelists
file_jpeg_target = top_cmakelists
else:
os.remove(os.path.join(self.build_folder, self._source_subfolder, "cmake", "FindZSTD.cmake"))

if self.options.shared and is_msvc(self):
# https://github.com/Microsoft/vcpkg/blob/master/ports/tiff/fix-cxx-shared-libs.patch
tools.replace_in_file(os.path.join(self._source_subfolder, "libtiff", "CMakeLists.txt"),
r"set_target_properties(tiffxx PROPERTIES SOVERSION ${SO_COMPATVERSION})",
r"set_target_properties(tiffxx PROPERTIES SOVERSION ${SO_COMPATVERSION} "
r"WINDOWS_EXPORT_ALL_SYMBOLS ON)")
cmakefile = os.path.join(self._source_subfolder, "CMakeLists.txt")
if self.settings.os == "Windows" and not is_msvc(self):
if Version(self.version) < "4.2.0":
tools.replace_in_file(cmakefile,
"find_library(M_LIBRARY m)",
"if (NOT MINGW)\n find_library(M_LIBRARY m)\nendif()")
if Version(self.version) < "4.0.9":
tools.replace_in_file(cmakefile, "if (UNIX)", "if (UNIX OR MINGW)")
tools.replace_in_file(cmakefile,
file_find_package_jpeg = os.path.join(self.source_folder, "cmake", "JPEGCodec.cmake")
file_jpeg_target = libtiff_cmakelists
cpp_info_jpeg_turbo = self.dependencies["libjpeg-turbo"].cpp_info
jpeg_config = cpp_info_jpeg_turbo.get_property("cmake_file_name") or "libjpeg-turbo"
jpeg_target = cpp_info_jpeg_turbo.components["jpeg"].get_property("cmake_target_name") or "libjpeg-turbo::jpeg"
replace_in_file(self, file_find_package_jpeg,
"find_package(JPEG)",
f"find_package({jpeg_config} REQUIRED CONFIG)\nset(JPEG_FOUND TRUE)")
replace_in_file(self, file_jpeg_target, "JPEG::JPEG", jpeg_target)

# Export symbols of tiffxx for msvc shared
replace_in_file(self, libtiff_cmakelists,
"set_target_properties(tiffxx PROPERTIES SOVERSION ${SO_COMPATVERSION})",
"set_target_properties(tiffxx PROPERTIES SOVERSION ${SO_COMPATVERSION} WINDOWS_EXPORT_ALL_SYMBOLS ON)")

# Disable tools, test, contrib, man & html generation
replace_in_file(self, top_cmakelists,
"add_subdirectory(tools)\nadd_subdirectory(test)\nadd_subdirectory(contrib)\nadd_subdirectory(build)\n"
"add_subdirectory(man)\nadd_subdirectory(html)", "")

def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
self._cmake.definitions["lzma"] = self.options.lzma
self._cmake.definitions["jpeg"] = self.options.jpeg != False
self._cmake.definitions["jbig"] = self.options.jbig
self._cmake.definitions["zlib"] = self.options.zlib
if self._has_libdeflate_option:
self._cmake.definitions["libdeflate"] = self.options.libdeflate
if self.options.libdeflate:
if Version(self.version) < "4.3.0":
self._cmake.definitions["DEFLATE_NAMES"] = self.deps_cpp_info["libdeflate"].libs[0]
if self._has_zstd_option:
self._cmake.definitions["zstd"] = self.options.zstd
if self._has_webp_option:
self._cmake.definitions["webp"] = self.options.webp
self._cmake.definitions["cxx"] = self.options.cxx

# Workaround for cross-build to at least iOS/tvOS/watchOS,
# when dependencies like libdeflate, jbig and zstd are found with find_path() and find_library()
# see https://github.com/conan-io/conan-center-index/issues/6637
if tools.cross_building(self):
self._cmake.definitions["CMAKE_FIND_ROOT_PATH_MODE_INCLUDE"] = "BOTH"
self._cmake.definitions["CMAKE_FIND_ROOT_PATH_MODE_LIBRARY"] = "BOTH"

self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("COPYRIGHT", src=self._source_subfolder, dst="licenses", ignore_case=True, keep_path=False)
cmake = self._configure_cmake()
copy(self, "COPYRIGHT", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"), ignore_case=True, keep_path=False)
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
Expand All @@ -190,18 +182,15 @@ def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_file_name", "TIFF")
self.cpp_info.set_property("cmake_target_name", "TIFF::TIFF")
self.cpp_info.set_property("pkg_config_name", "libtiff-{}".format(Version(self.version).major))
self.cpp_info.set_property("pkg_config_name", f"libtiff-{Version(self.version).major}")
suffix = "d" if is_msvc(self) and self.settings.build_type == "Debug" else ""
if self.options.cxx:
self.cpp_info.libs.append("tiffxx")
self.cpp_info.libs.append("tiff")
if self.settings.os == "Windows" and self.settings.build_type == "Debug" and is_msvc(self):
self.cpp_info.libs = [lib + "d" for lib in self.cpp_info.libs]
if self.options.shared and self.settings.os == "Windows" and not is_msvc(self):
self.cpp_info.libs = [lib + ".dll" for lib in self.cpp_info.libs]
self.cpp_info.libs.append(f"tiffxx{suffix}")
self.cpp_info.libs.append(f"tiff{suffix}")
if self.settings.os in ["Linux", "Android", "FreeBSD", "SunOS", "AIX"]:
self.cpp_info.system_libs.append("m")

# TODO: to remove in conan v2 once cmake_find_package* & pkg_config generators removed
self.cpp_info.names["cmake_find_package"] = "TIFF"
self.cpp_info.names["cmake_find_package_multi"] = "TIFF"
self.cpp_info.names["pkg_config"] = "libtiff-{}".format(Version(self.version).major)
self.cpp_info.names["pkg_config"] = f"libtiff-{Version(self.version).major}"

This file was deleted.

38 changes: 38 additions & 0 deletions recipes/libtiff/all/patches/4.0.8-0001-cmake-dependencies.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -544,12 +544,10 @@ endif()
option(jbig "use ISO JBIG compression (requires JBIT-KIT library)" ON)
if (jbig)
set(JBIG_FOUND 0)
- find_path(JBIG_INCLUDE_DIR jbig.h)
- set(JBIG_NAMES ${JBIG_NAMES} jbig libjbig)
- find_library(JBIG_LIBRARY NAMES ${JBIG_NAMES})
- if (JBIG_INCLUDE_DIR AND JBIG_LIBRARY)
+ find_package(jbig REQUIRED CONFIG)
+ if (1)
set(JBIG_FOUND 1)
- set(JBIG_LIBRARIES ${JBIG_LIBRARY})
+ set(JBIG_LIBRARIES jbig::jbig)
endif()
endif()
set(JBIG_SUPPORT 0)
@@ -564,7 +562,7 @@ set(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_INCLUDES_SAVE ${CMAKE_REQUIRED_INCLUDES})
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${JBIG_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${JBIG_LIBRARY})
-check_function_exists(jbg_newlen HAVE_JBG_NEWLEN)
+set(HAVE_JBG_NEWLEN TRUE)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE})
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVE})

@@ -701,8 +699,8 @@ endif()
if(ZLIB_LIBRARIES)
list(APPEND TIFF_LIBRARY_DEPS ${ZLIB_LIBRARIES})
endif()
-if(JPEG_LIBRARIES)
- list(APPEND TIFF_LIBRARY_DEPS ${JPEG_LIBRARIES})
+if(JPEG_FOUND)
+ list(APPEND TIFF_LIBRARY_DEPS JPEG::JPEG)
endif()
if(JPEG12_LIBRARIES)
list(APPEND TIFF_LIBRARY_DEPS ${JPEG12_LIBRARIES})
13 changes: 13 additions & 0 deletions recipes/libtiff/all/patches/4.0.8-0002-no-libm-mingw.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -206,7 +206,9 @@ else()
endif()

# Find libm, if available
-find_library(M_LIBRARY m)
+if (NOT MINGW)
+ find_library(M_LIBRARY m)
+endif()

check_include_file(assert.h HAVE_ASSERT_H)
check_include_file(dlfcn.h HAVE_DLFCN_H)
Loading

0 comments on commit 7f96bef

Please sign in to comment.