Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leptonica: add version 1.84.1 #21945

Closed
wants to merge 15 commits into from
Closed
3 changes: 3 additions & 0 deletions recipes/leptonica/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"1.84.1":
url: "https://github.com/DanBloomberg/leptonica/archive/1.84.1.tar.gz"
sha256: "ecd7a868403b3963c4e33623595d77f2c87667e2cfdd9b370f87729192061bef"
"1.83.1":
url: "https://github.com/DanBloomberg/leptonica/archive/1.83.1.tar.gz"
sha256: "4289d0a4224b614010072253531c0455a33a4d7c7a0017fe7825ed382290c0da"
Expand Down
49 changes: 41 additions & 8 deletions recipes/leptonica/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, collect_libs, copy, export_conandata_patches, get, replace_in_file, rmdir, save
Expand Down Expand Up @@ -44,6 +45,17 @@ class LeptonicaConan(ConanFile):
"with_webp": True,
}

# in case the project requires C17... the minimum compiler version should be listed
@property
def _compilers_minimum_version(self):
return {
"apple-clang": "11",
"clang": "7",
"gcc": "8",
"msvc": "192",
"Visual Studio": "16",
}

def export_sources(self):
export_conandata_patches(self)

Expand Down Expand Up @@ -84,10 +96,20 @@ def requirements(self):
if self.options.with_webp:
self.requires("libwebp/1.3.2")

def validate(self):
if Version(self.version) >= "1.84.0":
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C17, which your compiler does not support."
)

def build_requirements(self):
if self.options.with_webp or self.options.with_openjpeg:
if not self.conf.get("tools.gnu:pkg_config", check_type=str):
self.tool_requires("pkgconf/2.1.0")
if Version(self.version) >= "1.84.0":
self.tool_requires("cmake/[>=3.21 <4]")
uilianries marked this conversation as resolved.
Show resolved Hide resolved

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
Expand All @@ -101,6 +123,9 @@ def generate(self):
if Version(self.version) >= "1.83.0":
tc.variables["LIBWEBP_SUPPORT"] = self.options.with_webp
tc.variables["OPENJPEG_SUPPORT"] = self.options.with_openjpeg
if Version(self.version) >= "1.84.0" and self.options.with_openjpeg:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the version 1.84.0 added options to enable dependencies: DanBloomberg/leptonica@1.83.1...1.84.1#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20aR65

It could be not only added to this recipe, but also fix this preprocessor workaround.

jp2k_include_dir = self.dependencies["openjpeg"].cpp_info.includedirs[1].replace("\\", "/")
tc.preprocessor_definitions["LIBJP2K_HEADER"] = f"<{jp2k_include_dir}/openjpeg.h>"
tc.generate()
deps = CMakeDeps(self)
deps.generate()
Expand Down Expand Up @@ -159,7 +184,8 @@ def _patch_sources(self):
## We have to be more aggressive with dependencies found with pkgconfig
## Injection of libdirs is ensured by conan_basic_setup()
## openjpeg
replace_in_file(self, cmakelists_src, "${JP2K_LIBRARIES}", "openjp2")
if Version(self.version) < "1.84.0":
replace_in_file(self, cmakelists_src, "${JP2K_LIBRARIES}", "openjp2")
if Version(self.version) < "1.83.0":
# pkgconfig is prefered to CMake. Disable pkgconfig so only CMake is used
if Version(self.version) <= "1.78.0":
Expand All @@ -171,10 +197,12 @@ def _patch_sources(self):
if not self.options.with_openjpeg:
replace_in_file(self, cmakelists_src, "if (JP2K_FOUND)", "if(0)")
replace_in_file(self, cmake_configure, "if (JP2K_FOUND)", "if(0)")
else:
elif Version(self.version) < "1.84.0":
replace_in_file(self, cmakelists, "set(JP2K_INCLUDE_DIRS ${OPENJPEG_INCLUDE_DIRS})", "set(JP2K_INCLUDE_DIRS ${OpenJPEG_INCLUDE_DIRS})")
if not self.options.with_openjpeg:
replace_in_file(self, cmake_configure, "if(JP2K_FOUND)", "if(0)")
else:
replace_in_file(self, cmakelists_src, "target_include_directories (leptonica PRIVATE ${OPENJPEG_INCLUDE_DIRS})", "target_include_directories (leptonica PRIVATE ${OpenJPEG_INCLUDE_DIRS})")

## libwebp
if Version(self.version) < "1.83.0":
Expand All @@ -185,12 +213,13 @@ def _patch_sources(self):
if not self.options.with_webp:
replace_in_file(self, cmakelists_src, "if (WEBP_FOUND)", "if(0)")
replace_in_file(self, cmake_configure, "if (WEBP_FOUND)", "if(0)")
replace_in_file(self, cmakelists_src,
"if (WEBP_FOUND)",
"if (WEBP_FOUND)\n"
"target_link_directories(leptonica PRIVATE ${WEBP_LIBRARY_DIRS} ${WEBPMUX_LIBRARY_DIRS})\n"
"target_compile_definitions(leptonica PRIVATE ${WEBP_CFLAGS_OTHER} ${WEBPMUX_CFLAGS_OTHER})")
replace_in_file(self, cmakelists_src, "${WEBP_LIBRARIES}", "${WEBP_LIBRARIES} ${WEBPMUX_LIBRARIES}")
if Version(self.version) < "1.84.0":
replace_in_file(self, cmakelists_src,
"if (WEBP_FOUND)",
"if (WEBP_FOUND)\n"
"target_link_directories(leptonica PRIVATE ${WEBP_LIBRARY_DIRS} ${WEBPMUX_LIBRARY_DIRS})\n"
"target_compile_definitions(leptonica PRIVATE ${WEBP_CFLAGS_OTHER} ${WEBPMUX_CFLAGS_OTHER})")
replace_in_file(self, cmakelists_src, "${WEBP_LIBRARIES}", "${WEBP_LIBRARIES} ${WEBPMUX_LIBRARIES}")

# Remove detection of fmemopen() on macOS < 10.13
# CheckFunctionExists will find it in the link library.
Expand All @@ -204,6 +233,10 @@ def _patch_sources(self):
"set(functions_list\n "
"fstatat\n)")

if Version(self.version) >= "1.83.0":
libwebp_version = self.dependencies["libwebp"].ref.version
replace_in_file(self, cmakelists, "set(MINIMUM_WEBPMUX_VERSION 0.5.0)", f"set(MINIMUM_WEBPMUX_VERSION {libwebp_version})")

def build(self):
self._patch_sources()
cmake = CMake(self)
Expand Down
2 changes: 2 additions & 0 deletions recipes/leptonica/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"1.84.1":
folder: all
"1.83.1":
folder: all
"1.83.0":
Expand Down
Loading