Repository: conan-io/conan-center-index

Issue:
[bug] libidn wrong include path with VS2019 community edition
<!--
  Please don't forget to update the issue title.
  Include all applicable information to help us reproduce your problem.

  To help us debug your issue please explain:
-->

### Environment Details (include every applicable attribute)
  * Operating System+version: Windows 11
  * Compiler+version: Visual Studio 2019 Professional
  * Conan version: 1.44.1
  * Python version: 3.8.2

### Steps to reproduce (Include if Applicable)
Because podofo windows build is not provided by conancenter, so I want to build podofo on Windows with VS2019 Pro.
This is my content for conanfile.txt
```
[requires]
podofo/0.9.7

[options]
libtiff:jpeg=libjpeg-turbo
podofo:with_unistring=False
```
Then run this command
``` 
conan install conanfile.txt --build=podofo 
```
The build will fail because of libidn's header file has absolution file path of VS2019 community edition installed in C drive.
> <CONAN_USER_HOME>\.conan\data\libidn\1.36\_\_\package\256bf2ed7b116fe3adc0084e84ec6681a73e3e72\include\idn-int.h
```
  /* Some pre-C++11 <stdint.h> implementations need this.  */
# ifdef __cplusplus
#  ifndef __STDC_CONSTANT_MACROS
#   define __STDC_CONSTANT_MACROS 1
#  endif
#  ifndef __STDC_LIMIT_MACROS
#   define __STDC_LIMIT_MACROS 1
#  endif
# endif

  /* Other systems may have an incomplete or buggy <stdint.h>.
     Include it before <inttypes.h>, since any "#include <stdint.h>"
     in <inttypes.h> would reinclude us, skipping our contents because
     _GL_LGL_STDINT_H is defined.
     The include requires a split double-inclusion guard.  */
# include "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\stdint.h"
#endif
```

### Logs (Executed commands with output) (Include/Attach if Applicable)
conan build output
```
  PdfFileStream.cpp
***\.conan\data\libidn\1.36\_\_\package\256bf2ed7b116fe3adc0084e84ec6681a73e3e72\include\idn-int.h(77,11): fatal error C1083: Cannot open file: “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\
VC\Tools\MSVC\14.28.29333\include\stdint.h”: No such file or directory (Compiling source file ***\.conan\data\podofo\0.9.7\_\_\build\1504830c7867f1dfb999d969cda5322488d45e4a\source_subfolder\src\podofo\base\PdfEncry
pt.cpp) [***\.conan\data\podofo\0.9.7\_\_\build\1504830c7867f1dfb999d969cda5322488d45e4a\build_subfolder\source_subfolder\src\podofo\podofo_static.vcxproj]
```



Discussion:
This seems to be a recipe issue, from the ConanCenter repo, so moving it to ``conan-center-index`` repo. Thanks for reporting.
Ok there are 2 issues:
- podofo default options raise indirectly for Visual Studio (due to lack of msvc support in libunistring recipe), and it's not good.
- there are include issues in your build, so here it would be nice to share  your profile and the full build log.
> include "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\stdint.h

What a mess, libidn hardcodes at build time the path of local SDK in a public header, so it's not relocatable.
@madebr Any idea to fix this issue?

Resolving patch:
diff --git a/recipes/libidn/all/conanfile.py b/recipes/libidn/all/conanfile.py
--- a/recipes/libidn/all/conanfile.py
+++ b/recipes/libidn/all/conanfile.py
@@ -1,6 +1,7 @@
 from conans import AutoToolsBuildEnvironment, ConanFile, tools
 from conans.errors import ConanInvalidConfiguration
-from contextlib import contextmanager
+import contextlib
+import functools
 import os
 
 required_conan_version = ">=1.33.0"
@@ -13,6 +14,7 @@ class LibIdnConan(ConanFile):
     topics = ("libidn", "encode", "decode", "internationalized", "domain", "name")
     license = "GPL-3.0-or-later"
     url = "https://github.com/conan-io/conan-center-index"
+    settings = "os", "arch", "compiler", "build_type"
     options = {
         "shared": [True, False],
         "fPIC": [True, False],
@@ -23,9 +25,6 @@ class LibIdnConan(ConanFile):
         "fPIC": True,
         "threads": True,
     }
-    settings = "os", "arch", "compiler", "build_type"
-
-    _autotools = None
 
     @property
     def _source_subfolder(self):
@@ -35,6 +34,10 @@ def _source_subfolder(self):
     def _settings_build(self):
         return getattr(self, "settings_build", self.settings)
 
+    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
@@ -62,7 +65,7 @@ def source(self):
         tools.get(**self.conan_data["sources"][self.version],
                   destination=self._source_subfolder, strip_root=True)
 
-    @contextmanager
+    @contextlib.contextmanager
     def _build_context(self):
         if self.settings.compiler == "Visual Studio":
             with tools.vcvars(self):
@@ -77,17 +80,16 @@ def _build_context(self):
         else:
             yield
 
+    @functools.lru_cache(1)
     def _configure_autotools(self):
-        if self._autotools:
-            return self._autotools
-        self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
-        self._autotools.libs = []
+        autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
+        autotools.libs = []
         if not self.options.shared:
-            self._autotools.defines.append("LIBIDN_STATIC")
+            autotools.defines.append("LIBIDN_STATIC")
         if self.settings.compiler == "Visual Studio":
             if tools.Version(self.settings.compiler.version) >= "12":
-                self._autotools.flags.append("-FS")
-            self._autotools.link_flags.extend("-L{}".format(p.replace("\\", "/")) for p in self.deps_cpp_info.lib_paths)
+                autotools.flags.append("-FS")
+            autotools.link_flags.extend("-L{}".format(p.replace("\\", "/")) for p in self.deps_cpp_info.lib_paths)
         yes_no = lambda v: "yes" if v else "no"
         conf_args = [
             "--enable-shared={}".format(yes_no(self.options.shared)),
@@ -97,10 +99,12 @@ def _configure_autotools(self):
             "--disable-nls",
             "--disable-rpath",
         ]
-        self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder)
-        return self._autotools
+        autotools.configure(args=conf_args, configure_dir=self._source_subfolder)
+        return autotools
 
     def build(self):
+        for patch in self.conan_data.get("patches", {}).get(self.version, []):
+            tools.patch(**patch)
         if self.settings.compiler == "Visual Studio":
             if self.settings.arch in ("x86_64", "armv8", "armv8.3"):
                 ssize = "signed long long int"


Test patch: