Skip to content

Commit

Permalink
(conan-io#15729) fontconfig < 2.13.93: conan v2 support
Browse files Browse the repository at this point in the history
* conan v2 support

* add AutotoolsDeps

* cmake_find_package in test v1 package
  • Loading branch information
SpaceIm authored and sabelka committed Feb 12, 2023
1 parent 6cbed4f commit 9d0cf9b
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 117 deletions.
152 changes: 74 additions & 78 deletions recipes/fontconfig/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools import files, microsoft
from conans import tools, AutoToolsBuildEnvironment

import functools
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.build import cross_building
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv
from conan.tools.files import copy, get, replace_in_file, rm, rmdir
from conan.tools.gnu import Autotools, AutotoolsDeps, AutotoolsToolchain, PkgConfigDeps
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc
import os

required_conan_version = ">=1.50.2"
required_conan_version = ">=1.54.0"


class FontconfigConan(ConanFile):
Expand All @@ -26,110 +29,104 @@ class FontconfigConan(ConanFile):
"fPIC": True,
}

generators = "pkg_config"

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

@property
def _build_subfolder(self):
return "build_subfolder"

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

def export_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])

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

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
self.requires("freetype/2.12.1")
self.requires("expat/2.4.9")
self.requires("expat/2.5.0")
if self.settings.os == "Linux":
self.requires("libuuid/1.0.3")

def validate(self):
if microsoft.is_msvc(self):
if is_msvc(self):
raise ConanInvalidConfiguration("fontconfig does not support Visual Studio for versions < 2.13.93.")

def build_requirements(self):
self.build_requires("gperf/3.1")
self.build_requires("pkgconf/1.7.4")
if self._settings_build.os == "Windows" and not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.build_requires("msys2/cci.latest")
self.tool_requires("gperf/3.1")
if not self.conf.get("tools.gnu:pkg_config", check_type=str):
self.tool_requires("pkgconf/1.9.3")
if self._settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")

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

@functools.lru_cache(1)
def _configure_autotools(self):
autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
autotools.libs = []
def generate(self):
env = VirtualBuildEnv(self)
env.generate()
if not cross_building(self):
env = VirtualRunEnv(self)
env.generate(scope="build")

tc = AutotoolsToolchain(self)
yes_no = lambda v: "yes" if v else "no"
args = [
"--enable-shared={}".format(yes_no(self.options.shared)),
"--enable-static={}".format(yes_no(not self.options.shared)),
tc.configure_args.extend([
f"--enable-shared={yes_no(self.options.shared)}",
f"--enable-static={yes_no(not self.options.shared)}",
"--disable-docs",
"--disable-nls",
"--sysconfdir={}".format(tools.unix_path(os.path.join(self.package_folder, "bin", "etc"))),
"--datadir={}".format(tools.unix_path(os.path.join(self.package_folder, "bin", "share"))),
"--datarootdir={}".format(tools.unix_path(os.path.join(self.package_folder, "bin", "share"))),
"--localstatedir={}".format(tools.unix_path(os.path.join(self.package_folder, "bin", "var"))),
]
autotools.configure(configure_dir=self._source_subfolder, args=args)
files.replace_in_file(self, "Makefile", "po-conf test", "po-conf")
return autotools
"--sysconfdir=${prefix}/bin/etc",
"--datadir=${prefix}/bin/share",
"--datarootdir=${prefix}/bin/share",
"--localstatedir=${prefix}/bin/var",
])
tc.generate()

deps = AutotoolsDeps(self)
deps.generate()
deps = PkgConfigDeps(self)
deps.generate()

def _patch_files(self):
files.apply_conandata_patches(self)
# fontconfig requires libtool version number, change it for the corresponding freetype one
files.replace_in_file(self, os.path.join(self.install_folder, "freetype2.pc"),
"Version: {}".format(self.deps_cpp_info["freetype"].version),
"Version: {}".format(self.deps_user_info["freetype"].LIBTOOL_VERSION))
replace_in_file(
self, os.path.join(self.generators_folder, "freetype2.pc"),
"Version: {}".format(self.dependencies["freetype"].ref.version),
"Version: {}".format(self.dependencies["freetype"].conf_info.get("user.freetype:libtool_version")),
)
# disable fc-cache test to enable cross compilation but also builds with shared libraries on MacOS
files.replace_in_file(self,
os.path.join(self._source_subfolder, "Makefile.in"),
replace_in_file(self,
os.path.join(self.source_folder, "Makefile.in"),
"@CROSS_COMPILING_TRUE@RUN_FC_CACHE_TEST = false",
"RUN_FC_CACHE_TEST=false"
)

def build(self):
self._patch_files()
# relocatable shared lib on macOS
files.replace_in_file(self,
os.path.join(self._source_subfolder, "configure"),
"-install_name \\$rpath/",
"-install_name @rpath/"
)
with tools.run_environment(self):
autotools = self._configure_autotools()
autotools.make()
autotools = Autotools(self)
autotools.configure()
replace_in_file(self, os.path.join(self.build_folder, "Makefile"), "po-conf test", "po-conf")
autotools.make()

def package(self):
self.copy("COPYING", src=self._source_subfolder, dst="licenses")
with tools.run_environment(self):
autotools = self._configure_autotools()
autotools.install()

files.rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))
files.rm(self, "*.conf", os.path.join(self.package_folder, "bin", "etc", "fonts", "conf.d"))
files.rm(self, "*.def", os.path.join(self.package_folder, "lib"))
files.rm(self, "*.la", os.path.join(self.package_folder, "lib"))
files.rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
files.rmdir(self, os.path.join(self.package_folder, "etc"))
files.rmdir(self, os.path.join(self.package_folder, "share"))
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
autotools = Autotools(self)
autotools.install()
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))
rm(self, "*.conf", os.path.join(self.package_folder, "bin", "etc", "fonts", "conf.d"))
rm(self, "*.def", os.path.join(self.package_folder, "lib"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "etc"))
rmdir(self, os.path.join(self.package_folder, "share"))
fix_apple_shared_install_name(self)

def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "both")
Expand All @@ -140,15 +137,14 @@ def package_info(self):
if self.settings.os in ("Linux", "FreeBSD"):
self.cpp_info.system_libs.extend(["m", "pthread"])

self.cpp_info.names["cmake_find_package"] = "Fontconfig"
self.cpp_info.names["cmake_find_package_multi"] = "Fontconfig"

fontconfig_file = os.path.join(self.package_folder, "bin", "etc", "fonts", "fonts.conf")
self.output.info(f"Creating FONTCONFIG_FILE environment variable: {fontconfig_file}")
self.runenv_info.prepend_path("FONTCONFIG_FILE", fontconfig_file)
self.env_info.FONTCONFIG_FILE = fontconfig_file # TODO: remove in conan v2?

fontconfig_path = os.path.join(self.package_folder, "bin", "etc", "fonts")
self.output.info(f"Creating FONTCONFIG_PATH environment variable: {fontconfig_path}")
self.runenv_info.prepend_path("FONTCONFIG_PATH", fontconfig_path)
self.env_info.FONTCONFIG_PATH = fontconfig_path # TODO: remove in conan v2?

# TODO: to remove in conan v2
self.cpp_info.names["cmake_find_package"] = "Fontconfig"
self.cpp_info.names["cmake_find_package_multi"] = "Fontconfig"
self.env_info.FONTCONFIG_FILE = fontconfig_file
self.env_info.FONTCONFIG_PATH = fontconfig_path
19 changes: 0 additions & 19 deletions recipes/fontconfig/all/patches/0001-meson-win32.patch

This file was deleted.

11 changes: 4 additions & 7 deletions recipes/fontconfig/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
cmake_minimum_required(VERSION 3.14)
project(test_package LANGUAGES C)

find_package(Fontconfig REQUIRED)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} Fontconfig::Fontconfig)
set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 99)
target_link_libraries(${PROJECT_NAME} PRIVATE Fontconfig::Fontconfig)
target_compile_features(${PROJECT_NAME} PRIVATE c_std_99)
26 changes: 13 additions & 13 deletions recipes/fontconfig/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
from conans import ConanFile, CMake, tools
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 = "cmake", "cmake_find_package"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def build_requirements(self):
if self.settings.os == "Macos" and self.settings.arch == "armv8":
# Workaround for CMake bug with error message:
# Attempting to use @rpath without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being
# set. This could be because you are using a Mac OS X version less than 10.5
# or because CMake's platform configuration is corrupt.
# FIXME: Remove once CMake on macOS/M1 CI runners is upgraded.
self.build_requires("cmake/3.22.0")
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 not tools.cross_building(self, skip_x64_x86=True):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/fontconfig/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions recipes/fontconfig/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 9d0cf9b

Please sign in to comment.