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

ktx: add v4.3.2 #22312

Merged
merged 7 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 10 additions & 4 deletions recipes/ktx/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
sources:
"4.3.2":
url: "https://github.com/KhronosGroup/KTX-Software/archive/refs/tags/v4.3.2.tar.gz"
sha256: "74a114f465442832152e955a2094274b446c7b2427c77b1964c85c173a52ea1f"
"4.0.0":
url: "https://github.com/KhronosGroup/KTX-Software/archive/refs/tags/v4.0.0.tar.gz"
sha256: "6091f5064d0cfd54c6155bb6c0d2ba7287f312d109010e9b702839ac78529fd3"
patches:
"4.3.2":
- patch_file: "patches/4.3.2/0001-objutil-cxx-std.patch"

Check warning on line 10 in recipes/ktx/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/4.3.2/00 ... ^ (line: 10)
- patch_file: "patches/4.3.2/0004-unvendor-dependencies.patch"

Check warning on line 11 in recipes/ktx/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/4.3.2/00 ... ^ (line: 11)
"4.0.0":
- patch_file: "patches/0001-objutil-cxx-std.patch"
- patch_file: "patches/0002-lodepng-no-export-symbols.patch"
- patch_file: "patches/0003-clamp-include-algorithm.patch"
- patch_file: "patches/0004-unvendor-dependencies.patch"
- patch_file: "patches/4.0.0/0001-objutil-cxx-std.patch"

Check warning on line 13 in recipes/ktx/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/4.0.0/00 ... ^ (line: 13)
- patch_file: "patches/4.0.0/0002-lodepng-no-export-symbols.patch"

Check warning on line 14 in recipes/ktx/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/4.0.0/00 ... ^ (line: 14)
- patch_file: "patches/4.0.0/0003-clamp-include-algorithm.patch"

Check warning on line 15 in recipes/ktx/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/4.0.0/00 ... ^ (line: 15)
- patch_file: "patches/4.0.0/0004-unvendor-dependencies.patch"

Check warning on line 16 in recipes/ktx/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/4.0.0/00 ... ^ (line: 16)
58 changes: 51 additions & 7 deletions recipes/ktx/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd, stdcpp_library
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir, replace_in_file, save
from conan.tools.scm import Version
import os

required_conan_version = ">=1.53.0"
Expand Down Expand Up @@ -29,6 +31,25 @@ class KtxConan(ConanFile):
"tools": True,
}

@property
def _min_cppstd(self):
if Version(self.version) < "4.3.2":
return 11
return 17

@property
def _compilers_minimum_version(self):
if self._min_cppstd == 17:
return {
"gcc": "8",
"clang": "7",
"apple-clang": "10",
"msvc": "191",
"Visual Studio": "15",
}
return {}


@property
def _has_sse_support(self):
return self.settings.arch in ["x86", "x86_64"]
Expand All @@ -53,15 +74,30 @@ def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("lodepng/cci.20230410")
if Version(self.version) < "4.2.0":
# Newer versions use modified lodepng
# https://github.com/KhronosGroup/KTX-Software/blob/v4.2.1/tools/imageio/png.imageio/lodepng.h#L26-L32
self.requires("lodepng/cci.20230410")
self.requires("zstd/1.5.5")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)
check_min_cppstd(self, self._min_cppstd)
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 C++{self._min_cppstd}, which your compiler does not support."
)
if Version(self.version) >= "4.2" and self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < 6:
# astcenc_vecmathlib_sse_4.h:809:41: error: the last argument must be a 4-bit immediate
raise ConanInvalidConfiguration("GCC v6+ is required")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
# Avoid copying of 300 MB of test assets and third-party binaries
rmdir(self, os.path.join(self.source_folder, "tests"))
rmdir(self, os.path.join(self.source_folder, "other_lib"))
save(self, os.path.join(self.source_folder, "tests", "CMakeLists.txt"), "")

def generate(self):
tc = CMakeToolchain(self)
Expand All @@ -73,18 +109,24 @@ def generate(self):
tc.variables["BASISU_SUPPORT_SSE"] = self.options.get_safe("sse", False)
tc.generate()
deps = CMakeDeps(self)
deps.set_property("zstd", "cmake_target_name", "zstd::libzstd")
deps.generate()

def _patch_sources(self):
apply_conandata_patches(self)
# Unvendor several libs (we rely on patch files to link those libs)
# It's worth noting that vendored jpeg-compressor can't be replaced by CCI equivalent
basisu_dir = os.path.join(self.source_folder, "lib", "basisu")
## lodepng (the patch file 0002-lodepng-no-export-symbols is important, in order to not try to export lodepng symbols)
os.remove(os.path.join(basisu_dir, "encoder", "lodepng.cpp"))
os.remove(os.path.join(basisu_dir, "encoder", "lodepng.h"))
if Version(self.version) < "4.1.0":
## lodepng (the patch file 0002-lodepng-no-export-symbols is important, in order to not try to export lodepng symbols)
os.remove(os.path.join(basisu_dir, "encoder", "lodepng.cpp"))
os.remove(os.path.join(basisu_dir, "encoder", "lodepng.h"))
## zstd
rmdir(self, os.path.join(basisu_dir, "zstd"))
# disable -Werror
if Version(self.version) >= "4.3.2":
replace_in_file(self, os.path.join(self.source_folder, "lib", "astc-encoder", "Source", "cmake_core.cmake"),
"-Werror", "")

def build(self):
self._patch_sources()
Expand Down Expand Up @@ -125,6 +167,8 @@ def package_info(self):
self.cpp_info.components["libktx"].names["cmake_find_package"] = "ktx"
self.cpp_info.components["libktx"].names["cmake_find_package_multi"] = "ktx"
self.cpp_info.components["libktx"].set_property("cmake_target_name", "KTX::ktx")
self.cpp_info.components["libktx"].requires = ["lodepng::lodepng", "zstd::zstd"]
self.cpp_info.components["libktx"].requires = ["zstd::zstd"]
if Version(self.version) < "4.2.0":
self.cpp_info.components["libktx"].requires.append("lodepng::lodepng")
if self.options.tools:
self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
)
+find_package(lodepng REQUIRED CONFIG)
+find_package(zstd REQUIRED CONFIG)
+target_link_libraries(ktx PRIVATE lodepng::lodepng $<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>)
+target_link_libraries(ktx_read PRIVATE $<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>)
+target_link_libraries(ktx PRIVATE lodepng::lodepng zstd::libzstd)
+target_link_libraries(ktx_read PRIVATE zstd::libzstd)
target_include_directories(
ktx
PRIVATE
Expand All @@ -31,7 +31,7 @@
toktx
ktx
+ lodepng::lodepng
+ $<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>
+ zstd::libzstd
)

target_compile_definitions(
Expand Down
10 changes: 10 additions & 0 deletions recipes/ktx/all/patches/4.3.2/0001-objutil-cxx-std.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -972,6 +972,6 @@
PUBLIC
utils
)
-
+target_compile_features(objUtil PUBLIC cxx_std_11)
# In C++ apps that use statically linked Libraries all compilatiom units must
# be compiled with matching symbol visibility settings to avoid warnings from
21 changes: 21 additions & 0 deletions recipes/ktx/all/patches/4.3.2/0004-unvendor-dependencies.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -355,7 +355,6 @@
lib/basisu/transcoder/basisu_transcoder.cpp
lib/basisu/transcoder/basisu_transcoder.h
lib/basisu/transcoder/basisu.h
- lib/basisu/zstd/zstd.c
lib/checkheader.c
lib/dfdutils/createdfd.c
lib/dfdutils/colourspaces.c
@@ -765,6 +764,10 @@
BASISD_SUPPORT_KTX2=0
)

+find_package(zstd REQUIRED CONFIG)
+target_link_libraries(ktx PUBLIC zstd::libzstd)
+target_link_libraries(ktx_read PUBLIC zstd::libzstd)
+
# Turn off these warnings until Rich fixes the occurences.
# It it not clear to me if generator expressions can be used here
# hence the long-winded way.
2 changes: 2 additions & 0 deletions recipes/ktx/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
versions:
"4.3.2":
folder: all
"4.0.0":
folder: all
Loading