Repository: conan-io/conan-center-index

Issue:
[package] Libgd build breaks when with_png=true on linux
# Libgd build breaks when with_png=true on linux

## Problem description
It seems like the build definition is unconditionally depending on `getopt-for-visual-studio/20200201` if `with_png` is enabled:
https://github.com/conan-io/conan-center-index/blob/7c3f81b16596a01e9d4785d98f996dd367901524/recipes/libgd/all/conanfile.py#L58

Looking at the recipe for `getopt-for-visual-studio`, it seems to just raise an exception if the compiler is not Visual Studio:
https://github.com/conan-io/conan-center-index/blob/7c3f81b16596a01e9d4785d98f996dd367901524/recipes/getopt-for-visual-studio/all/conanfile.py#L17-L18

Thus, I think a simple fix to the problem is to only add this dependency in the libgd recipe with the inverse condition of configure function in getopt-for-visual-studio:
```python
    def requirements(self):
        ...
        if self.options.with_png:
            self.requires("libpng/1.6.37")
            if self.settings.compiler == "Visual Studio":
                self.requires("getopt-for-visual-studio/20200201")
        ...
```

## System information
Conan version: 1.51.0
Operating system: Ubuntu 18.04 running on WSL
Compiler: GCC 7.4.0

## How to reproduce (in principle):
- Use any profile that's not visual studio, and a clean conan index.
- Run `conan install libgd/2.3.2@ -o libgd:with_png=True --build=missing`

You should then see the following error:
```
ERROR: getopt-for-visual-studio/20200201: Invalid configuration: getopt-for-visual-studio is only supported for Visual Studio
```

I expect that this error should not show up, as I'm not on a Visual Studio compiler.



Discussion:

Resolving patch:
diff --git a/recipes/libgd/all/conanfile.py b/recipes/libgd/all/conanfile.py
--- a/recipes/libgd/all/conanfile.py
+++ b/recipes/libgd/all/conanfile.py
@@ -1,7 +1,11 @@
-from conans import ConanFile, tools, CMake
+from conan import ConanFile
+from conan.tools.microsoft import is_msvc
+from conans import CMake
+from conan.tools.files import get, patch, replace_in_file, rmdir, collect_libs
+from conan.tools.scm import Version
 import os
 
-required_conan_version = ">=1.33.0"
+required_conan_version = ">=1.47.0"
 
 
 class LibgdConan(ConanFile):
@@ -52,39 +56,41 @@ def configure(self):
             del self.options.fPIC
 
     def requirements(self):
-        self.requires("zlib/1.2.11")
+        self.requires("zlib/1.2.12")
         if self.options.with_png:
             self.requires("libpng/1.6.37")
-            self.requires("getopt-for-visual-studio/20200201")
+            if is_msvc(self):
+                self.requires("getopt-for-visual-studio/20200201")
         if self.options.with_jpeg:
             self.requires("libjpeg/9d")
         if self.options.with_tiff:
-            self.requires("libtiff/4.3.0")
+            self.requires("libtiff/4.4.0")
         if self.options.with_freetype:
-            self.requires("freetype/2.11.0")
+            self.requires("freetype/2.12.1")
 
     def source(self):
-        tools.get(**self.conan_data["sources"][self.version],
-                  destination=self._source_subfolder, strip_root=True)
+        get(self, **self.conan_data["sources"][self.version],
+            destination=self._source_subfolder, strip_root=True)
 
     def _patch(self):
-        for patch in self.conan_data.get("patches", {}).get(self.version, []):
-            tools.patch(**patch)
+        for patch_file in self.conan_data.get("patches", {}).get(self.version, []):
+            patch(self, **patch_file)
         cmakelists = os.path.join(self._source_subfolder, "CMakeLists.txt")
-        tools.replace_in_file(cmakelists, "${CMAKE_SOURCE_DIR}", "${CMAKE_CURRENT_SOURCE_DIR}")
-        tools.replace_in_file(cmakelists,
-                              "SET(CMAKE_MODULE_PATH \"${GD_SOURCE_DIR}/cmake/modules\")",
-                              "LIST(APPEND CMAKE_MODULE_PATH \"${GD_SOURCE_DIR}/cmake/modules\")")
-        tools.replace_in_file(os.path.join(self._source_subfolder, "src", "CMakeLists.txt"),
-                              "RUNTIME DESTINATION bin",
-                              "RUNTIME DESTINATION bin BUNDLE DESTINATION bin")
+        replace_in_file(self, cmakelists, "${CMAKE_SOURCE_DIR}",
+                        "${CMAKE_CURRENT_SOURCE_DIR}")
+        replace_in_file(self, cmakelists,
+                        "SET(CMAKE_MODULE_PATH \"${GD_SOURCE_DIR}/cmake/modules\")",
+                        "LIST(APPEND CMAKE_MODULE_PATH \"${GD_SOURCE_DIR}/cmake/modules\")")
+        replace_in_file(self, os.path.join(self._source_subfolder, "src", "CMakeLists.txt"),
+                        "RUNTIME DESTINATION bin",
+                        "RUNTIME DESTINATION bin BUNDLE DESTINATION bin")
 
     def _configure_cmake(self):
         if self._cmake:
             return self._cmake
         self._cmake = CMake(self)
         self._cmake.definitions["BUILD_STATIC_LIBS"] = not self.options.shared
-        if tools.Version(self.version) >= "2.3.0":
+        if Version(self.version) >= "2.3.0":
             self._cmake.definitions["ENABLE_GD_FORMATS"] = True
         self._cmake.definitions["ENABLE_PNG"] = self.options.with_png
         self._cmake.definitions["ENABLE_LIQ"] = False
@@ -95,10 +101,10 @@ def _configure_cmake(self):
         self._cmake.definitions["ENABLE_FREETYPE"] = self.options.with_freetype
         self._cmake.definitions["ENABLE_FONTCONFIG"] = False
         self._cmake.definitions["ENABLE_WEBP"] = False
-        if tools.Version(self.version) >= "2.3.2":
+        if Version(self.version) >= "2.3.2":
             self._cmake.definitions["ENABLE_HEIF"] = False
             self._cmake.definitions["ENABLE_AVIF"] = False
-        if tools.Version(self.version) >= "2.3.0":
+        if Version(self.version) >= "2.3.0":
             self._cmake.definitions["ENABLE_RAQM"] = False
         self._cmake.configure(build_folder=self._build_subfolder)
         return self._cmake
@@ -112,12 +118,12 @@ def package(self):
         self.copy("COPYING", src=self._source_subfolder, dst="licenses")
         cmake = self._configure_cmake()
         cmake.install()
-        tools.rmdir(os.path.join(self.package_folder, "share"))
-        tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
+        rmdir(self, os.path.join(self.package_folder, "share"))
+        rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
 
     def package_info(self):
         self.cpp_info.names["pkg_config"]= "gdlib"
-        self.cpp_info.libs = tools.collect_libs(self)
+        self.cpp_info.libs = collect_libs(self)
         if self.settings.os == "Windows" and not self.options.shared:
             self.cpp_info.defines.append("BGD_NONDLL")
             self.cpp_info.defines.append("BGDWIN32")


Test patch: