Skip to content

Commit

Permalink
(conan-io#14930) Glibmm v2 toolchain
Browse files Browse the repository at this point in the history
* [glibmm] add version 2.74.0

* [glibmm] update meson toolchain

* [glibmm] update test packages

* [glibmm] fix libsigcpp component requires

* [glibmm] add v1 test package

* [glibmm] disable static builds on msvc

* [glibmm] bump glib version

* Update recipes/glibmm/all/conanfile.py

Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>

* Update recipes/glibmm/all/conanfile.py

Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>

* [glibmm] add 2.75.0

* [glibmm] add and document patches for 2.75.0

* Update recipes/glibmm/all/conanfile.py

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* [glibmm] enable cross compilation

* [glibmm] reorder methods

* [glibmm] review suggestions

---------

Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
3 people authored and sabelka committed Feb 12, 2023
1 parent 8ae9d69 commit cce786a
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 127 deletions.
22 changes: 18 additions & 4 deletions recipes/glibmm/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"2.75.0":
url: "https://download.gnome.org/sources/glibmm/2.75/glibmm-2.75.0.tar.xz"
sha256: "60bb12e66488aa8ce41f0eb2f3612f89f5ddc887e3e4d45498524bf60b266b3d"
"2.72.1":
url: "https://download.gnome.org/sources/glibmm/2.72/glibmm-2.72.1.tar.xz"
sha256: "2a7649a28ab5dc53ac4dabb76c9f61599fbc628923ab6a7dd74bf675d9155cd8"
Expand All @@ -7,13 +10,24 @@ sources:
sha256: "199ace5682d81b15a1d565480b4a950682f2db6402c8aa5dd7217d71edff81d5"

patches:
"2.75.0":
- patch_file: "patches/enable_static_libs_2_75_0.patch"
patch_type: portability
patch_description: enable static library build for msvc
- patch_file: "patches/fix_initialization_order_fiasco_2_75_0.patch"
patch_type: bugfix
patch_description: fix initialization order for static library
"2.72.1":
- patch_file: "patches/enable_static_libs_2_72_1.patch"
base_path: "source_subfolder"
patch_type: portability
patch_description: enable static library build for msvc
- patch_file: "patches/fix_initialization_order_fiasco_2_72_1.patch"
base_path: "source_subfolder"
patch_type: bugfix
patch_description: fix initialization order for static library
"2.66.4":
- patch_file: "patches/enable_static_libs_2_66_4.patch"
base_path: "source_subfolder"
patch_type: portability
patch_description: enable static library build for msvc
- patch_file: "patches/fix_initialization_order_fiasco_2_66_4.patch"
base_path: "source_subfolder"
patch_type: bugfix
patch_description: fix initialization order for static library
216 changes: 103 additions & 113 deletions recipes/glibmm/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@
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.apple import fix_apple_shared_install_name
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,
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 @@ -25,14 +36,11 @@ class GlibmmConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

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

@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 @@ -42,130 +50,120 @@ def _glibmm_lib(self):
def _giomm_lib(self):
return f"giomm-{self._abi_version}"

def validate(self):
if hasattr(self, "settings_build") and build.cross_building(self):
raise ConanInvalidConfiguration("Cross-building not implemented")
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:
self.options.rm_safe("fPIC")
if self.options.shared:
self.options["glib"].shared = True

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

def requirements(self):
self.requires("glib/2.75.2")
if self._abi_version == "2.68":
self.requires("libsigcpp/3.0.7")
else:
self.requires("libsigcpp/2.10.8")

def package_id(self):
if not self.dependencies["glib"].options.shared:
self.info.requires["glib"].full_package_mode()

def validate(self):
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:
if self.options.shared and not self.dependencies["glib"].options.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):
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
if self.dependencies["glib"].options.shared and is_msvc_static_runtime(self):
raise ConanInvalidConfiguration("Linking shared glib with the MSVC static runtime is not supported")

def build_requirements(self):
self.build_requires("meson/0.64.1")
self.build_requires("pkgconf/1.9.3")
self.tool_requires("meson/1.0.0")
if not self.conf.get("tools.gnu:pkg_config", check_type=str):
self.tool_requires("pkgconf/1.9.3")

def requirements(self):
self.requires("glib/2.75.0")
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

if self._abi_version == "2.68":
self.requires("libsigcpp/3.0.7")
else:
self.requires("libsigcpp/2.10.8")
def generate(self):
env = VirtualBuildEnv(self)
env.generate()

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

tc = MesonToolchain(self)
tc.project_options.update({
"build-examples": "false",
"build-documentation": "false",
"msvc14x-parallel-installable": "false"
})
tc.generate()

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++")

def configure(self):
if self.options.shared:
del self.options.fPIC
if self.options.shared:
self.options["glib"].shared = True
replace_in_file(self, meson_build, "cpp_std=c++", "cpp_std=vc++")

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,26 +174,18 @@ 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))
fix_apple_shared_install_name(self)

def package_info(self):
glibmm_component = f"glibmm-{self._abi_version}"
giomm_component = f"giomm-{self._abi_version}"

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

if self._abi_version == "2.68":
self.cpp_info.components[glibmm_component].requires = ["glib::gobject-2.0", "libsigcpp::sigc++"]
else:
self.cpp_info.components[glibmm_component].requires = ["glib::gobject-2.0", "libsigcpp::sigc++-2.0"]

giomm_component = f"giomm-{self._abi_version}"
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):
if not self.options["glib"].shared:
self.info.requires["glib"].full_package_mode()
32 changes: 32 additions & 0 deletions recipes/glibmm/all/patches/enable_static_libs_2_75_0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/glib/glibmmconfig.h.meson b/glib/glibmmconfig.h.meson
index ef4753d7..b926720b 100644
--- a/glib/glibmmconfig.h.meson
+++ b/glib/glibmmconfig.h.meson
@@ -27,7 +27,9 @@
# if defined(_MSC_VER)
# define GLIBMM_MSC 1
# define GLIBMM_WIN32 1
-# define GLIBMM_DLL 1
+# ifndef GLIBMM_STATIC_LIB
+# define GLIBMM_DLL 1
+# endif
# elif defined(__CYGWIN__)
# define GLIBMM_CONFIGURE 1
# elif defined(__MINGW32__)
diff --git a/glib/meson.build b/glib/meson.build
index d16621e9..3eb8bc47 100644
--- a/glib/meson.build
+++ b/glib/meson.build
@@ -37,12 +37,6 @@ pkg_conf_data.set('MSVC_TOOLSET_VER', msvc14x_toolset_ver)

library_build_type = get_option('default_library')

-if cpp_compiler.get_argument_syntax() == 'msvc'
- if library_build_type == 'static' or library_build_type == 'both'
- error('Static builds are not supported by MSVC-style builds')
- endif
-endif
-
if library_build_type == 'static'
pkg_conf_data.set('GLIBMM_STATIC_LIB', 1)
pkg_conf_data.set('GIOMM_STATIC_LIB', 1)
Loading

0 comments on commit cce786a

Please sign in to comment.