Skip to content

Commit

Permalink
(conan-io#5783) add msdfgen/1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm authored and madebr committed Jun 21, 2021
1 parent f8f005c commit 11b9784
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/msdfgen/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8.11)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory(source_subfolder)
4 changes: 4 additions & 0 deletions recipes/msdfgen/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.9":
url: "https://github.com/Chlumsky/msdfgen/archive/refs/tags/v1.9.tar.gz"
sha256: "909eb88c71268dc00cdda244a1fa40a0feefae45f68a779fbfddd5463559fa40"
124 changes: 124 additions & 0 deletions recipes/msdfgen/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.33.0"


class MsdfgenConan(ConanFile):
name = "msdfgen"
description = "Multi-channel signed distance field generator"
license = "MIT"
topics = ("conan", "msdfgen", "msdf", "shape", "glyph", "font")
homepage = "https://github.com/Chlumsky/msdfgen"
url = "https://github.com/conan-io/conan-center-index"

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

exports_sources = "CMakeLists.txt"
generators = "cmake", "cmake_find_package"
_cmake = None

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

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

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

def requirements(self):
self.requires("freetype/2.10.4")
self.requires("lodepng/cci.20200615")
self.requires("tinyxml2/8.0.0")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)
if self.settings.compiler == "Visual Studio" and self.options.shared:
raise ConanInvalidConfiguration("msdfgen shared not supported by Visual Studio")
if self.options.with_skia:
raise ConanInvalidConfiguration("skia recipe not available yet in CCI")

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

def _patch_sources(self):
cmakelists = os.path.join(self._source_subfolder, "CMakeLists.txt")
# unvendor lodepng & tinyxml2
tools.rmdir(os.path.join(self._source_subfolder, "lib"))
tools.replace_in_file(cmakelists, "\"lib/*.cpp\"", "")
tools.replace_in_file(cmakelists,
"target_link_libraries(msdfgen-ext PUBLIC msdfgen::msdfgen Freetype::Freetype)",
"target_link_libraries(msdfgen-ext PUBLIC msdfgen::msdfgen ${CONAN_LIBS})")
# very weird but required for Visual Studio when libs are unvendored (at least for Ninja generator)
if self.settings.compiler == "Visual Studio":
tools.replace_in_file(cmakelists,
"set_target_properties(msdfgen-standalone PROPERTIES ARCHIVE_OUTPUT_DIRECTORY archive OUTPUT_NAME msdfgen)",
"set_target_properties(msdfgen-standalone PROPERTIES OUTPUT_NAME msdfgen IMPORT_PREFIX foo)")

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["MSDFGEN_BUILD_MSDFGEN_STANDALONE"] = self.options.utility
self._cmake.definitions["MSDFGEN_USE_OPENMP"] = self.options.with_openmp
self._cmake.definitions["MSDFGEN_USE_CPP11"] = True
self._cmake.definitions["MSDFGEN_USE_SKIA"] = self.options.with_skia
self._cmake.definitions["MSDFGEN_INSTALL"] = True
self._cmake.configure()
return self._cmake

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

def package(self):
self.copy("LICENSE.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "msdfgen"
self.cpp_info.names["cmake_find_package_multi"] = "msdfgen"

self.cpp_info.components["_msdfgen"].names["cmake_find_package"] = "msdfgen"
self.cpp_info.components["_msdfgen"].names["cmake_find_package_multi"] = "msdfgen"
self.cpp_info.components["_msdfgen"].libs = ["msdfgen"]
self.cpp_info.components["_msdfgen"].defines = ["MSDFGEN_USE_CPP11"]

self.cpp_info.components["msdfgen-ext"].names["cmake_find_package"] = "msdfgen-ext"
self.cpp_info.components["msdfgen-ext"].names["cmake_find_package_multi"] = "msdfgen-ext"
self.cpp_info.components["msdfgen-ext"].libs = ["msdfgen-ext"]
self.cpp_info.components["msdfgen-ext"].requires = [
"_msdfgen", "freetype::freetype",
"lodepng::lodepng", "tinyxml2::tinyxml2",
]
if self.options.with_skia:
self.cpp_info.components["msdfgen-ext"].defines.append("MSDFGEN_USE_SKIA")

if self.options.utility:
bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bin_path))
self.env_info.PATH.append(bin_path)
11 changes: 11 additions & 0 deletions recipes/msdfgen/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

find_package(msdfgen REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} msdfgen::msdfgen msdfgen::msdfgen-ext)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
Binary file not shown.
18 changes: 18 additions & 0 deletions recipes/msdfgen/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from conans import ConanFile, CMake, tools
import os


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

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

def test(self):
if not tools.cross_building(self.settings):
ttf_path = os.path.join(self.source_folder, "OpenSans-Bold.ttf")
bin_path = os.path.join("bin", "test_package")
self.run("{0} {1}".format(bin_path, ttf_path), run_environment=True)
31 changes: 31 additions & 0 deletions recipes/msdfgen/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <msdfgen/msdfgen.h>
#include <msdfgen/msdfgen-ext.h>

#include <iostream>

using namespace msdfgen;

int main(int argc, char **argv) {
if (argc < 2) {
std::cerr << "Need at least one argument\n";
return 1;
}

msdfgen::FreetypeHandle *ft = msdfgen::initializeFreetype();
if (ft) {
msdfgen::FontHandle *font = msdfgen::loadFont(ft, argv[1]);
if (font) {
msdfgen::Shape shape;
if (msdfgen::loadGlyph(shape, font, 'A')) {
shape.normalize();
msdfgen::edgeColoringSimple(shape, 3.0);
msdfgen::Bitmap<float, 3> msdf(32, 32);
msdfgen::generateMSDF(msdf, shape, 4.0, 1.0, msdfgen::Vector2(4.0, 4.0));
msdfgen::savePng(msdf, "output.png");
}
msdfgen::destroyFont(font);
}
msdfgen::deinitializeFreetype(ft);
}
return 0;
}
3 changes: 3 additions & 0 deletions recipes/msdfgen/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.9":
folder: all

0 comments on commit 11b9784

Please sign in to comment.