|
| 1 | +from conans import ConanFile, CMake, tools |
| 2 | +from conans.errors import ConanInvalidConfiguration |
| 3 | +import os |
| 4 | + |
| 5 | +required_conan_version = ">=1.33.0" |
| 6 | + |
| 7 | + |
| 8 | +class MsdfgenConan(ConanFile): |
| 9 | + name = "msdfgen" |
| 10 | + description = "Multi-channel signed distance field generator" |
| 11 | + license = "MIT" |
| 12 | + topics = ("conan", "msdfgen", "msdf", "shape", "glyph", "font") |
| 13 | + homepage = "https://github.com/Chlumsky/msdfgen" |
| 14 | + url = "https://github.com/conan-io/conan-center-index" |
| 15 | + |
| 16 | + settings = "os", "arch", "compiler", "build_type" |
| 17 | + options = { |
| 18 | + "shared": [True, False], |
| 19 | + "fPIC": [True, False], |
| 20 | + "with_openmp": [True, False], |
| 21 | + "with_skia": [True, False], |
| 22 | + "utility": [True, False], |
| 23 | + } |
| 24 | + default_options = { |
| 25 | + "shared": False, |
| 26 | + "fPIC": True, |
| 27 | + "with_openmp": False, |
| 28 | + "with_skia": False, |
| 29 | + "utility": True, |
| 30 | + } |
| 31 | + |
| 32 | + exports_sources = "CMakeLists.txt" |
| 33 | + generators = "cmake", "cmake_find_package" |
| 34 | + _cmake = None |
| 35 | + |
| 36 | + @property |
| 37 | + def _source_subfolder(self): |
| 38 | + return "source_subfolder" |
| 39 | + |
| 40 | + def config_options(self): |
| 41 | + if self.settings.os == "Windows": |
| 42 | + del self.options.fPIC |
| 43 | + |
| 44 | + def configure(self): |
| 45 | + if self.options.shared: |
| 46 | + del self.options.fPIC |
| 47 | + |
| 48 | + def requirements(self): |
| 49 | + self.requires("freetype/2.10.4") |
| 50 | + self.requires("lodepng/cci.20200615") |
| 51 | + self.requires("tinyxml2/8.0.0") |
| 52 | + |
| 53 | + def validate(self): |
| 54 | + if self.settings.compiler.get_safe("cppstd"): |
| 55 | + tools.check_min_cppstd(self, 11) |
| 56 | + if self.settings.compiler == "Visual Studio" and self.options.shared: |
| 57 | + raise ConanInvalidConfiguration("msdfgen shared not supported by Visual Studio") |
| 58 | + if self.options.with_skia: |
| 59 | + raise ConanInvalidConfiguration("skia recipe not available yet in CCI") |
| 60 | + |
| 61 | + def source(self): |
| 62 | + tools.get(**self.conan_data["sources"][self.version], |
| 63 | + destination=self._source_subfolder, strip_root=True) |
| 64 | + |
| 65 | + def _patch_sources(self): |
| 66 | + cmakelists = os.path.join(self._source_subfolder, "CMakeLists.txt") |
| 67 | + # unvendor lodepng & tinyxml2 |
| 68 | + tools.rmdir(os.path.join(self._source_subfolder, "lib")) |
| 69 | + tools.replace_in_file(cmakelists, "\"lib/*.cpp\"", "") |
| 70 | + tools.replace_in_file(cmakelists, |
| 71 | + "target_link_libraries(msdfgen-ext PUBLIC msdfgen::msdfgen Freetype::Freetype)", |
| 72 | + "target_link_libraries(msdfgen-ext PUBLIC msdfgen::msdfgen ${CONAN_LIBS})") |
| 73 | + # very weird but required for Visual Studio when libs are unvendored (at least for Ninja generator) |
| 74 | + if self.settings.compiler == "Visual Studio": |
| 75 | + tools.replace_in_file(cmakelists, |
| 76 | + "set_target_properties(msdfgen-standalone PROPERTIES ARCHIVE_OUTPUT_DIRECTORY archive OUTPUT_NAME msdfgen)", |
| 77 | + "set_target_properties(msdfgen-standalone PROPERTIES OUTPUT_NAME msdfgen IMPORT_PREFIX foo)") |
| 78 | + |
| 79 | + def _configure_cmake(self): |
| 80 | + if self._cmake: |
| 81 | + return self._cmake |
| 82 | + self._cmake = CMake(self) |
| 83 | + self._cmake.definitions["MSDFGEN_BUILD_MSDFGEN_STANDALONE"] = self.options.utility |
| 84 | + self._cmake.definitions["MSDFGEN_USE_OPENMP"] = self.options.with_openmp |
| 85 | + self._cmake.definitions["MSDFGEN_USE_CPP11"] = True |
| 86 | + self._cmake.definitions["MSDFGEN_USE_SKIA"] = self.options.with_skia |
| 87 | + self._cmake.definitions["MSDFGEN_INSTALL"] = True |
| 88 | + self._cmake.configure() |
| 89 | + return self._cmake |
| 90 | + |
| 91 | + def build(self): |
| 92 | + self._patch_sources() |
| 93 | + cmake = self._configure_cmake() |
| 94 | + cmake.build() |
| 95 | + |
| 96 | + def package(self): |
| 97 | + self.copy("LICENSE.txt", dst="licenses", src=self._source_subfolder) |
| 98 | + cmake = self._configure_cmake() |
| 99 | + cmake.install() |
| 100 | + tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) |
| 101 | + |
| 102 | + def package_info(self): |
| 103 | + self.cpp_info.names["cmake_find_package"] = "msdfgen" |
| 104 | + self.cpp_info.names["cmake_find_package_multi"] = "msdfgen" |
| 105 | + |
| 106 | + self.cpp_info.components["_msdfgen"].names["cmake_find_package"] = "msdfgen" |
| 107 | + self.cpp_info.components["_msdfgen"].names["cmake_find_package_multi"] = "msdfgen" |
| 108 | + self.cpp_info.components["_msdfgen"].libs = ["msdfgen"] |
| 109 | + self.cpp_info.components["_msdfgen"].defines = ["MSDFGEN_USE_CPP11"] |
| 110 | + |
| 111 | + self.cpp_info.components["msdfgen-ext"].names["cmake_find_package"] = "msdfgen-ext" |
| 112 | + self.cpp_info.components["msdfgen-ext"].names["cmake_find_package_multi"] = "msdfgen-ext" |
| 113 | + self.cpp_info.components["msdfgen-ext"].libs = ["msdfgen-ext"] |
| 114 | + self.cpp_info.components["msdfgen-ext"].requires = [ |
| 115 | + "_msdfgen", "freetype::freetype", |
| 116 | + "lodepng::lodepng", "tinyxml2::tinyxml2", |
| 117 | + ] |
| 118 | + if self.options.with_skia: |
| 119 | + self.cpp_info.components["msdfgen-ext"].defines.append("MSDFGEN_USE_SKIA") |
| 120 | + |
| 121 | + if self.options.utility: |
| 122 | + bin_path = os.path.join(self.package_folder, "bin") |
| 123 | + self.output.info("Appending PATH environment variable: {}".format(bin_path)) |
| 124 | + self.env_info.PATH.append(bin_path) |
0 commit comments