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

libjxl: migrate to Conan v2, add v0.10.2 #18812

Merged
merged 47 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a49eead
libjxl: migrate to Conan v2
valgur Jul 20, 2023
e9fff9e
libjxl: restore VirtualRunEnv in test_package
valgur Jul 26, 2023
c731280
libjxl: bump deps
valgur Sep 12, 2023
5d6c63a
libjxl: fix shared build
valgur Oct 24, 2023
83b4d1b
libjxl: simplify patching
valgur Oct 24, 2023
b28d312
libjxl: add v0.8.2, v0.7
valgur Oct 24, 2023
1ec0982
libjxl: fix test_v1_package
valgur Oct 24, 2023
9b1df9d
libjxl: avoid the use of $<TARGET_PROPERTY> in CMake
valgur Oct 24, 2023
013db8c
libjxl: fix linking issues with brotli
valgur Nov 3, 2023
b6c1bdb
libjxl: drop old versions
valgur Dec 3, 2023
840ecbf
libjxl: fix MSVC build
valgur Dec 3, 2023
9c39923
libjxl: package only shared or static
valgur Dec 4, 2023
9f25715
libjxl: add check_min_cppstd
valgur Dec 4, 2023
753e866
libjxl: disable libc++ on Conan v1
valgur Dec 4, 2023
e92c187
Merge branch 'master' into migrate/libjxl
valgur Dec 4, 2023
7cff378
Merge branch 'master' into migrate/libjxl
valgur Dec 5, 2023
178fef9
libidn: fix workaround check
valgur Dec 8, 2023
a22928a
Merge branch 'master' into migrate/libjxl
valgur Dec 12, 2023
82f54a5
Merge branch 'master' into migrate/libjxl
uilianries Dec 12, 2023
df9c130
libjxl: fix -latomic detection
valgur Dec 13, 2023
65bd2f7
Merge branch 'master' into migrate/libjxl
valgur Dec 14, 2023
c7ac8a2
jxl: add v0.9.1, v0.6.1, simplify patching
valgur Jan 13, 2024
7bab31e
jxl: add jxl_cms component
valgur Jan 13, 2024
a3c0d4f
jxl: always require newer CMake
valgur Jan 13, 2024
4c66090
jxl: Fix --exclude-libs detection on apple-clang
valgur Jan 13, 2024
44d6e24
jxl: add more target aliases
valgur Jan 13, 2024
dc31040
jxl: fix --exclude-libs on v0.6.1
valgur Jan 13, 2024
0a75227
jxl: disable FindAtomics.cmake
valgur Jan 13, 2024
87c5200
jxl: improve fPIC handling
valgur Jan 15, 2024
dc02c7e
jxl: -static suffix is no longer added on Windows
valgur Jan 15, 2024
5d9761b
jxl: more fPIC fixes
valgur Jan 15, 2024
b8f8a56
jxl: add with_tcmalloc option, set all v0.9.1 CMake vars
valgur Jan 15, 2024
387fc17
jxl: match the tcmalloc setting in the project
valgur Jan 15, 2024
52304e3
Merge branch 'master' into migrate/libjxl
valgur Jan 16, 2024
283be32
libjxl: fix Debug build
valgur Jan 23, 2024
3739eb9
libjxl: disable MSVC Debug build for v0.6.1
valgur Jan 23, 2024
d0a1134
libjxl: add DLL define for jxl_cms
valgur Jan 24, 2024
d74a964
Merge branch 'master' into migrate/libjxl
valgur Feb 20, 2024
98623b7
libjxl: bump to v0.10.2
valgur Mar 22, 2024
f613015
Merge remote-tracking branch 'upstream/master' into migrate/libjxl
valgur Mar 22, 2024
a61a47a
libjxl: bump deps
valgur Mar 22, 2024
a3d8f5a
libjxl: disable MSVC shared build for v0.6.1
valgur Mar 22, 2024
ab8e5c4
libjxl: add v0.8.2 for GDAL
valgur Mar 26, 2024
d8d8f0c
Test
AbrilRBS Apr 30, 2024
dffafd2
libjxl: refactor test_package
ErniGH Apr 30, 2024
5914026
Merge branch 'migrate/libjxl' of https://github.com/valgur/conan-cent…
ErniGH Apr 30, 2024
3b427b2
Disable tools via config and remove neon
uilianries Jul 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions recipes/libjxl/all/CMakeLists.txt

This file was deleted.

24 changes: 24 additions & 0 deletions recipes/libjxl/all/conan_deps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
find_package(Brotli REQUIRED CONFIG)
find_package(HWY REQUIRED CONFIG)
find_package(LCMS2 REQUIRED CONFIG)

# Add wrapper targets for the project to link against
add_library(brotlicommon INTERFACE)
target_link_libraries(brotlicommon INTERFACE brotli::brotli)
set_target_properties(brotlicommon PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Brotli_INCLUDE_DIRS}")
set_target_properties(brotlicommon PROPERTIES INCLUDE_DIRECTORIES "${Brotli_INCLUDE_DIRS}")
add_library(brotlidec ALIAS brotlicommon)
add_library(brotlienc ALIAS brotlicommon)
add_library(brotlicommon-static ALIAS brotlicommon)
add_library(brotlidec-static ALIAS brotlicommon)
add_library(brotlienc-static ALIAS brotlicommon)

add_library(hwy INTERFACE)
target_link_libraries(hwy INTERFACE highway::highway)
set_target_properties(hwy PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${HWY_INCLUDE_DIRS}")
set_target_properties(hwy PROPERTIES INCLUDE_DIRECTORIES "${HWY_INCLUDE_DIRS}")

add_library(lcms2 INTERFACE)
target_link_libraries(lcms2 INTERFACE lcms::lcms)
set_target_properties(lcms2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LCMS2_INCLUDE_DIRS}")
set_target_properties(lcms2 PROPERTIES INCLUDE_DIRECTORIES "${LCMS2_INCLUDE_DIRS}")
20 changes: 6 additions & 14 deletions recipes/libjxl/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
sources:
"0.5.0":
url: "https://github.com/libjxl/libjxl/archive/v0.5.zip"
sha256: "a208be41542c6f81f10a82c6bb4bc75d3eceb9d4f7ecb6ea0ad2f2d236694c4b"
"0.10.2":
url: "https://github.com/libjxl/libjxl/archive/v0.10.2.zip"
sha256: "910ab4245eebe0fba801a057f5fbc4fe96dad7c9979880bb49ad3e2623a911a2"
"0.8.2":
url: "https://github.com/libjxl/libjxl/archive/v0.8.2.zip"
sha256: "1f2ccc06f07c4f6cf4aa6c7763ba0598f12a7544d597f02beb07f615eb08ccf0"
"0.6.1":
url: "https://github.com/libjxl/libjxl/archive/v0.6.1.zip"
sha256: "3e4877daef07724aa6f490bf80c45ada804f35fe3cce59c27e89c5ae3099535a"
patches:
"0.5.0":
- patch_file: "patches/0001-clean-targets-v0.5.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-fix-dependencies-v0.5.patch"
base_path: "source_subfolder"
"0.6.1":
- patch_file: "patches/0001-clean-targets-v0.6.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-fix-dependencies-v0.6.patch"
base_path: "source_subfolder"
278 changes: 195 additions & 83 deletions recipes/libjxl/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from conans import ConanFile, CMake, tools
import os
import shutil
import glob

required_conan_version = ">=1.33.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import cross_building, stdcpp_library, check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import copy, get, rmdir, save, rm, replace_in_file
from conan.tools.gnu import PkgConfigDeps
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"


class LibjxlConan(ConanFile):
Expand All @@ -14,114 +21,219 @@ class LibjxlConan(ConanFile):
homepage = "https://github.com/libjxl/libjxl"
topics = ("image", "jpeg-xl", "jxl", "jpeg")

settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

exports_sources = "CMakeLists.txt", "patches/**"
generators = "cmake"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"avx512": [True, False],
"avx512_spr": [True, False],
"avx512_zen4": [True, False],
"force_neon": [True, False],
"with_tcmalloc": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"avx512": False,
"avx512_spr": False,
"avx512_zen4": False,
"force_neon": False,
"with_tcmalloc": False,
}

def export_sources(self):
copy(self, "conan_deps.cmake", self.recipe_folder, os.path.join(self.export_sources_folder, "src"))

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if self.settings.arch not in ["x86", "x86_64"] or Version(self.version) < "0.9":
del self.options.avx512
del self.options.avx512_spr
del self.options.avx512_zen4
if not str(self.settings.arch).startswith("arm"):
del self.options.force_neon
# https://github.com/libjxl/libjxl/blob/v0.9.1/CMakeLists.txt#L52-L59
if self.settings.os in ["Linux", "FreeBSD"] and self.settings.arch == "x86_64":
self.options.with_tcmalloc = True

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

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

def requirements(self):
self.requires("brotli/1.0.9")
self.requires("highway/0.12.2")
self.requires("lcms/2.11")
self.requires("brotli/1.1.0")
if Version(self.version) >= "0.7":
self.requires("highway/1.1.0")
else:
self.requires("highway/0.12.2")
self.requires("lcms/2.16")
if self.options.with_tcmalloc:
self.requires("gperftools/2.15")

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, 11)
if self.version == "0.6.1" and is_msvc(self) and self.options.shared:
# Fails with a missing DLL error in test_package
raise ConanInvalidConfiguration(f"{self.ref} does not support shared builds with MSVC")

def build_requirements(self):
# Require newer CMake, which allows INCLUDE_DIRECTORIES to be set on INTERFACE targets
# Also, v0.9+ require CMake 3.16
self.tool_requires("cmake/[>=3.19 <4]")

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

def generate(self):
VirtualBuildEnv(self).generate()

tc = CMakeToolchain(self)
tc.variables["CMAKE_PROJECT_LIBJXL_INCLUDE"] = "conan_deps.cmake"
tc.variables["BUILD_TESTING"] = False
tc.variables["JPEGXL_STATIC"] = not self.options.shared # applies to tools only
tc.variables["JPEGXL_BUNDLE_LIBPNG"] = False
tc.variables["JPEGXL_ENABLE_BENCHMARK"] = False
tc.variables["JPEGXL_ENABLE_DOXYGEN"] = False
tc.variables["JPEGXL_ENABLE_EXAMPLES"] = False
tc.variables["JPEGXL_ENABLE_JNI"] = False
tc.variables["JPEGXL_ENABLE_MANPAGES"] = False
tc.variables["JPEGXL_ENABLE_OPENEXR"] = False
tc.variables["JPEGXL_ENABLE_PLUGINS"] = False
tc.variables["JPEGXL_ENABLE_SJPEG"] = False
tc.variables["JPEGXL_ENABLE_SKCMS"] = False
tc.variables["JPEGXL_ENABLE_TCMALLOC"] = self.options.with_tcmalloc
tc.variables["JPEGXL_ENABLE_VIEWERS"] = False
tc.variables["JPEGXL_FORCE_SYSTEM_BROTLI"] = True
tc.variables["JPEGXL_FORCE_SYSTEM_GTEST"] = True
tc.variables["JPEGXL_FORCE_SYSTEM_HWY"] = True
tc.variables["JPEGXL_FORCE_SYSTEM_LCMS2"] = True
tc.variables["JPEGXL_WARNINGS_AS_ERRORS"] = False
tc.variables["JPEGXL_ENABLE_AVX512"] = self.options.get_safe("avx512", False)
tc.variables["JPEGXL_ENABLE_AVX512_SPR"] = self.options.get_safe("avx512_spr", False)
tc.variables["JPEGXL_ENABLE_AVX512_ZEN4"] = self.options.get_safe("avx512_zen4", False)
tc.variables["JPEGXL_FORCE_NEON"] = self.options.get_safe("force_neon", False)
if cross_building(self):
tc.variables["CMAKE_SYSTEM_PROCESSOR"] = str(self.settings.arch)
# Allow non-cache_variables to be used
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
# Skip the buggy custom FindAtomic and force the use of atomic library directly for libstdc++
tc.variables["ATOMICS_LIBRARIES"] = "atomic" if self._atomic_required else ""
if Version(self.version) >= "0.8":
# TODO: add support for the jpegli JPEG encoder library
tc.variables["JPEGXL_ENABLE_JPEGLI"] = False
tc.variables["JPEGXL_ENABLE_JPEGLI_LIBJPEG"] = False
# TODO: can hopefully be removed in newer versions
# https://github.com/libjxl/libjxl/issues/3159
if Version(self.version) >= "0.9" and self.settings.build_type == "Debug" and is_msvc(self):
tc.preprocessor_definitions["JXL_DEBUG_V_LEVEL"] = 1
tc.generate()

deps = CMakeDeps(self)
deps.set_property("brotli", "cmake_file_name", "Brotli")
deps.set_property("highway", "cmake_file_name", "HWY")
deps.set_property("lcms", "cmake_file_name", "LCMS2")
deps.generate()

# For tcmalloc
deps = PkgConfigDeps(self)
deps.generate()

@property
def _atomic_required(self):
return self.settings.get_safe("compiler.libcxx") in ["libstdc++", "libstdc++11"]

def _patch_sources(self):
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_TESTING"] = False
self._cmake.definitions["JPEGXL_STATIC"] = not self.options.shared
self._cmake.definitions["JPEGXL_ENABLE_BENCHMARK"] = False
self._cmake.definitions["JPEGXL_ENABLE_EXAMPLES"] = False
self._cmake.definitions["JPEGXL_ENABLE_MANPAGES"] = False
self._cmake.definitions["JPEGXL_ENABLE_SJPEG"] = False
self._cmake.definitions["JPEGXL_ENABLE_OPENEXR"] = False
self._cmake.definitions["JPEGXL_ENABLE_SKCMS"] = False
self._cmake.definitions["JPEGXL_ENABLE_TCMALLOC"] = False
if tools.cross_building(self):
self._cmake.definitions["CMAKE_SYSTEM_PROCESSOR"] = \
str(self.settings.arch)
self._cmake.configure()
return self._cmake
# Disable tools, extras and third_party
save(self, os.path.join(self.source_folder, "tools", "CMakeLists.txt"), "")
save(self, os.path.join(self.source_folder, "lib", "jxl_extras.cmake"), "")
save(self, os.path.join(self.source_folder, "third_party", "CMakeLists.txt"), "")
# FindAtomics.cmake values are set by CMakeToolchain instead
save(self, os.path.join(self.source_folder, "cmake", "FindAtomics.cmake"), "")

# Allow fPIC to be set by Conan
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)", "")
for cmake_file in ["jxl.cmake", "jxl_threads.cmake", "jxl_cms.cmake", "jpegli.cmake"]:
path = os.path.join(self.source_folder, "lib", cmake_file)
if os.path.exists(path):
fpic = "ON" if self.options.get_safe("fPIC", True) else "OFF"
replace_in_file(self, path, "POSITION_INDEPENDENT_CODE ON", f"POSITION_INDEPENDENT_CODE {fpic}")

if Version(self.version) < "0.7":
replace_in_file(self, os.path.join(self.source_folder, "lib", "jxl.cmake"),
" DESTINATION ${CMAKE_INSTALL_LIBDIR}",
" RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib")
if self.settings.compiler not in ["gcc", "clang"]:
replace_in_file(self, os.path.join(self.source_folder, "lib", "jxl.cmake"),
"-Wl,--exclude-libs=ALL", "")

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

def package(self):
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.install()

self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))

copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
if self.options.shared:
libs_dir = os.path.join(self.package_folder, "lib")
tools.remove_files_by_mask(libs_dir, "*.a")
tools.remove_files_by_mask(libs_dir, "*-static.lib")

if self.settings.os == "Windows":
self.copy("jxl_dec.dll", src="bin", dst="bin")
self.copy("jxl_dec.lib", src="lib", dst="lib")
for dll_path in glob.glob(os.path.join(libs_dir, "*.dll")):
shutil.move(dll_path, os.path.join(self.package_folder,
"bin", os.path.basename(dll_path)))
else:
self.copy("libjxl_dec.*", src="lib", dst="lib")
rm(self, "*.a", os.path.join(self.package_folder, "lib"))
rm(self, "*-static.lib", os.path.join(self.package_folder, "lib"))

def _lib_name(self, name):
if not self.options.shared and self.settings.os == "Windows":
if Version(self.version) < "0.9" and not self.options.shared and self.settings.os == "Windows":
return name + "-static"
return name

def package_info(self):
libcxx = stdcpp_library(self)

# jxl
self.cpp_info.components["jxl"].names["pkg_config"] = "libjxl"
self.cpp_info.components["jxl"].set_property("pkg_config_name", "libjxl")
self.cpp_info.components["jxl"].libs = [self._lib_name("jxl")]
self.cpp_info.components["jxl"].requires = ["brotli::brotli",
"highway::highway",
"lcms::lcms"]
self.cpp_info.components["jxl"].requires = ["brotli::brotli", "highway::highway", "lcms::lcms"]
if self.options.with_tcmalloc:
self.cpp_info.components["jxl"].requires.append("gperftools::tcmalloc_minimal")
if self._atomic_required:
self.cpp_info.components["jxl"].system_libs.append("atomic")
if not self.options.shared:
self.cpp_info.components["jxl"].defines.append("JXL_STATIC_DEFINE")
if libcxx:
self.cpp_info.components["jxl"].system_libs.append(libcxx)

# jxl_cms
if Version(self.version) >= "0.9.0":
self.cpp_info.components["jxl_cms"].set_property("pkg_config_name", "libjxl_cms")
self.cpp_info.components["jxl_cms"].libs = [self._lib_name("jxl_cms")]
self.cpp_info.components["jxl_cms"].requires = ["lcms::lcms", "highway::highway"]
if not self.options.shared:
self.cpp_info.components["jxl"].defines.append("JXL_CMS_STATIC_DEFINE")
if libcxx:
self.cpp_info.components["jxl_cms"].system_libs.append(libcxx)

# jxl_dec
self.cpp_info.components["jxl_dec"].names["pkg_config"] = "libjxl_dec"
self.cpp_info.components["jxl_dec"].libs = [self._lib_name("jxl_dec")]
self.cpp_info.components["jxl_dec"].requires = ["brotli::brotli",
"highway::highway",
"lcms::lcms"]
if Version(self.version) < "0.9.0":
if not self.options.shared:
self.cpp_info.components["jxl_dec"].set_property("pkg_config_name", "libjxl_dec")
self.cpp_info.components["jxl_dec"].libs = [self._lib_name("jxl_dec")]
self.cpp_info.components["jxl_dec"].requires = ["brotli::brotli", "highway::highway", "lcms::lcms"]
if libcxx:
self.cpp_info.components["jxl_dec"].system_libs.append(libcxx)

# jxl_threads
self.cpp_info.components["jxl_threads"].names["pkg_config"] = \
"libjxl_threads"
self.cpp_info.components["jxl_threads"].libs = \
[self._lib_name("jxl_threads")]
if self.settings.os == "Linux":
self.cpp_info.components["jxl_threads"].set_property("pkg_config_name", "libjxl_threads")
self.cpp_info.components["jxl_threads"].libs = [self._lib_name("jxl_threads")]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["jxl_threads"].system_libs = ["pthread"]

if not self.options.shared and tools.stdcpp_library(self):
self.cpp_info.components["jxl"].system_libs.append(
tools.stdcpp_library(self))
self.cpp_info.components["jxl_dec"].system_libs.append(
tools.stdcpp_library(self))
self.cpp_info.components["jxl_threads"].system_libs.append(
tools.stdcpp_library(self))
if not self.options.shared:
self.cpp_info.components["jxl_threads"].defines.append("JXL_THREADS_STATIC_DEFINE")
if libcxx:
self.cpp_info.components["jxl_threads"].system_libs.append(libcxx)
Loading
Loading