Skip to content

Commit

Permalink
(conan-io#13031) mozjpeg: add version 4.1.1 and support conan v2
Browse files Browse the repository at this point in the history
* mozjpeg: add version 4.1.1 and support conan v2

* add argument to is_msvc_static_untime

* Update conanfile.py

* fix bug in bin_path

* remove lib64 folder

* fix jpeg file path

* fix binary install folder

* fix link error in MT

* fix wrong condition for WITH_CRT_DLL

* revert ENABLE_SHARED,ENABLE_STATIC

* fix static binary path

* use TARGET_FILE in 3.3.1
  • Loading branch information
toge authored and kayoub5 committed Sep 29, 2022
1 parent b99acf6 commit 6f1b74b
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 124 deletions.
9 changes: 0 additions & 9 deletions recipes/mozjpeg/all/CMakeLists.txt

This file was deleted.

17 changes: 13 additions & 4 deletions recipes/mozjpeg/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
sources:
"4.1.1":
url: "https://github.com/mozilla/mozjpeg/archive/v4.1.1.tar.gz"
sha256: "66b1b8d6b55d263f35f27f55acaaa3234df2a401232de99b6d099e2bb0a9d196"
"4.0.0":
url: "https://github.com/mozilla/mozjpeg/archive/v4.0.0.tar.gz"
sha256: "961e14e73d06a015e9b23b8af416f010187cc0bec95f6e3b0fcb28cc7e2cbdd4"
"3.3.1":
url: "https://github.com/mozilla/mozjpeg/archive/v3.3.1.tar.gz"
sha256: "aebbea60ea038a84a2d1ed3de38fdbca34027e2e54ee2b7d08a97578be72599d"
patches:
"4.1.1":
- patch_file: "patches/4.1.1-0001-cmake-fixes.patch"
patch_description: "fix install folder and disable /NODEFAULT in MSVC"
patch_type: "conan"
"4.0.0":
- base_path: "source_subfolder"
patch_file: "patches/4.0.0-0001-cmake-fixes.patch"
- patch_file: "patches/4.0.0-0001-cmake-fixes.patch"
patch_description: "fix install folder"
patch_type: "conan"
"3.3.1":
- base_path: "source_subfolder"
patch_file: "patches/3.3.1-0001-cmake-fixes.patch"
- patch_file: "patches/3.3.1-0001-cmake-fixes.patch"
patch_description: "fix install folder"
patch_type: "conan"
208 changes: 114 additions & 94 deletions recipes/mozjpeg/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
from conans import ConanFile, AutoToolsBuildEnvironment, CMake, tools
import os

from conan import ConanFile
from conan.tools.microsoft import is_msvc_static_runtime, is_msvc
from conan.tools.files import apply_conandata_patches, get, copy, rm, rmdir, export_conandata_patches
from conan.tools.build import cross_building
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps
from conan.tools.env import VirtualBuildEnv
from conan.tools.layout import basic_layout

required_conan_version = ">=1.33.0"
import os

required_conan_version = ">=1.52.0"

class MozjpegConan(ConanFile):
name = "mozjpeg"
description = "MozJPEG is an improved JPEG encoder"
url = "https://github.com/conan-io/conan-center-index"
topics = ("conan", "image", "format", "mozjpeg", "jpg", "jpeg", "picture", "multimedia", "graphics")
license = ("BSD", "BSD-3-Clause", "ZLIB")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/mozilla/mozjpeg"
exports_sources = ("CMakeLists.txt", "patches/*")
generators = "cmake"
topics = ("conan", "image", "format", "mozjpeg", "jpg", "jpeg", "picture", "multimedia", "graphics")
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand Down Expand Up @@ -42,21 +47,13 @@ class MozjpegConan(ConanFile):
"enable12bit": False,
}

_autotools = None
_cmake = None

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

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

@property
def _has_simd_support(self):
return self.settings.arch in ["x86", "x86_64"]

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
Expand All @@ -65,122 +62,145 @@ def config_options(self):

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
try:
del self.options.fPIC
except Exception:
pass
try:
del self.settings.compiler.libcxx
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass
self.provides = ["libjpeg", "libjpeg-turbo"] if self.options.turbojpeg else "libjpeg"

@property
def _use_cmake(self):
return self.settings.os == "Windows" or tools.Version(self.version) >= "4.0.0"
return self.settings.os == "Windows" or Version(self.version) >= "4.0.0"

def layout(self):
if self._use_cmake:
cmake_layout(self, src_folder="src")
else:
basic_layout(self, src_folder='src')

def build_requirements(self):
if not self._use_cmake:
if self.settings.os != "Windows":
self.build_requires("libtool/2.4.6")
self.build_requires("pkgconf/1.7.4")
if not self._use_cmake and self.settings.os != "Windows":
self.tool_requires("libtool/2.4.7")
self.tool_requires("pkgconf/1.7.4")
if self.options.get_safe("SIMD"):
self.build_requires("nasm/2.15.05")
self.tool_requires("nasm/2.15.05")

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

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
if tools.cross_building(self.settings):
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def generate_cmake(self):
tc = CMakeToolchain(self)
if cross_building(self):
# FIXME: too specific and error prone, should be delegated to CMake helper
cmake_system_processor = {
"armv8": "aarch64",
"armv8.3": "aarch64",
}.get(str(self.settings.arch), str(self.settings.arch))
self._cmake.definitions["CMAKE_SYSTEM_PROCESSOR"] = cmake_system_processor
self._cmake.definitions["ENABLE_TESTING"] = False
self._cmake.definitions["ENABLE_STATIC"] = not self.options.shared
self._cmake.definitions["ENABLE_SHARED"] = self.options.shared
self._cmake.definitions["REQUIRE_SIMD"] = self.options.get_safe("SIMD", False)
self._cmake.definitions["WITH_SIMD"] = self.options.get_safe("SIMD", False)
self._cmake.definitions["WITH_ARITH_ENC"] = self.options.arithmetic_encoder
self._cmake.definitions["WITH_ARITH_DEC"] = self.options.arithmetic_decoder
self._cmake.definitions["WITH_JPEG7"] = self.options.libjpeg7_compatibility
self._cmake.definitions["WITH_JPEG8"] = self.options.libjpeg8_compatibility
self._cmake.definitions["WITH_MEM_SRCDST"] = self.options.mem_src_dst
self._cmake.definitions["WITH_TURBOJPEG"] = self.options.turbojpeg
self._cmake.definitions["WITH_JAVA"] = self.options.java
self._cmake.definitions["WITH_12BIT"] = self.options.enable12bit
self._cmake.definitions["CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT"] = False
self._cmake.definitions["PNG_SUPPORTED"] = False # PNG and zlib are only required for executables (and static libraries)
if self.settings.compiler == "Visual Studio":
self._cmake.definitions["WITH_CRT_DLL"] = "MD" in str(self.settings.compiler.runtime)
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def _configure_autotools(self):
if not self._autotools:
self._autotools = AutoToolsBuildEnvironment(self)
yes_no = lambda v: "yes" if v else "no"
args = [
"--with-pic={}".format(yes_no(self.options.get_safe("fPIC", True))),
"--with-simd={}".format(yes_no(self.options.get_safe("SIMD", False))),
"--with-arith-enc={}".format(yes_no(self.options.arithmetic_encoder)),
"--with-arith-dec={}".format(yes_no(self.options.arithmetic_decoder)),
"--with-jpeg7={}".format(yes_no(self.options.libjpeg7_compatibility)),
"--with-jpeg8={}".format(yes_no(self.options.libjpeg8_compatibility)),
"--with-mem-srcdst={}".format(yes_no(self.options.mem_src_dst)),
"--with-turbojpeg={}".format(yes_no(self.options.turbojpeg)),
"--with-java={}".format(yes_no(self.options.java)),
"--with-12bit={}".format(yes_no(self.options.enable12bit)),
"--enable-shared={}".format(yes_no(self.options.shared)),
"--enable-static={}".format(yes_no(not self.options.shared)),
]
self._autotools.configure(configure_dir=self._source_subfolder, args=args)
return self._autotools
tc.variables["CMAKE_SYSTEM_PROCESSOR"] = cmake_system_processor
tc.variables["ENABLE_SHARED"] = self.options.shared
tc.variables["ENABLE_STATIC"] = not self.options.shared
tc.variables["ENABLE_TESTING"] = False
tc.variables["REQUIRE_SIMD"] = bool(self.options.get_safe("SIMD", False))
tc.variables["WITH_SIMD"] = bool(self.options.get_safe("SIMD", False))
tc.variables["WITH_ARITH_ENC"] = bool(self.options.arithmetic_encoder)
tc.variables["WITH_ARITH_DEC"] = bool(self.options.arithmetic_decoder)
tc.variables["WITH_JPEG7"] = bool(self.options.libjpeg7_compatibility)
tc.variables["WITH_JPEG8"] = bool(self.options.libjpeg8_compatibility)
tc.variables["WITH_MEM_SRCDST"] = bool(self.options.mem_src_dst)
tc.variables["WITH_TURBOJPEG"] = bool(self.options.turbojpeg)
tc.variables["WITH_JAVA"] = bool(self.options.java)
tc.variables["WITH_12BIT"] = bool(self.options.enable12bit)
tc.variables["CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT"] = False
tc.variables["PNG_SUPPORTED"] = False # PNG and zlib are only required for executables (and static libraries)
if is_msvc(self):
tc.variables["WITH_CRT_DLL"] = not is_msvc_static_runtime(self)
tc.generate()

tc = CMakeDeps(self)
tc.generate()

def generate_autotools(self):
toolchain = AutotoolsToolchain(self)
yes_no = lambda v: "yes" if v else "no"
toolchain.configure_args.append("--with-pic={}".format(yes_no(self.options.get_safe("fPIC", True))))
toolchain.configure_args.append("--with-simd={}".format(yes_no(self.options.get_safe("SIMD", False))))
toolchain.configure_args.append("--with-arith-enc={}".format(yes_no(self.options.arithmetic_encoder)))
toolchain.configure_args.append("--with-arith-dec={}".format(yes_no(self.options.arithmetic_decoder)))
toolchain.configure_args.append("--with-jpeg7={}".format(yes_no(self.options.libjpeg7_compatibility)))
toolchain.configure_args.append("--with-jpeg8={}".format(yes_no(self.options.libjpeg8_compatibility)))
toolchain.configure_args.append("--with-mem-srcdst={}".format(yes_no(self.options.mem_src_dst)))
toolchain.configure_args.append("--with-turbojpeg={}".format(yes_no(self.options.turbojpeg)))
toolchain.configure_args.append("--with-java={}".format(yes_no(self.options.java)))
toolchain.configure_args.append("--with-12bit={}".format(yes_no(self.options.enable12bit)))
toolchain.generate()

deps = AutotoolsDeps(self)
deps.generate()

def generate(self):
if self._use_cmake:
self.generate_cmake()
else:
self.generate_autotools()

tc = VirtualBuildEnv(self)
tc.generate(scope="build")

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
apply_conandata_patches(self)
if self._use_cmake:
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()
else:
with tools.chdir(self._source_subfolder):
self.run("{} -fiv".format(tools.get_env("AUTORECONF")))
autotools = self._configure_autotools()
autotools = Autotools(self)
autotools.autoreconf()
autotools.configure()
autotools.make()

def package(self):
self.copy(pattern="LICENSE.md", dst="licenses", src=self._source_subfolder)
copy(self, pattern="LICENSE.md", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
if self._use_cmake:
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "doc"))
rmdir(self, os.path.join(self.package_folder, "doc"))
else:
autotools = self._configure_autotools()
autotools = Autotools(self)
autotools.install()
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
rm(self, pattern="*.la", folder=os.path.join(self.package_folder, "lib"))

tools.rmdir(os.path.join(self.package_folder, "share"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
copy(self, pattern="*.a", dst=os.path.join(self.package_folder, "lib"), src=os.path.join(self.package_folder, "lib64"))
rmdir(self, os.path.join(self.package_folder, "lib64"))
# remove binaries and pdb files
for bin_pattern_to_remove in ["cjpeg*", "djpeg*", "jpegtran*", "tjbench*", "wrjpgcom*", "rdjpgcom*", "*.pdb"]:
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), bin_pattern_to_remove)
rm(self, pattern=bin_pattern_to_remove, folder=os.path.join(self.package_folder, "bin"))

def _lib_name(self, name):
if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio" and not self.options.shared:
if is_msvc(self) and not self.options.shared:
return name + "-static"
return name

def package_info(self):
# libjpeg
self.cpp_info.components["libjpeg"].names["pkg_config"] = "libjpeg"
self.cpp_info.components["libjpeg"].libs = [self._lib_name("jpeg")]
if self.settings.os == "Linux":
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["libjpeg"].system_libs.append("m")
# libturbojpeg
if self.options.turbojpeg:
self.cpp_info.components["libturbojpeg"].names["pkg_config"] = "libturbojpeg"
self.cpp_info.components["libturbojpeg"].libs = [self._lib_name("turbojpeg")]
if self.settings.os == "Linux":
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["libturbojpeg"].system_libs.append("m")
10 changes: 5 additions & 5 deletions recipes/mozjpeg/all/patches/3.3.1-0001-cmake-fixes.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 743a243..b5d41a1 100644
index 743a243..eb787c8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -168,7 +168,7 @@ message(STATUS "Install directory = ${CMAKE_INSTALL_PREFIX}")
Expand Down Expand Up @@ -34,7 +34,7 @@ index 743a243..b5d41a1 100644
install(TARGETS turbojpeg-static ARCHIVE DESTINATION lib)
if(NOT ENABLE_SHARED)
- install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/tjbench-static.exe
+ install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tjbench-static.exe
+ install(PROGRAMS $<TARGET_FILE:tjbench-static>
DESTINATION bin RENAME tjbench.exe)
endif()
endif()
Expand All @@ -46,13 +46,13 @@ index 743a243..b5d41a1 100644
install(TARGETS jpeg-static ARCHIVE DESTINATION lib)
if(NOT ENABLE_SHARED)
- install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/cjpeg-static.exe
+ install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/cjpeg-static.exe
+ install(PROGRAMS $<TARGET_FILE:cjpeg-static>
DESTINATION bin RENAME cjpeg.exe)
- install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/djpeg-static.exe
+ install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/djpeg-static.exe
+ install(PROGRAMS $<TARGET_FILE:djpeg-static>
DESTINATION bin RENAME djpeg.exe)
- install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/jpegtran-static.exe
+ install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/jpegtran-static.exe
+ install(PROGRAMS $<TARGET_FILE:jpegtran-static>
DESTINATION bin RENAME jpegtran.exe)
endif()
endif()
Expand Down
34 changes: 34 additions & 0 deletions recipes/mozjpeg/all/patches/4.1.1-0001-cmake-fixes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8d295c6..b30dacb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1461,7 +1461,7 @@ if(WITH_TURBOJPEG)
else()
set(DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
- install(PROGRAMS ${DIR}/tjbench-static${EXE}
+ install(PROGRAMS $<TARGET_FILE:tjbench-static>
DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME tjbench${EXE})
endif()
endif()
@@ -1479,16 +1479,16 @@ if(ENABLE_STATIC)
else()
set(DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
- install(PROGRAMS ${DIR}/cjpeg-static${EXE}
+ install(PROGRAMS $<TARGET_FILE:cjpeg-static>
DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME cjpeg${EXE})
- install(PROGRAMS ${DIR}/djpeg-static${EXE}
+ install(PROGRAMS $<TARGET_FILE:djpeg-static>
DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME djpeg${EXE})
- install(PROGRAMS ${DIR}/jpegtran-static${EXE}
+ install(PROGRAMS $<TARGET_FILE:jpegtran-static>
DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME jpegtran${EXE})
endif()
endif()

-install(TARGETS rdjpgcom wrjpgcom RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+install(TARGETS rdjpgcom wrjpgcom DESTINATION ${CMAKE_INSTALL_BINDIR})

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/README.ijg
${CMAKE_CURRENT_SOURCE_DIR}/README.md ${CMAKE_CURRENT_SOURCE_DIR}/example.txt
8 changes: 4 additions & 4 deletions recipes/mozjpeg/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.8)

project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(mozjpeg REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE mozjpeg::libjpeg)
Loading

0 comments on commit 6f1b74b

Please sign in to comment.