Skip to content

Commit

Permalink
[glibmm] update meson toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
planetmarshall committed Jan 5, 2023
1 parent 41c35fa commit c463312
Showing 1 changed file with 73 additions and 77 deletions.
150 changes: 73 additions & 77 deletions recipes/glibmm/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@
import shutil

from conan import ConanFile
from conan.tools import (
build,
files,
microsoft,
scm
)
from conan.errors import ConanInvalidConfiguration
from conans import Meson, tools
from conan.tools.build import check_min_cppstd, cross_building
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import (
apply_conandata_patches,
copy,
get,
replace_in_file,
rename,
rm,
rmdir
)
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, is_msvc_static_runtime
from conan.tools.scm import Version

required_conan_version = ">=1.50.0"
required_conan_version = ">=1.53.0"


class GlibmmConan(ConanFile):
Expand All @@ -32,7 +41,7 @@ class GlibmmConan(ConanFile):

@property
def _abi_version(self):
return "2.68" if scm.Version(self.version) >= "2.68.0" else "2.4"
return "2.68" if Version(self.version) >= "2.68.0" else "2.4"

@property
def _glibmm_lib(self):
Expand All @@ -43,75 +52,87 @@ def _giomm_lib(self):
return f"giomm-{self._abi_version}"

def validate(self):
if hasattr(self, "settings_build") and build.cross_building(self):
if hasattr(self, "settings_build") and cross_building(self):
raise ConanInvalidConfiguration("Cross-building not implemented")

if self.settings.compiler.get_safe("cppstd"):
if self._abi_version == "2.68":
build.check_min_cppstd(self, 17)
check_min_cppstd(self, 17)
else:
build.check_min_cppstd(self, 11)
check_min_cppstd(self, 11)

if self.options.shared and not self.options["glib"].shared:
raise ConanInvalidConfiguration(
"Linking a shared library against static glib can cause unexpected behaviour."
)

if self.options["glib"].shared and microsoft.is_msvc_static_runtime(self):
if self.options["glib"].shared and is_msvc_static_runtime(self):
raise ConanInvalidConfiguration(
"Linking shared glib with the MSVC static runtime is not supported"
)

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

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

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

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

def build_requirements(self):
self.build_requires("meson/0.64.1")
self.build_requires("pkgconf/1.9.3")
self.tool_requires("meson/0.63.3")
self.tool_requires("pkgconf/1.9.3")

def requirements(self):
self.requires("glib/2.75.0")

if self._abi_version == "2.68":
self.requires("glib/2.74.0")
self.requires("libsigcpp/3.0.7")
else:
self.requires("glib/2.67.6")
self.requires("libsigcpp/2.10.8")

def generate(self):
deps = PkgConfigDeps(self)
deps.generate()

tc = MesonToolchain(self)
tc.project_options.update({
"build-examples": "false",
"build-documentation": "false",
"msvc14x-parallel-installable": "false",
"default_library": "shared" if self.options.shared else "static",
})
tc.generate()

env = VirtualBuildEnv(self)
env.generate()

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, destination=self.source_folder)

def _patch_sources(self):
files.apply_conandata_patches(self)
meson_build = os.path.join(self._source_subfolder, "meson.build")
files.replace_in_file(self, meson_build, "subdir('tests')", "")
if microsoft.is_msvc(self):
apply_conandata_patches(self)
meson_build = os.path.join(self.source_folder, "meson.build")
replace_in_file(self, meson_build, "subdir('tests')", "")
if is_msvc(self):
# GLiBMM_GEN_EXTRA_DEFS_STATIC is not defined anywhere and is not
# used anywhere except here
# when building a static build !defined(GLiBMM_GEN_EXTRA_DEFS_STATIC)
# evaluates to 0
if not self.options.shared:
files.replace_in_file(self,
os.path.join(self._source_subfolder, "tools",
"extra_defs_gen", "generate_extra_defs.h"),
"#if defined (_MSC_VER) && !defined (GLIBMM_GEN_EXTRA_DEFS_STATIC)",
"#if 0",
)
replace_in_file(self,
os.path.join(self.source_folder, "tools",
"extra_defs_gen", "generate_extra_defs.h"),
"#if defined (_MSC_VER) && !defined (GLIBMM_GEN_EXTRA_DEFS_STATIC)",
"#if 0",
)

# when using cpp_std=c++NM 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
files.replace_in_file(self, meson_build, "cpp_std=c++", "cpp_std=vc++")
replace_in_file(self, meson_build, "cpp_std=c++", "cpp_std=vc++")

def configure(self):
if self.options.shared:
Expand All @@ -121,51 +142,26 @@ def configure(self):

def build(self):
self._patch_sources()
with tools.environment_append(tools.RunEnvironment(self).vars):
meson = self._configure_meson()
meson.build()

def _configure_meson(self):
meson = Meson(self)
defs = {
"build-examples": "false",
"build-documentation": "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
meson.configure()
meson.build()

def package(self):
self.copy("COPYING", dst="licenses", src=self._source_subfolder)
meson = self._configure_meson()
def rename_msvc_static_libs():
lib_folder = os.path.join(self.package_folder, "lib")
rename(self, os.path.join(lib_folder, f"libglibmm-{self._abi_version}.a"), os.path.join(lib_folder, f"{self._glibmm_lib}.lib"))
rename(self, os.path.join(lib_folder, f"libgiomm-{self._abi_version}.a"), os.path.join(lib_folder, f"{self._giomm_lib}.lib"))
rename(self, os.path.join(lib_folder, f"libglibmm_generate_extra_defs-{self._abi_version}.a"), os.path.join(lib_folder, f"glibmm_generate_extra_defs-{self._abi_version}.lib"))

meson = Meson(self)
meson.install()

if microsoft.is_msvc(self):
files.rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))
copy(self, "COPYING", self.source_folder, os.path.join(self.package_folder, "licenses"))

if is_msvc(self):
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))
if not self.options.shared:
files.rename(
self,
os.path.join(self.package_folder, "lib", f"libglibmm-{self._abi_version}.a"),
os.path.join(self.package_folder, "lib", f"{self._glibmm_lib}.lib")
)
files.rename(
self,
os.path.join(self.package_folder, "lib", f"libgiomm-{self._abi_version}.a"),
os.path.join(self.package_folder, "lib", f"{self._giomm_lib}.lib")
)
files.rename(
self,
os.path.join(self.package_folder, "lib", f"libglibmm_generate_extra_defs-{self._abi_version}.a"),
os.path.join(self.package_folder, "lib", f"glibmm_generate_extra_defs-{self._abi_version}.lib"),
)
rename_msvc_static_libs()

for directory in [self._glibmm_lib, self._giomm_lib]:
directory_path = os.path.join(self.package_folder, "lib", directory, "include", "*.h")
Expand All @@ -176,7 +172,7 @@ def package(self):
)

for dir_to_remove in ["pkgconfig", self._glibmm_lib, self._giomm_lib]:
files.rmdir(self, os.path.join(self.package_folder, "lib", dir_to_remove))
rmdir(self, os.path.join(self.package_folder, "lib", dir_to_remove))

def package_info(self):
glibmm_component = f"glibmm-{self._abi_version}"
Expand All @@ -193,7 +189,7 @@ def package_info(self):

self.cpp_info.components[giomm_component].set_property("pkg_config_name", giomm_component)
self.cpp_info.components[giomm_component].libs = [giomm_component]
self.cpp_info.components[giomm_component].includedirs = [ os.path.join("include", giomm_component)]
self.cpp_info.components[giomm_component].includedirs = [os.path.join("include", giomm_component)]
self.cpp_info.components[giomm_component].requires = [glibmm_component, "glib::gio-2.0"]

def package_id(self):
Expand Down

0 comments on commit c463312

Please sign in to comment.