-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* thorvg: add recipe * try to support msvc * update thorvg, update meson * use vs2022 instead of vs backend * update 0.12.9, update meson * update 0.13.0 * Update recipes/thorvg/all/conanfile.py * Update recipes/thorvg/all/conanfile.py * Added some meson options * wip * Added extra definitions in cpp_info * Added several workarounds for Windows * Removing pdb files * Adding m as system libraries --------- Co-authored-by: Francisco Ramírez <franchuti688@gmail.com>
- Loading branch information
1 parent
22cda07
commit 8b46db5
Showing
6 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources: | ||
"0.13.0": | ||
url: "https://github.com/thorvg/thorvg/archive/refs/tags/v0.13.0.tar.gz" | ||
sha256: "4245c401fa637452c8526c0c4448d8c7915f09a6a2e1fa85d6e9032ee610b454" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.apple import fix_apple_shared_install_name | ||
from conan.tools.build import check_min_cppstd | ||
from conan.tools.files import copy, get, rmdir, rename, replace_in_file, rm | ||
from conan.tools.gnu import PkgConfigDeps | ||
from conan.tools.layout import basic_layout | ||
from conan.tools.meson import Meson, MesonToolchain | ||
from conan.tools.scm import Version | ||
from conan.tools.microsoft import is_msvc | ||
from conan.tools.env import VirtualBuildEnv | ||
import os | ||
|
||
|
||
required_conan_version = ">=1.64.0 <2 || >=2.2.0" | ||
|
||
|
||
class ThorvgConan(ConanFile): | ||
name = "thorvg" | ||
description = "ThorVG is a platform-independent portable library that allows for drawing vector-based scenes and animations." | ||
license = "MIT" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/thorvg/thorvg" | ||
topics = ("svg", "animation", "tvg") | ||
package_type = "library" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
"with_engines": ['sw', 'gl_beta', 'wg_beta'], | ||
"with_loaders": [False, 'tvg', 'svg', 'png', 'jpg', 'lottie', 'ttf', 'webp', 'all'], | ||
"with_savers": [False, 'tvg', 'gif', 'all'], | ||
"with_bindings": [False, 'capi', 'wasm_beta'], | ||
"with_tools": [False, 'svg2tvg', 'svg2png', 'lottie2gif', 'all'], | ||
"with_threads": [True, False], | ||
"with_vector": [True, False], | ||
"with_examples": [True, False] | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": True, | ||
"with_engines": 'sw', | ||
"with_loaders": 'all', | ||
"with_savers": False, | ||
"with_bindings": 'capi', | ||
"with_tools": False, | ||
"with_threads": True, | ||
"with_vector": False, | ||
"with_examples": False | ||
} | ||
# See more here: https://github.com/thorvg/thorvg/blob/main/meson_options.txt | ||
options_description = { | ||
"engines": "Enable Rasterizer Engine in thorvg", | ||
"loaders": "Enable File Loaders in thorvg", | ||
"savers": "Enable File Savers in thorvg", | ||
"threads": "Enable the multi-threading task scheduler in thorvg", | ||
"vector": "Enable CPU Vectorization(SIMD) in thorvg", | ||
"bindings": "Enable API bindings", | ||
"tools": "Enable building thorvg tools", | ||
"examples": "Enable building examples", | ||
} | ||
|
||
@property | ||
def _min_cppstd(self): | ||
return 14 | ||
|
||
@property | ||
def _compilers_minimum_version(self): | ||
return { | ||
"gcc": "6", | ||
"clang": "5", | ||
"apple-clang": "10", | ||
"Visual Studio": "15", | ||
"msvc": "191", | ||
} | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
self.options.rm_safe("fPIC") | ||
|
||
def layout(self): | ||
basic_layout(self, src_folder="src") | ||
|
||
def validate(self): | ||
if self.settings.compiler.get_safe("cppstd"): | ||
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." | ||
) | ||
|
||
def build_requirements(self): | ||
self.tool_requires("meson/1.4.0") | ||
if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str): | ||
self.tool_requires("pkgconf/2.1.0") | ||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
def generate(self): | ||
tc = MesonToolchain(self, backend=("vs" if is_msvc(self) else None)) | ||
is_debug = self.settings.get_safe("build_type") == "Debug" | ||
tc.project_options.update({ | ||
"engines": str(self.options.with_engines), | ||
"loaders": str(self.options.with_loaders) if self.options.with_loaders else '', | ||
"savers": str(self.options.with_savers) if self.options.with_savers else '', | ||
"bindings": str(self.options.with_bindings) if self.options.with_bindings else '', | ||
"tools": str(self.options.with_tools )if self.options.with_tools else '', | ||
"threads": bool(self.options.with_threads), | ||
"vector": bool(self.options.with_vector), | ||
"examples": bool(self.options.with_examples), | ||
"tests": False, | ||
"log": is_debug | ||
}) | ||
# Workaround to avoid: error D8016: '/O1' and '/RTC1' command-line options are incompatible | ||
if is_msvc(self) and is_debug: | ||
tc.project_options["optimization"] = "plain" | ||
tc.generate() | ||
tc = PkgConfigDeps(self) | ||
tc.generate() | ||
venv = VirtualBuildEnv(self) | ||
venv.generate() | ||
|
||
def _patch_sources(self): | ||
# Workaround to avoid: Stripping target 'src\\thorvg-0.dll'. | ||
if is_msvc(self) and self.options.shared: | ||
replace_in_file(self, os.path.join(self.source_folder, "meson.build"), ", 'strip=true'", "") | ||
|
||
def build(self): | ||
self._patch_sources() | ||
meson = Meson(self) | ||
meson.configure() | ||
meson.build() | ||
|
||
def package(self): | ||
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) | ||
meson = Meson(self) | ||
meson.install() | ||
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
rm(self, "*.pdb", os.path.join(self.package_folder, "bin")) | ||
fix_apple_shared_install_name(self) | ||
|
||
if is_msvc(self) and not self.options.shared: | ||
rename(self, os.path.join(self.package_folder, "lib", "libthorvg.a"), os.path.join(self.package_folder, "lib", "thorvg.lib")) | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = ["thorvg"] | ||
|
||
self.cpp_info.set_property("pkg_config_name", "libthorvg") | ||
if self.settings.os in ["Linux", "FreeBSD"]: | ||
self.cpp_info.system_libs.extend(["pthread", "m"]) | ||
if not self.options.shared: | ||
self.cpp_info.defines = ["TVG_STATIC"] | ||
else: | ||
self.cpp_info.defines = ["TVG_EXPORT", "TVG_BUILD"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(test_package LANGUAGES CXX) | ||
|
||
find_package(thorvg REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE thorvg::thorvg) | ||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout, CMake | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeDeps", "CMakeToolchain", "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 can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindir, "test_package") | ||
self.run(bin_path, env="conanrun") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "thorvg.h" | ||
|
||
int main() { | ||
const int WIDTH = 800; | ||
const int HEIGHT = 600; | ||
|
||
tvg::Initializer::init(tvg::CanvasEngine::Sw, 0); | ||
|
||
static uint32_t buffer[WIDTH * HEIGHT]; // canvas target buffer | ||
|
||
auto canvas = tvg::SwCanvas::gen(); // generate a canvas | ||
canvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888); // buffer, stride, w, h, Colorspace | ||
|
||
auto rect = tvg::Shape::gen(); // generate a shape | ||
rect->appendRect(50, 50, 200, 200, 20, 20); // define it as a rounded rectangle (x, y, w, h, rx, ry) | ||
rect->fill(100, 100, 100, 255); // set its color (r, g, b, a) | ||
canvas->push(move(rect)); // push the rectangle into the canvas | ||
|
||
auto circle = tvg::Shape::gen(); // generate a shape | ||
circle->appendCircle(400, 400, 100, 100); // define it as a circle (cx, cy, rx, ry) | ||
|
||
auto fill = tvg::RadialGradient::gen(); // generate a radial gradient | ||
fill->radial(400, 400, 150); // set the radial gradient geometry info (cx, cy, radius) | ||
|
||
tvg::Fill::ColorStop colorStops[2]; // gradient colors | ||
colorStops[0] = {0.0, 255, 255, 255, 255}; // 1st color values (offset, r, g, b, a) | ||
colorStops[1] = {1.0, 0, 0, 0, 255}; // 2nd color values (offset, r, g, b, a) | ||
fill->colorStops(colorStops, 2); // set the gradient colors info | ||
|
||
circle->fill(move(fill)); // set the circle fill | ||
canvas->push(move(circle)); // push the circle into the canvas | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"0.13.0": | ||
folder: all |