Repository: conan-io/conan-center-index

Issue:
[package] gtk/4.4.0: shared option does not work
<!-- 
  Please don't forget to update the issue title.
  Include all applicable information to help us reproduce your problem.
-->

The gtk/4.4.0 package has only a .so library even with shared=False

### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **gtk/4.4.0**
  * Operating System+version: **Linux Ubuntu 20.04**
  * Compiler+version: **GCC 9**
  * Conan version: **conan 1.47.0**
  * Python version: **Python 3.8.10**


### Conan profile (output of `conan profile show default` or `conan profile show <profile>` if custom profile is in use)
```
Configuration for profile default:

[settings]
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=9
compiler.libcxx=libstdc++
build_type=Release
[options]
[conf]
[build_requires]
[env]
```


### Steps to reproduce (Include if Applicable)
First install gtk/4.4.0
```
conan install gtk/4.4.0@ --build=gtk --build=graphene -g txt -o gtk:shared=False # graphene is built to fix undefined reference to __atan2f_finite
```

Second, find the libpath of gtk from conanbuildinfo.txt, and inspect the path:
```
ls /home/zhaoquan/.conan/data/gtk/4.4.0/_/_/package/5c17355d7562eb3e21680750e9c180893d53bca6/lib
```

We can see that the lib directory has only .so but no .a, which means the libraries are all shared.
```
gtk-4.0  libgtk-4.so  libgtk-4.so.1  libgtk-4.so.1.400.0
```


### Logs (Include/Attach if Applicable)
N/A


Discussion:

Resolving patch:
diff --git a/recipes/gtk/all/conanfile.py b/recipes/gtk/all/conanfile.py
--- a/recipes/gtk/all/conanfile.py
+++ b/recipes/gtk/all/conanfile.py
@@ -38,6 +38,8 @@ class GtkConan(ConanFile):
         "with_cloudprint": False
     }
 
+    short_paths = True
+
     @property
     def _source_subfolder(self):
         return "source_subfolder"
@@ -49,14 +51,26 @@ def _build_subfolder(self):
     @property
     def _gtk4(self):
         return tools.Version("4.0.0") <= tools.Version(self.version) < tools.Version("5.0.0")
-    @property
 
+    @property
     def _gtk3(self):
         return tools.Version("3.0.0") <= tools.Version(self.version) < tools.Version("4.0.0")
 
+    def export_sources(self):
+        for patch in self.conan_data.get("patches", {}).get(self.version, []):
+            self.copy(patch["patch_file"])
+
     def config_options(self):
         if self.settings.os == "Windows":
             del self.options.fPIC
+            # Fix duplicate definitions of DllMain
+            self.options["gdk-pixbuf"].shared = True
+            # Fix segmentation fault
+            self.options["cairo"].shared = True
+        if tools.Version(self.version) >= "4.1.0":
+            # The upstream meson file does not create a static library
+            # See https://github.com/GNOME/gtk/commit/14f0a0addb9a195bad2f8651f93b95450b186bd6
+            self.options.shared = True
         if self.settings.os != "Linux":
             del self.options.with_wayland
             del self.options.with_x11
@@ -64,6 +78,16 @@ def config_options(self):
     def validate(self):
         if self.settings.compiler == "gcc" and tools.Version(self.settings.compiler.version) < "5":
             raise ConanInvalidConfiguration("this recipes does not support GCC before version 5. contributions are welcome")
+        if str(self.settings.compiler) in ["Visual Studio", "msvc"]:
+            if tools.Version(self.version) < "4.2":
+                raise ConanInvalidConfiguration("MSVC support of this recipe requires at least gtk/4.2")
+            if not self.options["gdk-pixbuf"].shared:
+                raise ConanInvalidConfiguration("MSVC build requires shared gdk-pixbuf")
+            if not self.options["cairo"].shared:
+                raise ConanInvalidConfiguration("MSVC build requires shared cairo")
+        if tools.Version(self.version) >= "4.1.0":
+            if not self.options.shared:
+                raise ConanInvalidConfiguration("gtk supports only shared since 4.1.0")
 
     def configure(self):
         if self.options.shared:
@@ -74,42 +98,46 @@ def configure(self):
             if self.options.with_wayland or self.options.with_x11:
                 if not self.options.with_pango:
                     raise ConanInvalidConfiguration("with_pango option is mandatory when with_wayland or with_x11 is used")
-        if self.settings.os == "Windows":
-            raise ConanInvalidConfiguration("GTK recipe is not yet compatible with Windows. Contributions are welcome.")
 
     def build_requirements(self):
-        self.build_requires("meson/0.59.1")
+        self.build_requires("meson/0.61.2")
+        if self._gtk4:
+            self.build_requires("libxml2/2.9.13") # for xmllint
         self.build_requires("pkgconf/1.7.4")
         if self._gtk4:
             self.build_requires("sassc/3.6.2")
 
     def requirements(self):
-        self.requires("gdk-pixbuf/2.42.4")
-        self.requires("glib/2.69.3")
-        if self.settings.compiler != "Visual Studio":
+        self.requires("gdk-pixbuf/2.42.6")
+        self.requires("glib/2.72.0")
+        if self._gtk4 or self.settings.compiler != "Visual Studio":
             self.requires("cairo/1.17.4")
         if self._gtk4:
-            self.requires("graphene/1.10.6")
+            self.requires("graphene/1.10.8")
+            self.requires("fribidi/1.0.12")
+            self.requires("libpng/1.6.37")
+            self.requires("libtiff/4.3.0")
+            self.requires("libjpeg/9d")
         if self.settings.os == "Linux":
             if self._gtk4:
-                self.requires("xkbcommon/1.3.1")
+                self.requires("xkbcommon/1.4.0")
             if self._gtk3:
                 self.requires("at-spi2-atk/2.38.0")
             if self.options.with_wayland:
                 if self._gtk3:
-                    self.requires("xkbcommon/1.3.1")
-                self.requires("wayland/1.19.0")
+                    self.requires("xkbcommon/1.4.0")
+                self.requires("wayland/1.20.0")
             if self.options.with_x11:
                 self.requires("xorg/system")
         if self._gtk3:
-            self.requires("atk/2.36.0")
-        self.requires("libepoxy/1.5.9")
+            self.requires("atk/2.38.0")
+        self.requires("libepoxy/1.5.10")
         if self.options.with_pango:
-            self.requires("pango/1.49.1")
+            self.requires("pango/1.50.7")
         if self.options.with_ffmpeg:
-            self.requires("ffmpeg/4.2.1")
+            self.requires("ffmpeg/5.0")
         if self.options.with_gstreamer:
-            self.requires("gstreamer/1.19.1")
+            self.requires("gstreamer/1.19.2")
 
     def source(self):
         tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
@@ -121,8 +149,8 @@ def _configure_meson(self):
             defs["wayland_backend" if self._gtk3 else "wayland-backend"] = "true" if self.options.with_wayland else "false"
             defs["x11_backend" if self._gtk3 else "x11-backend"] = "true" if self.options.with_x11 else "false"
         defs["introspection"] = "false" if self._gtk3 else "disabled"
-        defs["documentation"] = "false"
-        defs["man-pages"] = "false"
+        defs["gtk_doc"] = "false"
+        defs["man-pages" if self._gtk4 else "man"] = "false"
         defs["tests" if self._gtk3 else "build-tests"] = "false"
         defs["examples" if self._gtk3 else "build-examples"] = "false"
         defs["demos"] = "false"
@@ -135,19 +163,26 @@ def _configure_meson(self):
             defs["media-ffmpeg"] = enabled_disabled(self.options.with_ffmpeg)
             defs["media-gstreamer"] = enabled_disabled(self.options.with_gstreamer)
             defs["print-cups"] = enabled_disabled(self.options.with_cups)
-            defs["print-cloudprint"] = enabled_disabled(self.options.with_cloudprint)
+            if tools.Version(self.version) < "4.3.2":
+                defs["print-cloudprint"] = enabled_disabled(self.options.with_cloudprint)
         args=[]
         args.append("--wrap-mode=nofallback")
         meson.configure(defs=defs, build_folder=self._build_subfolder, source_folder=self._source_subfolder, pkg_config_paths=[self.install_folder], args=args)
         return meson
 
     def build(self):
+        for patch in self.conan_data.get("patches", {}).get(self.version, []):
+            tools.patch(**patch)
         if self._gtk3:
             tools.replace_in_file(os.path.join(self._source_subfolder, "meson.build"), "\ntest(\n", "\nfalse and test(\n")
-        if tools.Version(self.version) >= "4.2.0":
+        if "4.2.0" <= tools.Version(self.version) < "4.6.1":
             tools.replace_in_file(os.path.join(self._source_subfolder, "meson.build"),
                                   "gtk_update_icon_cache: true",
                                   "gtk_update_icon_cache: false")
+        if "4.6.2" <= tools.Version(self.version):
+            tools.replace_in_file(os.path.join(self._source_subfolder, "meson.build"),
+                                  "dependency(is_msvc_like ? ",
+                                  "dependency(false ? ")
         with tools.environment_append(tools.RunEnvironment(self).vars):
             meson = self._configure_meson()
             meson.build()
@@ -162,6 +197,8 @@ def package(self):
 
         self.copy(pattern="COPYING", src=self._source_subfolder, dst="licenses")
         tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
+        tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.pdb")
+        tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.pdb")
 
     def package_info(self):
         if self._gtk3:


Test patch: