Skip to content

Commit

Permalink
(conan-io#14871) [sail] Bump to 0.9.0-rc2, migrate to Conan V2
Browse files Browse the repository at this point in the history
* Added libjpeg-turbo option

* Use SAIL_ENABLE_CODECS

* [sail] Update to 0.9.0-rc1

* [sail] Fix linter errors

* [sail] Migrate to new CMake

* [sail] Use apply_conandata_patches

* [sail] Update libwebp 1.2.2 -> 1.2.3

* [sail] Fix libjpeg-turbo target name

* [sail] Remove unused imports

* [sail] Refactor libjpeg-turbo usage

* [sail] Added missing self

* [sail] Use copy from CMake tools

* [sail] Remove root CMakeLists and generators

* [sail] Update avif rc1 patch

* [sail] Remove CONFIG

* [sail] Disable pre23 for testing

* [sail] Disable AVIF for testing

* Workaroud Windows SDK bug

* Update to RC2

* Bump versions

* Remove pre23 patch

* V1 test suite

* Update RC1 to RC2 in config.yml

* Added missing CMakeDeps

* Enable AVIF

* Update recipes/sail/all/conanfile.py

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Update recipes/sail/all/conanfile.py

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Update recipes/sail/all/conanfile.py

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Update recipes/sail/all/test_v1_package/CMakeLists.txt

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Use self.options.rm_safe("fPIC")

* Fix typo

* Delete test_package.c

* Delete test_package.cpp

* Try workaround for check_c_source_compiles

* Test

* Try workaround for check_c_source_compiles for Windows only

* Use str()

* Update libavif version

Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
2 people authored and StellaSmith committed Feb 2, 2023
1 parent 13a65b1 commit e347e82
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 99 deletions.
7 changes: 0 additions & 7 deletions recipes/sail/all/CMakeLists.txt

This file was deleted.

13 changes: 7 additions & 6 deletions recipes/sail/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
sources:
"0.9.0-pre23":
url: "https://github.com/smoked-herring/sail/archive/v0.9.0-pre23.tar.gz"
sha256: "6c5314561fda3d388b4653e7424cdf2ae2c65767e79203576804ca41fc930a6b"
"0.9.0-rc2":
url: "https://github.com/smoked-herring/sail/archive/v0.9.0-rc2.tar.gz"
sha256: "988d318fd4cfbc77ccbda49f4ac751d1998b990db157aef32b0dbd32d11f8fd6"
patches:
"0.9.0-pre23":
- patch_file: "patches/0.9.0-pre23-avif-find-package.patch"
base_path: "src"
"0.9.0-rc2":
- patch_file: "patches/0.9.0-rc2-avif-find-package.patch"
patch_type: "conan"
patch_description: "Make the AVIF codec use find_package()"
139 changes: 72 additions & 67 deletions recipes/sail/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from conan.tools.files import rename
from conans import ConanFile, CMake, tools
import functools
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, export_conandata_patches, copy, get, rename, rmdir
from conan.tools.microsoft import is_msvc
import os

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.53.0"

class SAILConan(ConanFile):
name = "sail"
Expand All @@ -20,7 +21,7 @@ class SAILConan(ConanFile):
"with_avif": [True, False],
"with_gif": [True, False],
"with_jpeg2000": [True, False],
"with_jpeg": [True, False],
"with_jpeg": ["libjpeg", "libjpeg-turbo", False],
"with_png": [True, False],
"with_tiff": [True, False],
"with_webp": [True, False],
Expand All @@ -32,101 +33,105 @@ class SAILConan(ConanFile):
"with_avif": True,
"with_gif": True,
"with_jpeg2000": True,
"with_jpeg": True,
"with_jpeg": "libjpeg",
"with_png": True,
"with_tiff": True,
"with_webp": True,
}
generators = "cmake", "cmake_find_package", "cmake_find_package_multi"

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

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

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":
del self.options.fPIC
self.options.rm_safe("fPIC")

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

def requirements(self):
if self.options.with_avif:
self.requires("libavif/0.9.3")
self.requires("libavif/0.11.1")
if self.options.with_gif:
self.requires("giflib/5.2.1")
if self.options.with_jpeg2000:
self.requires("jasper/2.0.33")
if self.options.with_jpeg:
self.requires("libjpeg/9d")
if self.options.with_jpeg == "libjpeg-turbo":
self.requires("libjpeg-turbo/2.1.4")
elif self.options.with_jpeg == "libjpeg":
self.requires("libjpeg/9e")
if self.options.with_png:
self.requires("libpng/1.6.37")
self.requires("libpng/1.6.39")
if self.options.with_tiff:
self.requires("libtiff/4.3.0")
self.requires("libtiff/4.4.0")
if self.options.with_webp:
self.requires("libwebp/1.2.2")
self.requires("libwebp/1.2.4")

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

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

@functools.lru_cache(1)
def _configure_cmake(self):
except_codecs = []

if not self.options.with_avif:
except_codecs.append("AVIF")
if not self.options.with_gif:
except_codecs.append("GIF")
if not self.options.with_jpeg2000:
except_codecs.append("JPEG2000")
if not self.options.with_jpeg:
except_codecs.append("JPEG")
if not self.options.with_png:
except_codecs.append("PNG")
if not self.options.with_tiff:
except_codecs.append("TIFF")
if not self.options.with_webp:
except_codecs.append("WEBP")
get(self, **self.conan_data["sources"][self.version],
strip_root=True, destination=self.source_folder)

cmake = CMake(self)
cmake.definitions["SAIL_BUILD_APPS"] = False
cmake.definitions["SAIL_BUILD_EXAMPLES"] = False
cmake.definitions["SAIL_BUILD_TESTS"] = False
cmake.definitions["SAIL_COMBINE_CODECS"] = True
cmake.definitions["SAIL_EXCEPT_CODECS"] = ";".join(except_codecs)
cmake.definitions["SAIL_INSTALL_PDB"] = False
cmake.definitions["SAIL_THREAD_SAFE"] = self.options.thread_safe
cmake.configure(build_folder=self._build_subfolder)
def generate(self):
enable_codecs = []

return cmake
if self.options.with_avif:
enable_codecs.append("avif")
if self.options.with_gif:
enable_codecs.append("gif")
if self.options.with_jpeg2000:
enable_codecs.append("jpeg2000")
if self.options.with_jpeg:
enable_codecs.append("jpeg")
if self.options.with_png:
enable_codecs.append("png")
if self.options.with_tiff:
enable_codecs.append("tiff")
if self.options.with_webp:
enable_codecs.append("webp")

tc = CMakeToolchain(self)
tc.variables["SAIL_BUILD_APPS"] = False
tc.variables["SAIL_BUILD_EXAMPLES"] = False
tc.variables["SAIL_BUILD_TESTS"] = False
tc.variables["SAIL_COMBINE_CODECS"] = True
tc.variables["SAIL_ENABLE_CODECS"] = ";".join(enable_codecs)
tc.variables["SAIL_INSTALL_PDB"] = False
tc.variables["SAIL_THREAD_SAFE"] = self.options.thread_safe
# TODO: Remove after fixing https://github.com/conan-io/conan/issues/12012
if is_msvc(self):
tc.cache_variables["CMAKE_TRY_COMPILE_CONFIGURATION"] = str(self.settings.build_type)
# TODO: Remove after fixing https://github.com/conan-io/conan-center-index/issues/13159
# C3I workaround to force CMake to choose the highest version of
# the windows SDK available in the system
if is_msvc(self) and not self.conf.get("tools.cmake.cmaketoolchain:system_version"):
tc.variables["CMAKE_SYSTEM_VERSION"] = "10.0"
tc.generate()

deps = CMakeDeps(self)
deps.generate()

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

cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE.txt", src=self._source_subfolder, dst="licenses")
self.copy("LICENSE.INIH.txt", src=self._source_subfolder, dst="licenses")
self.copy("LICENSE.MUNIT.txt", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
copy(self, "LICENSE.txt", self.source_folder, os.path.join(self.package_folder, "licenses"))
copy(self, "LICENSE.INIH.txt", self.source_folder, os.path.join(self.package_folder, "licenses"))
copy(self, "LICENSE.MUNIT.txt", self.source_folder, os.path.join(self.package_folder, "licenses"))

cmake = CMake(self)
cmake.install()

# Remove CMake and pkg-config rules
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
# Move icons
rename(self, os.path.join(self.package_folder, "share"),
os.path.join(self.package_folder, "res"))
Expand Down Expand Up @@ -158,7 +163,7 @@ def package_info(self):
if self.options.with_jpeg2000:
self.cpp_info.components["sail-codecs"].requires.append("jasper::jasper")
if self.options.with_jpeg:
self.cpp_info.components["sail-codecs"].requires.append("libjpeg::libjpeg")
self.cpp_info.components["sail-codecs"].requires.append("{0}::{0}".format(self.options.with_jpeg))
if self.options.with_png:
self.cpp_info.components["sail-codecs"].requires.append("libpng::libpng")
if self.options.with_tiff:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
diff --git a/src/sail-codecs/avif/CMakeLists.txt b/src/sail-codecs/avif/CMakeLists.txt
index 870de541..1fe5a7e7 100644
index 3f36e0c8..1e31be83 100644
--- a/src/sail-codecs/avif/CMakeLists.txt
+++ b/src/sail-codecs/avif/CMakeLists.txt
@@ -1,7 +1,6 @@
-find_library(AVIF_LIBRARY avif)
-find_path(AVIF_INCLUDE_DIRS avif/avif.h)
+find_package(libavif CONFIG)
-find_library(AVIF_LIBRARY avif ${SAIL_CODEC_AVIF_REQUIRED_OPTION})
-find_path(AVIF_INCLUDE_DIRS avif/avif.h ${SAIL_CODEC_AVIF_REQUIRED_OPTION})
+find_package(libavif ${SAIL_CODEC_AVIF_REQUIRED_OPTION})

-if (NOT AVIF_LIBRARY OR NOT AVIF_INCLUDE_DIRS)
+if (NOT libavif_FOUND)
Expand Down
7 changes: 2 additions & 5 deletions recipes/sail/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(Sail REQUIRED CONFIG)

# C API
add_executable(test_package_c test_package.c)
target_compile_definitions(test_package_c PRIVATE SAIL_DEMO_FILE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/png.png")
target_compile_definitions(test_package_c PRIVATE SAIL_DEMO_FILE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/bmp.bmp")
target_link_libraries(test_package_c PRIVATE SAIL::Sail)

# C++ API
add_executable(test_package_cxx test_package.cpp)
target_compile_definitions(test_package_cxx PRIVATE SAIL_DEMO_FILE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/png.png")
target_compile_definitions(test_package_cxx PRIVATE SAIL_DEMO_FILE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/bmp.bmp")
target_link_libraries(test_package_cxx PRIVATE SAIL::SailC++)
Binary file added recipes/sail/all/test_package/bmp.bmp
Binary file not shown.
24 changes: 16 additions & 8 deletions recipes/sail/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os

from conans import ConanFile, CMake, tools

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package", "cmake_find_package_multi"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package_c")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package_c")
self.run(bin_path, env="conanrun")

bin_path = os.path.join("bin", "test_package_cxx")
self.run(bin_path, run_environment=True)
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package_cxx")
self.run(bin_path, env="conanrun")
Binary file removed recipes/sail/all/test_package/png.png
Binary file not shown.
2 changes: 1 addition & 1 deletion recipes/sail/all/test_package/test_package.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main(int argc, char *argv[])

struct sail_image *image;

SAIL_TRY_OR_EXECUTE(sail_load_image_from_file(SAIL_DEMO_FILE_PATH, &image),
SAIL_TRY_OR_EXECUTE(sail_load_from_file(SAIL_DEMO_FILE_PATH, &image),
/* on error */ return 1);

printf("Size: %ux%u, bytes per line: %u, "
Expand Down
8 changes: 8 additions & 0 deletions recipes/sail/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
Binary file added recipes/sail/all/test_v1_package/bmp.bmp
Binary file not shown.
20 changes: 20 additions & 0 deletions recipes/sail/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os

from conans import ConanFile, CMake, tools

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package", "cmake_find_package_multi"

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package_c")
self.run(bin_path, run_environment=True)

bin_path = os.path.join("bin", "test_package_cxx")
self.run(bin_path, run_environment=True)
2 changes: 1 addition & 1 deletion recipes/sail/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
versions:
"0.9.0-pre23":
"0.9.0-rc2":
folder: all

0 comments on commit e347e82

Please sign in to comment.