[DO-976] libpng recipe (!5)
Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech> Reviewed-on: https://git.avroid.tech/Conan/conan_build/pulls/5
This commit is contained in:
7
recipes/libpng/all/conan_cmake_project_include.cmake
Normal file
7
recipes/libpng/all/conan_cmake_project_include.cmake
Normal file
@@ -0,0 +1,7 @@
|
||||
# Older versions of libpng's CMakeLists reference the ZLIB_LIBRARy
|
||||
# varible which was never officially documented.
|
||||
# This was fixed in which first went into version 1.6.38.
|
||||
# This can be deleted once the recipe no longer supports versions older than that.
|
||||
# https://github.com/glennrp/libpng/commit/9f734b13f4ea062af98652c4c7678f667d2d85c7
|
||||
find_package(ZLIB CONFIG REQUIRED)
|
||||
set(ZLIB_LIBRARY "${ZLIB_LIBRARIES}")
|
||||
31
recipes/libpng/all/conandata.yml
Normal file
31
recipes/libpng/all/conandata.yml
Normal file
@@ -0,0 +1,31 @@
|
||||
sources:
|
||||
"1.6.44":
|
||||
url: "https://nexus.avroid.tech/repository/all-raw-proxy-sourceforge_net/projects/libpng/files/libpng16/1.6.44/libpng-1.6.44.tar.xz"
|
||||
sha256: "60c4da1d5b7f0aa8d158da48e8f8afa9773c1c8baa5d21974df61f1886b8ce8e"
|
||||
"1.6.43":
|
||||
url: "https://nexus.avroid.tech/repository/all-raw-proxy-sourceforge_net/projects/libpng/files/libpng16/1.6.43/libpng-1.6.43.tar.xz"
|
||||
sha256: "6a5ca0652392a2d7c9db2ae5b40210843c0bbc081cbd410825ab00cc59f14a6c"
|
||||
"1.6.42":
|
||||
url: "https://nexus.avroid.tech/repository/all-raw-proxy-sourceforge_net/projects/libpng/files/libpng16/1.6.42/libpng-1.6.42.tar.xz"
|
||||
sha256: "c919dbc11f4c03b05aba3f8884d8eb7adfe3572ad228af972bb60057bdb48450"
|
||||
"1.6.41":
|
||||
url: "https://nexus.avroid.tech/repository/all-raw-proxy-sourceforge_net/projects/libpng/files/libpng16/1.6.41/libpng-1.6.41.tar.xz"
|
||||
sha256: "d6a49a7a4abca7e44f72542030e53319c081fea508daccf4ecc7c6d9958d190f"
|
||||
"1.6.40":
|
||||
url: "https://nexus.avroid.tech/repository/all-raw-proxy-sourceforge_net/projects/libpng/files/libpng16/1.6.40/libpng-1.6.40.tar.xz"
|
||||
sha256: "535b479b2467ff231a3ec6d92a525906fb8ef27978be4f66dbe05d3f3a01b3a1"
|
||||
"1.6.39":
|
||||
url: "https://nexus.avroid.tech/repository/all-raw-proxy-sourceforge_net/projects/libpng/files/libpng16/1.6.39/libpng-1.6.39.tar.xz"
|
||||
sha256: "1f4696ce70b4ee5f85f1e1623dc1229b210029fa4b7aee573df3e2ba7b036937"
|
||||
"1.6.38":
|
||||
url: "https://nexus.avroid.tech/repository/all-raw-proxy-sourceforge_net/projects/libpng/files/libpng16/1.6.38/libpng-1.6.38.tar.xz"
|
||||
sha256: "b3683e8b8111ebf6f1ac004ebb6b0c975cd310ec469d98364388e9cedbfa68be"
|
||||
"1.6.37":
|
||||
url: "https://nexus.avroid.tech/repository/all-raw-proxy-sourceforge_net/projects/libpng/files/libpng16/1.6.37/libpng-1.6.37.tar.xz"
|
||||
sha256: "505e70834d35383537b6491e7ae8641f1a4bed1876dbfe361201fc80868d88ca"
|
||||
"1.6.32":
|
||||
url: "https://nexus.avroid.tech/repository/all-raw-proxy-sourceforge_net/projects/libpng/files/libpng16/older-releases/1.6.32/libpng-1.6.32.tar.xz"
|
||||
sha256: "c918c3113de74a692f0a1526ce881dc26067763eb3915c57ef3a0f7b6886f59b"
|
||||
"1.5.30":
|
||||
url: "https://nexus.avroid.tech/repository/all-raw-proxy-sourceforge_net/projects/libpng/files/libpng15/1.5.30/libpng-1.5.30.tar.xz"
|
||||
sha256: "7d76275fad2ede4b7d87c5fd46e6f488d2a16b5a69dc968ffa840ab39ba756ed"
|
||||
174
recipes/libpng/all/conanfile.py
Normal file
174
recipes/libpng/all/conanfile.py
Normal file
@@ -0,0 +1,174 @@
|
||||
from conan import ConanFile
|
||||
from conan.errors import ConanInvalidConfiguration
|
||||
from conan.tools.apple import is_apple_os
|
||||
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
|
||||
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir
|
||||
from conan.tools.microsoft import is_msvc
|
||||
from conan.tools.scm import Version
|
||||
import os
|
||||
|
||||
required_conan_version = ">=1.53.0"
|
||||
|
||||
|
||||
class LibpngConan(ConanFile):
|
||||
name = "libpng"
|
||||
description = "libpng is the official PNG file format reference library."
|
||||
url = "https://github.com/conan-io/conan-center-index"
|
||||
homepage = "http://www.libpng.org"
|
||||
license = "libpng-2.0"
|
||||
topics = ("png", "graphics", "image")
|
||||
settings = "os", "arch", "compiler", "build_type"
|
||||
options = {
|
||||
"shared": [True, False],
|
||||
"fPIC": [True, False],
|
||||
"neon": [True, "check", False],
|
||||
"msa": [True, False],
|
||||
"sse": [True, False],
|
||||
"vsx": [True, False],
|
||||
"api_prefix": ["ANY"],
|
||||
}
|
||||
default_options = {
|
||||
"shared": False,
|
||||
"fPIC": True,
|
||||
"neon": True,
|
||||
"msa": True,
|
||||
"sse": True,
|
||||
"vsx": True,
|
||||
"api_prefix": "",
|
||||
}
|
||||
|
||||
@property
|
||||
def _is_clang_cl(self):
|
||||
return self.settings.os == "Windows" and self.settings.compiler == "clang" and \
|
||||
self.settings.compiler.get_safe("runtime")
|
||||
|
||||
@property
|
||||
def _has_neon_support(self):
|
||||
return "arm" in self.settings.arch
|
||||
|
||||
@property
|
||||
def _has_msa_support(self):
|
||||
return "mips" in self.settings.arch
|
||||
|
||||
@property
|
||||
def _has_sse_support(self):
|
||||
return self.settings.arch in ["x86", "x86_64"]
|
||||
|
||||
@property
|
||||
def _has_vsx_support(self):
|
||||
return "ppc" in self.settings.arch
|
||||
|
||||
@property
|
||||
def _neon_msa_sse_vsx_mapping(self):
|
||||
return {
|
||||
"True": "on",
|
||||
"False": "off",
|
||||
"check": "check",
|
||||
}
|
||||
|
||||
def export_sources(self):
|
||||
export_conandata_patches(self)
|
||||
copy(self, "conan_cmake_project_include.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 not self._has_neon_support:
|
||||
del self.options.neon
|
||||
if not self._has_msa_support:
|
||||
del self.options.msa
|
||||
if not self._has_sse_support:
|
||||
del self.options.sse
|
||||
if not self._has_vsx_support:
|
||||
del self.options.vsx
|
||||
|
||||
def configure(self):
|
||||
if self.options.shared:
|
||||
self.options.rm_safe("fPIC")
|
||||
self.settings.rm_safe("compiler.libcxx")
|
||||
self.settings.rm_safe("compiler.cppstd")
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self, src_folder="src")
|
||||
|
||||
def requirements(self):
|
||||
self.requires("zlib/[>=1.2.11 <2]")
|
||||
|
||||
def validate(self):
|
||||
if Version(self.version) < "1.6" and self.settings.arch == "armv8" and is_apple_os(self):
|
||||
raise ConanInvalidConfiguration(f"{self.ref} currently does not building for {self.settings.os} {self.settings.arch}. Contributions are welcomed")
|
||||
|
||||
def source(self):
|
||||
get(self, **self.conan_data["sources"][self.version], strip_root=True)
|
||||
|
||||
def generate(self):
|
||||
tc = CMakeToolchain(self)
|
||||
tc.cache_variables["PNG_TESTS"] = False
|
||||
tc.cache_variables["PNG_SHARED"] = self.options.shared
|
||||
tc.cache_variables["PNG_STATIC"] = not self.options.shared
|
||||
tc.cache_variables["PNG_DEBUG"] = self.settings.build_type == "Debug"
|
||||
tc.cache_variables["PNG_PREFIX"] = self.options.api_prefix
|
||||
if Version(self.version) < "1.6.38":
|
||||
tc.cache_variables["CMAKE_PROJECT_libpng_INCLUDE"] = os.path.join(self.source_folder, "conan_cmake_project_include.cmake")
|
||||
if self._has_neon_support:
|
||||
tc.variables["PNG_ARM_NEON"] = self._neon_msa_sse_vsx_mapping[str(self.options.neon)]
|
||||
if self._has_msa_support:
|
||||
tc.variables["PNG_MIPS_MSA"] = self._neon_msa_sse_vsx_mapping[str(self.options.msa)]
|
||||
if self._has_sse_support:
|
||||
tc.variables["PNG_INTEL_SSE"] = self._neon_msa_sse_vsx_mapping[str(self.options.sse)]
|
||||
if self._has_vsx_support:
|
||||
tc.variables["PNG_POWERPC_VSX"] = self._neon_msa_sse_vsx_mapping[str(self.options.vsx)]
|
||||
if Version(self.version) >= "1.6.41":
|
||||
tc.variables["PNG_FRAMEWORK"] = False # changed from False to True by default in PNG 1.6.41
|
||||
tc.variables["PNG_TOOLS"] = False
|
||||
elif Version(self.version) >= "1.6.38":
|
||||
tc.variables["PNG_EXECUTABLES"] = False
|
||||
|
||||
tc.cache_variables["CMAKE_MACOSX_BUNDLE"] = False
|
||||
tc.generate()
|
||||
tc = CMakeDeps(self)
|
||||
tc.generate()
|
||||
|
||||
def _patch_sources(self):
|
||||
apply_conandata_patches(self)
|
||||
|
||||
def build(self):
|
||||
self._patch_sources()
|
||||
cmake = CMake(self)
|
||||
cmake.configure()
|
||||
cmake.build()
|
||||
|
||||
def package(self):
|
||||
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
|
||||
cmake = CMake(self)
|
||||
cmake.install()
|
||||
if self.options.shared:
|
||||
rm(self, "*[!.dll]", os.path.join(self.package_folder, "bin"))
|
||||
else:
|
||||
rmdir(self, os.path.join(self.package_folder, "bin"))
|
||||
rmdir(self, os.path.join(self.package_folder, "lib", "libpng"))
|
||||
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
|
||||
rmdir(self, os.path.join(self.package_folder, "share"))
|
||||
rm(self, "*.cmake", os.path.join(self.package_folder, "lib", "cmake", "PNG"))
|
||||
|
||||
def package_info(self):
|
||||
major_min_version = f"{Version(self.version).major}{Version(self.version).minor}"
|
||||
|
||||
self.cpp_info.set_property("cmake_find_mode", "both")
|
||||
self.cpp_info.set_property("cmake_file_name", "PNG")
|
||||
self.cpp_info.set_property("cmake_target_name", "PNG::PNG")
|
||||
self.cpp_info.set_property("pkg_config_name", "libpng")
|
||||
self.cpp_info.set_property("pkg_config_aliases", [f"libpng{major_min_version}"])
|
||||
|
||||
prefix = "lib" if (is_msvc(self) or self._is_clang_cl) else ""
|
||||
suffix = major_min_version if self.settings.os == "Windows" else ""
|
||||
if is_msvc(self) or self._is_clang_cl:
|
||||
suffix += "_static" if not self.options.shared else ""
|
||||
suffix += "d" if self.settings.os == "Windows" and self.settings.build_type == "Debug" else ""
|
||||
self.cpp_info.libs = [f"{prefix}png{suffix}"]
|
||||
if self.settings.os in ["Linux", "Android", "FreeBSD", "SunOS", "AIX"]:
|
||||
self.cpp_info.system_libs.append("m")
|
||||
|
||||
# TODO: Remove after Conan 2.0
|
||||
self.cpp_info.names["cmake_find_package"] = "PNG"
|
||||
self.cpp_info.names["cmake_find_package_multi"] = "PNG"
|
||||
7
recipes/libpng/all/test_package/CMakeLists.txt
Normal file
7
recipes/libpng/all/test_package/CMakeLists.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(test_package LANGUAGES C)
|
||||
|
||||
find_package(PNG REQUIRED)
|
||||
|
||||
add_executable(${PROJECT_NAME} test_package.c)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE PNG::PNG)
|
||||
26
recipes/libpng/all/test_package/conanfile.py
Normal file
26
recipes/libpng/all/test_package/conanfile.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from conan import ConanFile
|
||||
from conan.tools.build import can_run
|
||||
from conan.tools.cmake import CMake, cmake_layout
|
||||
import os
|
||||
|
||||
|
||||
class TestPackageConan(ConanFile):
|
||||
settings = "os", "arch", "compiler", "build_type"
|
||||
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
|
||||
test_type = "explicit"
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self)
|
||||
|
||||
def requirements(self):
|
||||
self.requires(self.tested_reference_str)
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
cmake.configure()
|
||||
cmake.build()
|
||||
|
||||
def test(self):
|
||||
if can_run(self):
|
||||
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
|
||||
self.run(bin_path, env="conanrun")
|
||||
16
recipes/libpng/all/test_package/test_package.c
Normal file
16
recipes/libpng/all/test_package/test_package.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "png.h"
|
||||
|
||||
|
||||
int main(void) {
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
|
||||
fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n", PNG_LIBPNG_VER_STRING, png_libpng_ver);
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
8
recipes/libpng/all/test_v1_package/CMakeLists.txt
Normal file
8
recipes/libpng/all/test_v1_package/CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(test_package)
|
||||
|
||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||
conan_basic_setup(TARGETS)
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
|
||||
${CMAKE_CURRENT_BINARY_DIR}/test_package)
|
||||
17
recipes/libpng/all/test_v1_package/conanfile.py
Normal file
17
recipes/libpng/all/test_v1_package/conanfile.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from conans import ConanFile, CMake, tools
|
||||
import os
|
||||
|
||||
|
||||
class TestPackageConan(ConanFile):
|
||||
settings = "os", "arch", "compiler", "build_type"
|
||||
generators = "cmake", "cmake_find_package"
|
||||
|
||||
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")
|
||||
self.run(bin_path, run_environment=True)
|
||||
21
recipes/libpng/config.yml
Normal file
21
recipes/libpng/config.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
versions:
|
||||
"1.6.44":
|
||||
folder: all
|
||||
"1.6.43":
|
||||
folder: all
|
||||
"1.6.42":
|
||||
folder: all
|
||||
"1.6.41":
|
||||
folder: all
|
||||
"1.6.40":
|
||||
folder: all
|
||||
"1.6.39":
|
||||
folder: all
|
||||
"1.6.38":
|
||||
folder: all
|
||||
"1.6.37":
|
||||
folder: all
|
||||
"1.6.32":
|
||||
folder: all
|
||||
"1.5.30":
|
||||
folder: all
|
||||
Reference in New Issue
Block a user