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

Glibmm v2 toolchain #14930

Merged
merged 15 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
7 changes: 3 additions & 4 deletions recipes/glibmm/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"2.74.0":
url: "https://download.gnome.org/sources/glibmm/2.74/glibmm-2.74.0.tar.xz"
sha256: "2b472696cbac79db8e405724118ec945219c5b9b18af63dc8cfb7f1d89b0f1fa"
"2.72.1":
url: "https://download.gnome.org/sources/glibmm/2.72/glibmm-2.72.1.tar.xz"
sha256: "2a7649a28ab5dc53ac4dabb76c9f61599fbc628923ab6a7dd74bf675d9155cd8"
Expand All @@ -9,11 +12,7 @@ sources:
patches:
"2.72.1":
- patch_file: "patches/enable_static_libs_2_72_1.patch"
base_path: "source_subfolder"
- patch_file: "patches/fix_initialization_order_fiasco_2_72_1.patch"
base_path: "source_subfolder"
"2.66.4":
- patch_file: "patches/enable_static_libs_2_66_4.patch"
base_path: "source_subfolder"
- patch_file: "patches/fix_initialization_order_fiasco_2_66_4.patch"
base_path: "source_subfolder"
170 changes: 84 additions & 86 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, cross_building
planetmarshall marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -43,129 +51,118 @@ 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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should work now with MesonToolchain. It was a limitation of the legacy Meson build helper.


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 is_msvc(self) and not self.options.shared:
raise ConanInvalidConfiguration("Static library build is not supported by MSVC")
planetmarshall marked this conversation as resolved.
Show resolved Hide resolved

if self.options.shared and not self.options["glib"].shared:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"
if self.options["glib"].shared and is_msvc_static_runtime(self):
planetmarshall marked this conversation as resolved.
Show resolved Hide resolved
raise ConanInvalidConfiguration("Linking shared glib with the MSVC static runtime is not supported")

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/1.0.0")
self.tool_requires("pkgconf/1.9.3")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.tool_requires("pkgconf/1.9.3")
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")

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 generate(self):
planetmarshall marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def generate(self):
def generate(self):
env = VirtualBuildEnv(self)
env.generate()

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"default_library": "shared" if self.options.shared else "static"

already managed by MesonToolchain

})
tc.generate()

env = VirtualBuildEnv(self)
env.generate()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 export_sources(self):
planetmarshall marked this conversation as resolved.
Show resolved Hide resolved
export_conandata_patches(self)

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):
Copy link
Contributor

@SpaceIm SpaceIm Feb 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configure() appears so late when you read this recipe from top to bottom, with a logic to change glib shared option.
I wouldn't be against reordering of methods by order of execution: https://docs.conan.io/en/latest/reference/commands/creator/create.html#methods-execution-order
It's super hard to follow global logic of this recipe.

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

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 +173,8 @@ 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))
planetmarshall marked this conversation as resolved.
Show resolved Hide resolved
fix_apple_shared_install_name(self)

def package_info(self):
glibmm_component = f"glibmm-{self._abi_version}"
Expand All @@ -189,11 +187,11 @@ def package_info(self):
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"]
self.cpp_info.components[glibmm_component].requires = ["glib::gobject-2.0", "libsigcpp::libsigcpp"]
Copy link
Contributor

@SpaceIm SpaceIm Feb 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at libsigcpp recipe, this branching shouldn't exist, it should always be self.cpp_info.components[glibmm_component].requires = ["glib::gobject-2.0", "libsigcpp::libsigcpp"]. Existence of a component in libsigcpp recipe is (or was) just a trick for target name of legacy cmake_find_package*.


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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't review the line below, but there is a if not self.options["glib"].shared here to replace by if not self.dependencies["glib"].options.shared

Expand Down
7 changes: 2 additions & 5 deletions recipes/glibmm/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
cmake_minimum_required(VERSION 3.6)
project(test_package)

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

find_package(glibmm REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)

if (TARGET glibmm::glibmm-2.68)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)
target_link_libraries(${PROJECT_NAME} glibmm::glibmm-2.68 glibmm::giomm-2.68)
target_link_libraries(${PROJECT_NAME} PRIVATE glibmm::glibmm-2.68 glibmm::giomm-2.68)
else()
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
target_link_libraries(${PROJECT_NAME} glibmm::glibmm-2.4 glibmm::giomm-2.4)
target_link_libraries(${PROJECT_NAME} PRIVATE glibmm::glibmm-2.4 glibmm::giomm-2.4)
endif()

21 changes: 16 additions & 5 deletions recipes/glibmm/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake
from conan.tools.layout import cmake_layout

import os


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

def layout(self):
cmake_layout(self)

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 can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/glibmm/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/)
17 changes: 17 additions & 0 deletions recipes/glibmm/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

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)
2 changes: 2 additions & 0 deletions recipes/glibmm/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"2.74.0":
folder: "all"
"2.72.1":
folder: "all"
"2.66.4":
Expand Down