Skip to content

Commit

Permalink
glibmm: drop static build support
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Dec 28, 2023
1 parent 189939d commit 3b508b3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 421 deletions.
14 changes: 0 additions & 14 deletions recipes/glibmm/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,3 @@ sources:
"2.66.4":
url: "https://download.gnome.org/sources/glibmm/2.66/glibmm-2.66.4.tar.xz"
sha256: "199ace5682d81b15a1d565480b4a950682f2db6402c8aa5dd7217d71edff81d5"

patches:
"2.75.0":
- 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/fix_initialization_order_fiasco_2_72_1.patch"
patch_type: bugfix
patch_description: fix initialization order for static library
"2.66.4":
- patch_file: "patches/fix_initialization_order_fiasco_2_66_4.patch"
patch_type: bugfix
patch_description: fix initialization order for static library
72 changes: 7 additions & 65 deletions recipes/glibmm/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import os
import glob
import os
import shutil

from conan import ConanFile, conan_version
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
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.files import copy, get, replace_in_file, rm, rmdir
from conan.tools.gnu import PkgConfigDeps
from conan.tools.layout import basic_layout
from conan.tools.meson import Meson, MesonToolchain
Expand All @@ -33,16 +24,8 @@ class GlibmmConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
description = "glibmm is a C++ API for parts of glib that are useful for C++."
topics = ("giomm",)
package_type = "library"
package_type = "shared-library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}
short_paths = True

@property
Expand All @@ -57,18 +40,8 @@ def _glibmm_lib(self):
def _giomm_lib(self):
return f"giomm-{self._abi_version}"

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")
wildcard = "" if conan_version.major == 1 else "/*"
self.options[f"glib{wildcard}"].shared = True
self.options["glib"].shared = True

def layout(self):
basic_layout(self, src_folder="src")
Expand All @@ -82,24 +55,19 @@ def requirements(self):

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
if self._abi_version == "2.68":
if Version(self._abi_version) >= "2.68":
check_min_cppstd(self, 17)
else:
check_min_cppstd(self, 11)

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

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

if not self.options.shared and Version(self.version) >= "2.78":
# The project does not support static builds out of the box
# and extensive patching is required, including at the source code level.
raise ConanInvalidConfiguration("Static builds are not supported")

def build_requirements(self):
self.tool_requires("meson/1.3.1")
if not self.conf.get("tools.gnu:pkg_config", check_type=str):
Expand All @@ -124,30 +92,15 @@ def generate(self):
tc.generate()

def _patch_sources(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:
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
replace_in_file(self, meson_build, "cpp_std=c++", "cpp_std=vc++")
if not self.options.shared:
replace_in_file(self, os.path.join(self.source_folder, "glib", "glibmmconfig.h.meson"),
"# define GLIBMM_DLL 1", "# define GLIBMM_DLL 0")
replace_in_file(self, os.path.join(self.source_folder, "glib", "meson.build"),
"error('Static builds are not supported by MSVC-style builds')", "")

def build(self):
self._patch_sources()
Expand All @@ -156,24 +109,13 @@ def build(self):
meson.build()

def package(self):
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()

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:
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 Down

This file was deleted.

Loading

0 comments on commit 3b508b3

Please sign in to comment.