Skip to content

Commit

Permalink
(#21085) msdfgen: add 1.11 + package_type + bump deps
Browse files Browse the repository at this point in the history
* add package_type

* bump freetype & libpng

* avoid patch in 1.10

* add msdfgen/1.11

* inject BUILD_SHARED_LIBS as cache_variables

* simplify patching strategy of previous versions

* restore find_package module freetype

* remove pdb files

* Revert "restore find_package module freetype"

This reverts commit d678393.

* workaround for conan-io/conan#13560

* bump freetype

* less verbose package_info()

* Update recipes/msdfgen/all/conanfile.py

Co-authored-by: Matthieu Darbois <[email protected]>

---------

Co-authored-by: Rubén Rincón Blanco <[email protected]>
Co-authored-by: Matthieu Darbois <[email protected]>
  • Loading branch information
3 people authored May 28, 2024
1 parent f707cc7 commit a8cbe2a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 71 deletions.
7 changes: 5 additions & 2 deletions recipes/msdfgen/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"1.11":
url: "https://github.com/Chlumsky/msdfgen/archive/refs/tags/v1.11.tar.gz"
sha256: "fad74e33274f591e72511bc0546189e7aec439f2a512ef1b2fde243554d457cb"
"1.10":
url: "https://github.com/Chlumsky/msdfgen/archive/refs/tags/v1.10.tar.gz"
sha256: "2754d1687bfb80968d9c682e0c4c04c8fcf72df1421d076baf44ea0d87aa3662"
Expand All @@ -10,8 +13,8 @@ sources:
sha256: "909eb88c71268dc00cdda244a1fa40a0feefae45f68a779fbfddd5463559fa40"
patches:
"1.10":
- patch_file: "patches/1.10-0001-fix-cmake.patch"
patch_description: "move project position to top"
- patch_file: "patches/1.10-0001-honor-msvc-runtime.patch"
patch_description: "Remove hardcoded vc runtime"
patch_type: "conan"
"1.9.1":
- patch_file: "patches/1.9-0001-unvendor-external-libs.patch"
Expand Down
76 changes: 31 additions & 45 deletions recipes/msdfgen/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rmdir
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rm, rmdir
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
from conan.tools.scm import Version
import os
Expand All @@ -17,7 +17,7 @@ class MsdfgenConan(ConanFile):
topics = ("msdf", "shape", "glyph", "font")
homepage = "https://github.com/Chlumsky/msdfgen"
url = "https://github.com/conan-io/conan-center-index"

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand Down Expand Up @@ -49,11 +49,11 @@ def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("freetype/2.12.1")
self.requires("freetype/2.13.2")
if Version(self.version) < "1.10":
self.requires("lodepng/cci.20200615")
else:
self.requires("libpng/1.6.39")
self.requires("libpng/[>=1.6 <2]")
self.requires("tinyxml2/9.0.0")

def validate(self):
Expand All @@ -65,59 +65,45 @@ def validate(self):
raise ConanInvalidConfiguration("skia recipe not available yet in CCI")

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["MSDFGEN_BUILD_MSDFGEN_STANDALONE"] = self.options.utility
tc.variables["MSDFGEN_USE_OPENMP"] = self.options.with_openmp
tc.variables["MSDFGEN_USE_CPP11"] = True
tc.variables["MSDFGEN_USE_SKIA"] = self.options.with_skia
tc.variables["MSDFGEN_INSTALL"] = True
tc.cache_variables["MSDFGEN_BUILD_MSDFGEN_STANDALONE"] = self.options.utility
tc.cache_variables["MSDFGEN_USE_OPENMP"] = self.options.with_openmp
tc.cache_variables["MSDFGEN_USE_CPP11"] = True
tc.cache_variables["MSDFGEN_USE_SKIA"] = self.options.with_skia
tc.cache_variables["MSDFGEN_INSTALL"] = True
if Version(self.version) >= "1.10":
tc.variables["MSDFGEN_DYNAMIC_RUNTIME"] = not is_msvc_static_runtime(self)
tc.variables["MSDFGEN_USE_VCPKG"] = False
tc.cache_variables["MSDFGEN_USE_VCPKG"] = False
# Because in upstream CMakeLists, project() is called after some logic based on BUILD_SHARED_LIBS
tc.cache_variables["BUILD_SHARED_LIBS"] = self.options.shared
if Version(self.version) >= "1.11":
tc.cache_variables["MSDFGEN_DYNAMIC_RUNTIME"] = not is_msvc_static_runtime(self)
if self.settings.os == "Linux":
# Workaround for https://github.com/conan-io/conan/issues/13560
libdirs_host = [l for dependency in self.dependencies.host.values() for l in dependency.cpp_info.aggregated_components().libdirs]
tc.variables["CMAKE_BUILD_RPATH"] = ";".join(libdirs_host)
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
apply_conandata_patches(self)
cmakelists = os.path.join(self.source_folder, "CMakeLists.txt")
# workaround against CMAKE_FIND_PACKAGE_PREFER_CONFIG ON in conan toolchain
replace_in_file(self, cmakelists, "find_package(Freetype REQUIRED)", "find_package(Freetype REQUIRED MODULE)")
# remove bundled lodepng & tinyxml2
rmdir(self, os.path.join(self.source_folder, "lib"))
rmdir(self, os.path.join(self.source_folder, "include"))
# very weird but required for Visual Studio when libs are unvendored (at least for Ninja generator)
if is_msvc(self):
if Version(self.version) < "1.10":

if Version(self.version) < "1.10":
# remove bundled lodepng & tinyxml2
rmdir(self, os.path.join(self.source_folder, "lib"))
rmdir(self, os.path.join(self.source_folder, "include"))

# very weird but required for Visual Studio when libs are unvendored (at least for Ninja generator)
if is_msvc(self):
replace_in_file(
self,
cmakelists,
os.path.join(self.source_folder, "CMakeLists.txt"),
"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)",
)
else:
replace_in_file(
self,
cmakelists,
'set_property(TARGET msdfgen-core PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")',
''
)
replace_in_file(
self,
cmakelists,
'set_property(TARGET msdfgen-ext PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")',
''
)
replace_in_file(
self,
cmakelists,
'set_property(TARGET msdfgen PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")',
''
)

def build(self):
self._patch_sources()
Expand All @@ -130,6 +116,7 @@ def package(self):
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "msdfgen")
Expand Down Expand Up @@ -167,7 +154,6 @@ def package_info(self):
if self.options.with_skia:
self.cpp_info.components["msdfgen-ext"].defines.append("MSDFGEN_USE_SKIA")

# TODO: to remove once conan v1 support dropped
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)
self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))
24 changes: 0 additions & 24 deletions recipes/msdfgen/all/patches/1.10-0001-fix-cmake.patch

This file was deleted.

26 changes: 26 additions & 0 deletions recipes/msdfgen/all/patches/1.10-0001-honor-msvc-runtime.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -79,7 +79,6 @@ file(GLOB_RECURSE MSDFGEN_EXT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "ext/
add_library(msdfgen-core "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen.h" ${MSDFGEN_CORE_HEADERS} ${MSDFGEN_CORE_SOURCES})
add_library(msdfgen::msdfgen-core ALIAS msdfgen-core)
set_target_properties(msdfgen-core PROPERTIES PUBLIC_HEADER "${MSDFGEN_CORE_HEADERS}")
-set_property(TARGET msdfgen-core PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
target_compile_definitions(msdfgen-core PUBLIC
MSDFGEN_VERSION=${MSDFGEN_VERSION}
MSDFGEN_VERSION_MAJOR=${MSDFGEN_VERSION_MAJOR}
@@ -127,7 +126,6 @@ if(NOT MSDFGEN_CORE_ONLY)
add_library(msdfgen-ext "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen-ext.h" ${MSDFGEN_EXT_HEADERS} ${MSDFGEN_EXT_SOURCES})
add_library(msdfgen::msdfgen-ext ALIAS msdfgen-ext)
set_target_properties(msdfgen-ext PROPERTIES PUBLIC_HEADER "${MSDFGEN_EXT_HEADERS}")
- set_property(TARGET msdfgen-ext PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
target_compile_definitions(msdfgen-ext PUBLIC MSDFGEN_USE_LIBPNG)
target_link_libraries(msdfgen-ext PRIVATE msdfgen::msdfgen-core Freetype::Freetype tinyxml2::tinyxml2 PNG::PNG)
target_include_directories(msdfgen-ext
@@ -171,7 +169,6 @@ if(MSDFGEN_BUILD_STANDALONE)
add_executable(msdfgen ${MSDFGEN_STANDALONE_SOURCES})
target_compile_definitions(msdfgen PUBLIC MSDFGEN_STANDALONE)
target_compile_definitions(msdfgen PRIVATE MSDFGEN_VERSION_UNDERLINE=${MSDFGEN_VERSION_UNDERLINE})
- set_property(TARGET msdfgen PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
target_link_libraries(msdfgen PRIVATE msdfgen::msdfgen)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT msdfgen)
endif()
2 changes: 2 additions & 0 deletions recipes/msdfgen/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"1.11":
folder: all
"1.10":
folder: all
"1.9.1":
Expand Down

0 comments on commit a8cbe2a

Please sign in to comment.