Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cairomm v2 toolchain #15713

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions recipes/cairomm/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"1.16.2":
url: "https://cairographics.org/releases/cairomm-1.16.2.tar.xz"
sha256: "6a63bf98a97dda2b0f55e34d1b5f3fb909ef8b70f9b8d382cb1ff3978e7dc13f"
"1.16.1":
url: "https://cairographics.org/releases/cairomm-1.16.1.tar.xz"
sha256: "6f6060d8e98dd4b8acfee2295fddbdd38cf487c07c26aad8d1a83bb9bff4a2c6"
Expand All @@ -9,7 +12,9 @@ sources:
patches:
"1.16.1":
- patch_file: "patches/enable_static_lib_1_16_1.patch"
base_path: "source_subfolder"
patch_description: "enable static library build on MSVC"
patch_type: "portability"
"1.14.3":
- patch_file: "patches/enable_static_lib_1_14_3.patch"
base_path: "source_subfolder"
patch_description: "enable static library build on MSVC"
patch_type: "portability"
239 changes: 117 additions & 122 deletions recipes/cairomm/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
from conans import ConanFile, Meson, tools
from conan.tools.files import rename
from conan.tools.microsoft import is_msvc
from conans.errors import ConanInvalidConfiguration
import glob
import os
import shutil

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import fix_apple_shared_install_name, is_apple_os
from conan.tools.build import check_min_cppstd
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rm, rmdir, rename
from conan.tools.gnu import PkgConfigDeps
from conan.tools.layout import basic_layout
from conan.tools.meson import Meson, MesonToolchain
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version
from conan import __version__ as conan_version


class CairommConan(ConanFile):
name = "cairomm"
Expand All @@ -14,7 +23,7 @@ class CairommConan(ConanFile):
license = "LGPL-2.0"
description = "cairomm is a C++ wrapper for the cairo graphics library."
topics = ["cairo", "wrapper", "graphics"]

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -24,171 +33,157 @@ class CairommConan(ConanFile):
"shared": False,
"fPIC": True,
}

generators = "pkg_config"
exports_sources = "patches/**"
short_paths = True

@property
def _abi_version(self):
return "1.16" if tools.Version(self.version) >= "1.16.0" else "1.0"
return "1.16" if Version(self.version) >= "1.16.0" else "1.0"

def validate(self):
if hasattr(self, "settings_build") and tools.cross_building(self):
raise ConanInvalidConfiguration("Cross-building not implemented")
if self.settings.compiler.get_safe("cppstd"):
if self._abi_version() == "1.16":
tools.check_min_cppstd(self, 17)
else:
tools.check_min_cppstd(self, 11)
if self.options.shared and not self.options["cairo"].shared:
raise ConanInvalidConfiguration(
"Linking against static cairo would cause shared cairomm to link "
"against static glib which can cause problems."
)
@property
def _min_cppstd(self):
return "17" if self._abi_version == "1.16" else "11"

@property
def _source_subfolder(self):
return "source_subfolder"
def is_conan2(self):
return Version(conan_version) >= "2.0.0"

@property
def _build_subfolder(self):
return "build_subfolder"
def _compilers_minimum_version_17(self):
return {
"gcc": "7",
"clang": "7",
"apple-clang": "10",
}

def _patch_sources(self):
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)
if is_msvc(self):
# when using cpp_std=c++11 the /permissive- flag is added which
# attempts enforcing standard conformant c++ code
# the problem is that older versions of Windows SDK is not standard
# conformant! see:
# https://developercommunity.visualstudio.com/t/error-c2760-in-combaseapih-with-windows-sdk-81-and/185399
tools.replace_in_file(
os.path.join(self._source_subfolder, "meson.build"),
"cpp_std=c++", "cpp_std=vc++")
def export_sources(self):
export_conandata_patches(self)

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

def configure(self):
if self.options.shared:
del self.options.fPIC
if self.options.shared:
self.options.rm_safe("fPIC")
self.options["cairo"].shared = True

def build_requirements(self):
self.build_requires("meson/0.59.1")
self.build_requires("pkgconf/1.7.4")
def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
self.requires("cairo/1.17.4")
self.requires("cairo/1.17.6", transitive_headers=True)
if self.is_conan2:
# TODO remove once cairo has added transitive headers arg
self.requires("freetype/2.13.0", transitive_headers=True)

if self._abi_version() == "1.16":
self.requires("libsigcpp/3.0.7")
if self._abi_version == "1.16":
self.requires("libsigcpp/3.0.7", transitive_headers=True)
else:
self.requires("libsigcpp/2.10.8")
self.requires("libsigcpp/2.10.8", transitive_headers=True)

def source(self):
tools.get(
**self.conan_data["sources"][self.version],
strip_root=True,
destination=self._source_subfolder,
)
def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)

def build(self):
self._patch_sources()
with tools.environment_append(tools.RunEnvironment(self).vars):
meson = self._configure_meson()
meson.build()
if not is_msvc(self) and self._abi_version == "1.16":
minimum_version = self._compilers_minimum_version_17.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 _configure_meson(self):
meson = Meson(self)
defs = {
if self.options.shared and not self.dependencies["cairo"].options.shared:
raise ConanInvalidConfiguration(
"Linking against static cairo would cause shared cairomm to link "
"against static glib which can cause problems."
)

def build_requirements(self):
self.tool_requires("meson/1.2.1")
self.tool_requires("pkgconf/2.0.3")

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

def generate(self):
tc = MesonToolchain(self)
tc.project_options.update({
"build-examples": "false",
"build-documentation": "false",
"build-tests": "false",
"msvc14x-parallel-installable": "false",
"default_library": "shared" if self.options.shared else "static",
}
meson.configure(
defs=defs,
build_folder=self._build_subfolder,
source_folder=self._source_subfolder,
pkg_config_paths=[self.install_folder],
)
return meson
})
tc.generate()

PkgConfigDeps(self).generate()
VirtualBuildEnv(self).generate()

def _patch_sources(self):
apply_conandata_patches(self)
if is_msvc(self):
# when using cpp_std=c++11 the /permissive- flag is added which
# attempts enforcing standard conformant c++ code
# the problem is that older versions of Windows SDK is not standard
# conformant! see:
# https://developercommunity.visualstudio.com/t/error-c2760-in-combaseapih-with-windows-sdk-81-and/185399
replace_in_file(self,
os.path.join(self.source_folder, "meson.build"),
"cpp_std=c++", "cpp_std=vc++")

def build(self):
self._patch_sources()
meson = Meson(self)
meson.configure()
meson.build()

def package(self):
self.copy("COPYING", dst="licenses", src=self._source_subfolder)
meson = self._configure_meson()
copy(self, pattern="COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
meson = Meson(self)
meson.install()

if is_msvc(self):
tools.remove_files_by_mask(
os.path.join(self.package_folder, "bin"), "*.pdb")
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))
if not self.options.shared:
rename(
self,
os.path.join(
self.package_folder,
"lib",
f"libcairomm-{self._abi_version()}.a",
),
os.path.join(self.package_folder, "lib",
f"cairomm-{self._abi_version()}.lib"),
rename(self,
os.path.join( self.package_folder, "lib", f"libcairomm-{self._abi_version}.a"),
os.path.join(self.package_folder, "lib", f"cairomm-{self._abi_version}.lib"),
)

for header_file in glob.glob(
os.path.join(
self.package_folder,
"lib",
f"cairomm-{self._abi_version()}",
"include",
"*.h",
)):
os.path.join(self.package_folder, "lib", f"cairomm-{self._abi_version}", "include", "*.h")):
shutil.move(
header_file,
os.path.join(
self.package_folder,
"include",
f"cairomm-{self._abi_version()}",
f"cairomm-{self._abi_version}",
os.path.basename(header_file),
),
)

for dir_to_remove in ["pkgconfig", f"cairomm-{self._abi_version()}"]:
tools.rmdir(os.path.join(self.package_folder, "lib",
dir_to_remove))
for dir_to_remove in ["pkgconfig", f"cairomm-{self._abi_version}"]:
rmdir(self, os.path.join(self.package_folder, "lib", dir_to_remove))

fix_apple_shared_install_name(self)

def package_info(self):
if self._abi_version() == "1.16":
self.cpp_info.components["cairomm-1.16"].names[
"pkg_config"] = "cairomm-1.16"
self.cpp_info.components["cairomm-1.16"].includedirs = [
os.path.join("include", "cairomm-1.16")
]
self.cpp_info.components["cairomm-1.16"].libs = ["cairomm-1.16"]
self.cpp_info.components["cairomm-1.16"].requires = [
"libsigcpp::sigc++", "cairo::cairo_"
]
if tools.is_apple_os(self.settings.os):
self.cpp_info.components["cairomm-1.16"].frameworks = [
"CoreFoundation"
]
else:
self.cpp_info.components["cairomm-1.0"].names[
"pkg_config"] = "cairomm-1.0"
self.cpp_info.components["cairomm-1.0"].includedirs = [
os.path.join("include", "cairomm-1.0")
]
self.cpp_info.components["cairomm-1.0"].libs = ["cairomm-1.0"]
self.cpp_info.components["cairomm-1.0"].requires = [
"libsigcpp::sigc++-2.0", "cairo::cairo_"
]
if tools.is_apple_os(self.settings.os):
self.cpp_info.components["cairomm-1.0"].frameworks = [
"CoreFoundation"
]
cairomm_lib_name = f"cairomm-{self._abi_version}"
self.cpp_info.components[cairomm_lib_name].set_property("pkg_config_name", cairomm_lib_name)
self.cpp_info.components[cairomm_lib_name].includedirs = [os.path.join("include", cairomm_lib_name)]
self.cpp_info.components[cairomm_lib_name].libs = [cairomm_lib_name]

component_requires = ["libsigcpp::libsigcpp", "cairo::cairo_"]
if self.is_conan2:
# TODO required only because cairo recipe needs updating to declare
# transitive header dependency on freetype
component_requires.append("freetype::freetype")
self.cpp_info.components[cairomm_lib_name].requires = component_requires

if is_apple_os(self):
self.cpp_info.components[cairomm_lib_name].frameworks = ["CoreFoundation"]


def package_id(self):
self.info.requires["cairo"].full_package_mode()
if not self.dependencies["cairo"].options.shared:
self.info.requires["cairo"].full_package_mode()
7 changes: 2 additions & 5 deletions recipes/cairomm/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
cmake_minimum_required(VERSION 3.6)
project(test_package)

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

add_executable(${PROJECT_NAME} test_package.cpp)

find_package(cairomm REQUIRED CONFIG)
if (TARGET cairomm::cairomm-1.16)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)
target_link_libraries(${PROJECT_NAME} cairomm::cairomm-1.16)
target_link_libraries(${PROJECT_NAME} PRIVATE cairomm::cairomm-1.16)
else()
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
target_link_libraries(${PROJECT_NAME} cairomm::cairomm-1.0)
target_link_libraries(${PROJECT_NAME} PRIVATE cairomm::cairomm-1.0)
endif()
17 changes: 11 additions & 6 deletions recipes/cairomm/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools import build
from conan.tools.cmake import CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv", "VirtualBuildEnv"
test_type = "explicit"

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):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

if not build.cross_building(self):
bin_path = os.path.join(self.build_folder, "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/cairomm/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/)
Loading