Skip to content

Commit

Permalink
wayland: Switch to MesonToolchain generator to allow cross-compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
jwillikers committed Jul 7, 2022
1 parent 5dec193 commit 5251310
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 95 deletions.
171 changes: 91 additions & 80 deletions recipes/wayland/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
from conans import ConanFile, Meson, tools
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.36.0"
from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.files import get, replace_in_file, rm
from conan.tools.layout import basic_layout
from conan.tools.meson import Meson, MesonToolchain
from conan.tools.scm import Version
from conan.errors import ConanInvalidConfiguration

required_conan_version = ">=1.43.0"

class WaylandConan(ConanFile):
name = "wayland"
Expand All @@ -26,16 +32,7 @@ class WaylandConan(ConanFile):
"enable_dtd_validation": True,
}

generators = "pkg_config"
_meson = None

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

@property
def _build_subfolder(self):
return "build_subfolder"
generators = "pkg_config", "PkgConfigDeps", "VirtualBuildEnv", "VirtualRunEnv"

def validate(self):
if self.settings.os != "Linux":
Expand All @@ -55,48 +52,52 @@ def requirements(self):
self.requires("expat/2.4.8")

def build_requirements(self):
self.build_requires("meson/0.60.2")
self.tool_requires("meson/0.62.2")
self.tool_requires("pkgconf/1.7.4")
if cross_building(self):
self.tool_requires("wayland/%s" % self.version)

def layout(self):
basic_layout(self)

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

def _patch_sources(self):
tools.replace_in_file(os.path.join(self._source_subfolder, "meson.build"),
"subdir('tests')", "#subdir('tests')")

def _configure_meson(self):
if not self._meson:
defs = {
"libraries": "true" if self.options.enable_libraries else "false",
"dtd_validation": "true" if self.options.enable_dtd_validation else "false",
"documentation": "false",
}
if tools.Version(self.version) >= "1.18.91":
defs.update({"scanner": "true"})
self._meson = Meson(self)
self._meson.configure(
source_folder=self._source_subfolder,
build_folder=self._build_subfolder,
defs=defs,
args=["--datadir={}".format(os.path.join(self.package_folder, "res"))]
)
return self._meson
replace_in_file(self, os.path.join(self.source_folder, "meson.build"),
"subdir('tests')", "#subdir('tests')")

def generate(self):
tc = MesonToolchain(self)
tc.project_options["libdir"] = "lib"
tc.project_options["datadir"] = "res"
tc.project_options["libraries"] = True
tc.project_options["dtd_validation"] = self.options.enable_dtd_validation
tc.project_options["documentation"] = False
if Version(self.version) >= "1.18.91":
tc.project_options["scanner"] = True
tc.generate()

def build(self):
self._patch_sources()
meson = self._configure_meson()
with tools.run_environment(self):
meson.build()
meson = Meson(self)
meson.configure()
meson.build()

def package(self):
self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder)
meson = self._configure_meson()
self.copy(pattern="COPYING", dst="licenses", src=self.source_folder)
meson = Meson(self)
meson.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
pkg_config_dir = os.path.join(self.package_folder, "lib", "pkgconfig")
rm(self, "wayland-egl*.pc", pkg_config_dir)
rm(self, "wayland-client.pc", pkg_config_dir)
rm(self, "wayland-cursor.pc", pkg_config_dir)
rm(self, "wayland-server.pc", pkg_config_dir)

def package_info(self):
self.cpp_info.components["wayland-scanner"].set_property("pkg_config_name", "wayland-scanner")
self.cpp_info.components["wayland-scanner"].names["pkg_config"] = "wayland-scanner"
self.cpp_info.components["wayland-scanner"].resdirs = ["res"]
self.cpp_info.components["wayland-scanner"].requires = ["expat::expat"]
if self.options.enable_dtd_validation:
self.cpp_info.components["wayland-scanner"].requires.append("libxml2::libxml2")
Expand All @@ -108,44 +109,54 @@ def package_info(self):
}
self.cpp_info.components["wayland-scanner"].set_property(
"pkg_config_custom_content",
"\n".join("%s=%s" % (key, value) for key,value in pkgconfig_variables.items()))
"\n".join(f"{key}={value}" for key,value in pkgconfig_variables.items()))

if self.options.enable_libraries:
self.cpp_info.components["wayland-server"].libs = ["wayland-server"]
self.cpp_info.components["wayland-server"].names["pkg_config"] = "wayland-server"
self.cpp_info.components["wayland-server"].requires = ["libffi::libffi"]
self.cpp_info.components["wayland-server"].system_libs = ["pthread", "m"]
pkgconfig_variables = {
'datarootdir': '${prefix}/res',
'pkgdatadir': '${datarootdir}/wayland',
}
self.cpp_info.components["wayland-server"].set_property(
"pkg_config_custom_content",
"\n".join("%s=%s" % (key, value) for key,value in pkgconfig_variables.items()))

self.cpp_info.components["wayland-client"].libs = ["wayland-client"]
self.cpp_info.components["wayland-client"].names["pkg_config"] = "wayland-client"
self.cpp_info.components["wayland-client"].requires = ["libffi::libffi"]
self.cpp_info.components["wayland-client"].system_libs = ["pthread", "m"]
pkgconfig_variables = {
'datarootdir': '${prefix}/res',
'pkgdatadir': '${datarootdir}/wayland',
}
self.cpp_info.components["wayland-client"].set_property(
"pkg_config_custom_content",
"\n".join("%s=%s" % (key, value) for key,value in pkgconfig_variables.items()))

self.cpp_info.components["wayland-cursor"].libs = ["wayland-cursor"]
self.cpp_info.components["wayland-cursor"].names["pkg_config"] = "wayland-cursor"
self.cpp_info.components["wayland-cursor"].requires = ["wayland-client"]

self.cpp_info.components["wayland-egl"].libs = ["wayland-egl"]
self.cpp_info.components["wayland-egl"].names["pkg_config"] = "wayland-egl"
self.cpp_info.components["wayland-egl"].requires = ["wayland-client"]

self.cpp_info.components["wayland-egl-backend"].names["pkg_config"] = "wayland-egl-backend"
self.cpp_info.components["wayland-egl-backend"].version = "3"
pkg_config_dir = os.path.join(self.package_folder, "lib", "pkgconfig")
self.buildenv_info.prepend_path("PKG_CONFIG_PATH", pkg_config_dir)
self.buildenv_info.define("PKG_CONFIG_wayland_scanner_PREFIX", self.package_folder)

bindir = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bindir))
self.env_info.PATH.append(bindir)
self.buildenv_info.prepend_path("PATH", bindir)
self.runenv_info.prepend_path("PATH", bindir)

self.cpp_info.components["wayland-server"].libs = ["wayland-server"]
self.cpp_info.components["wayland-server"].set_property("pkg_config_name", "wayland-server")
self.cpp_info.components["wayland-server"].names["pkg_config"] = "wayland-server"
self.cpp_info.components["wayland-server"].requires = ["libffi::libffi"]
self.cpp_info.components["wayland-server"].system_libs = ["pthread", "m"]
self.cpp_info.components["wayland-server"].resdirs = ["res"]
pkgconfig_variables = {
'datarootdir': '${prefix}/res',
'pkgdatadir': '${datarootdir}/wayland',
}
self.cpp_info.components["wayland-server"].set_property(
"pkg_config_custom_content",
"\n".join(f"{key}={value}" for key, value in pkgconfig_variables.items()))

self.cpp_info.components["wayland-client"].libs = ["wayland-client"]
self.cpp_info.components["wayland-client"].set_property("pkg_config_name", "wayland-client")
self.cpp_info.components["wayland-client"].names["pkg_config"] = "wayland-client"
self.cpp_info.components["wayland-client"].requires = ["libffi::libffi"]
self.cpp_info.components["wayland-client"].system_libs = ["pthread", "m"]
self.cpp_info.components["wayland-client"].resdirs = ["res"]
pkgconfig_variables = {
'datarootdir': '${prefix}/res',
'pkgdatadir': '${datarootdir}/wayland',
}
self.cpp_info.components["wayland-client"].set_property(
"pkg_config_custom_content",
"\n".join(f"{key}={value}" for key, value in pkgconfig_variables.items()))

self.cpp_info.components["wayland-cursor"].libs = ["wayland-cursor"]
self.cpp_info.components["wayland-cursor"].set_property("pkg_config_name", "wayland-cursor")
self.cpp_info.components["wayland-cursor"].names["pkg_config"] = "wayland-cursor"
self.cpp_info.components["wayland-cursor"].requires = ["wayland-client"]

self.cpp_info.components["wayland-egl"].libs = ["wayland-egl"]
self.cpp_info.components["wayland-egl"].set_property("pkg_config_name", "wayland-egl")
self.cpp_info.components["wayland-egl"].names["pkg_config"] = "wayland-egl"
self.cpp_info.components["wayland-egl"].requires = ["wayland-client"]

self.cpp_info.components["wayland-egl-backend"].names["pkg_config"] = "wayland-egl-backend"
self.cpp_info.components["wayland-egl-backend"].set_property("pkg_config_name", "wayland-egl-backend")
self.cpp_info.components["wayland-egl-backend"].version = "3"
9 changes: 4 additions & 5 deletions recipes/wayland/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.16)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(wayland COMPONENTS wayland-client REQUIRED)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
add_executable(test_package test_package.c)
target_link_libraries(test_package PRIVATE wayland::wayland-client)
26 changes: 16 additions & 10 deletions recipes/wayland/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
from conans import ConanFile, CMake, tools
import os

from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.cmake import CMake
from conan.tools.gnu import PkgConfig
from conan.tools.layout import basic_layout


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

def layout(self):
basic_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
if not tools.cross_building(self, skip_x64_x86=True):
with tools.environment_append({'PKG_CONFIG_PATH': "."}):
pkg_config = tools.PkgConfig("wayland-scanner")
self.run('%s --version' % pkg_config.variables["wayland_scanner"], run_environment=True)
if not cross_building(self):
pkg_config = PkgConfig(self, "wayland-scanner", self.generators_folder)
self.run('%s --version' % pkg_config.variables["wayland_scanner"], env="conanrun")

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 cross_building(self):
cmd = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(cmd, env="conanrun")

0 comments on commit 5251310

Please sign in to comment.