Repository: conan-io/conan-center-index

Issue:
[package] libcurl/7.73.0 : windows build with option  with_nghttp2=True doesn't find the  nghttp2 package

### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **libcurl/7.73.0**
  * Operating System+version: **Windows 10**
  * Compiler+version: **Visual Studio 2019**
  * Conan version: **conan 1.45.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 (profile_host):
[settings]
arch=x86_64
arch_build=x86_64
arch_target=x86_64
build_type=Debug
compiler=Visual Studio
compiler.runtime=MDd
compiler.version=16
os=Windows
os_build=Windows
os_target=Windows
[options]
[build_requires]
[env]

Configuration (profile_build):
[settings]
arch=x86_64
arch_build=x86_64
arch_target=x86_64
build_type=Debug
compiler=Visual Studio
compiler.runtime=MDd
compiler.version=16
os=Windows
os_build=Windows
os_target=Windows
[options]
[build_requires]
[env]
```


### Steps to reproduce (Include if Applicable)
create package libcurl/7.73.0 with option with_nghttp2=True

The Problem is, that CMake hits the libcurl FindNGHTTP2.cmake, which will not finde the cmake file generated by conan.

### Logs (Include/Attach if Applicable)
<details><summary>Click to expand log</summary>

```
libcurl/7.73.0: Configuring sources in R:.conan\data\libcurl\7.73.0\_\_\source
Downloading curl-7.73.0.tar.gz completed [3942.09k]

Downloading cacert.pem completed [216.23k]

libcurl/7.73.0: Copying sources to build folder
libcurl/7.73.0: Building your package in R:\.conan\data\libcurl\7.73.0\_\_\build\a4841135d52a10b44a9bf37748f0431d73cb789c
libcurl/7.73.0: Generator cmake created conanbuildinfo.cmake
libcurl/7.73.0: Generator pkg_config created libcrypto.pc
libcurl/7.73.0: Generator pkg_config created libssl.pc
libcurl/7.73.0: Generator pkg_config created openssl.pc
libcurl/7.73.0: Generator pkg_config created libnghttp2.pc
libcurl/7.73.0: Generator pkg_config created zlib.pc
libcurl/7.73.0: Generator cmake_find_package_multi created OpenSSLConfigVersion.cmake
libcurl/7.73.0: Generator cmake_find_package_multi created OpenSSLTarget-debug.cmake
libcurl/7.73.0: Generator cmake_find_package_multi created OpenSSLTargets.cmake
libcurl/7.73.0: Generator cmake_find_package_multi created OpenSSLConfig.cmake
libcurl/7.73.0: Generator cmake_find_package_multi created libnghttp2-config-version.cmake
libcurl/7.73.0: Generator cmake_find_package_multi created libnghttp2-config.cmake
libcurl/7.73.0: Generator cmake_find_package_multi created libnghttp2Targets.cmake
libcurl/7.73.0: Generator cmake_find_package_multi created libnghttp2Target-debug.cmake
libcurl/7.73.0: Generator cmake_find_package_multi created ZLIBConfigVersion.cmake
libcurl/7.73.0: Generator cmake_find_package_multi created ZLIBConfig.cmake
libcurl/7.73.0: Generator cmake_find_package_multi created ZLIBTargets.cmake
libcurl/7.73.0: Generator cmake_find_package_multi created ZLIBTarget-debug.cmake
libcurl/7.73.0: Aggregating env generators
libcurl/7.73.0: Calling build()
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.19042.
-- The C compiler identification is MSVC 19.29.30133.0
-- The CXX compiler identification is MSVC 19.29.30133.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: called by CMake conan helper
-- Conan: called inside local cache
-- Conan: Adjusting output directories
-- Conan: Using cmake global configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- curl version=[7.73.0]
-- Could NOT find Perl (missing: PERL_EXECUTABLE)
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Looking for getch in ws2_32;
-- Looking for getch in ws2_32; - found
-- Looking for getch in winmm;ws2_32
-- Looking for getch in winmm;ws2_32 - found
-- Found OpenSSL: R:/.conan/data/openssl/1.1.1l/_/_/package/d057732059ea44a47760900cb5e4855d2bea8714/lib/libcryptod.lib (found version "1.1.1l")
-- Looking for openssl/crypto.h
-- Looking for openssl/crypto.h - found
-- Looking for openssl/err.h
-- Looking for openssl/err.h - found
-- Looking for openssl/pem.h
-- Looking for openssl/pem.h - found
-- Looking for openssl/rsa.h
-- Looking for openssl/rsa.h - found
-- Looking for openssl/ssl.h
-- Looking for openssl/ssl.h - found
-- Looking for openssl/x509.h
-- Looking for openssl/x509.h - found
-- Looking for openssl/rand.h
-- Looking for openssl/rand.h - found
CMake Error at C:/Program Files/CMake/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
  Could NOT find NGHTTP2 (missing: NGHTTP2_LIBRARY)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
  source_subfolder/CMake/FindNGHTTP2.cmake:28 (find_package_handle_standard_args)
  source_subfolder/CMakeLists.txt:451 (find_package)


-- Configuring incomplete, errors occurred!
See also "R:/.conan/data/libcurl/7.73.0/_/_/build/a4841135d52a10b44a9bf37748f0431d73cb789c/build_subfolder/CMakeFiles/CMakeOutput.log".
See also "R:/.conan/data/libcurl/7.73.0/_/_/build/a4841135d52a10b44a9bf37748f0431d73cb789c/build_subfolder/CMakeFiles/CMakeError.log".
libcurl/7.73.0:
libcurl/7.73.0: ERROR: Package 'a4841135d52a10b44a9bf37748f0431d73cb789c' build failed
libcurl/7.73.0: WARN: Build folder R:\.conan\data\libcurl\7.73.0\_\_\build\a4841135d52a10b44a9bf37748f0431d73cb789c
ERROR: libcurl/7.73.0: Error in build() method, line 181
        self._build_with_cmake()
while calling '_build_with_cmake', line 458
        cmake = self._configure_cmake()
while calling '_configure_cmake', line 454
        self._cmake.configure(build_folder=self._build_subfolder)
        ConanException: Error 1 while executing cd R:\.conan\data\libcurl\7.73.0\_\_\build\a4841135d52a10b44a9bf37748f0431d73cb789c\build_subfolder && cmake -G "Visual Studio 16 2019" -A "x64" -DCONAN_LINK_RUNTIME="/MDd" -DCONAN_IN_LOCAL_CACHE="ON" -DCONAN_COMPILER="Visual Studio" -DCONAN_COMPILER_VERSION="16" -DCONAN_CXX_FLAGS="/MP12" -DCONAN_C_FLAGS="/MP12" -DBUILD_SHARED_LIBS="False" -DCMAKE_INSTALL_PREFIX="R:.conan\data\libcurl\7.73.0\_\_\package\a4841135d52a10b44a9bf37748f0431d73cb789c" -DCMAKE_INSTALL_BINDIR="bin" -DCMAKE_INSTALL_SBINDIR="bin" -DCMAKE_INSTALL_LIBEXECDIR="bin" -DCMAKE_INSTALL_LIBDIR="lib" -DCMAKE_INSTALL_INCLUDEDIR="include" -DCMAKE_INSTALL_OLDINCLUDEDIR="include" -DCMAKE_INSTALL_DATAROOTDIR="share" -DCMAKE_PREFIX_PATH="R:/.conan/data/libcurl/7.73.0/_/_/build/a4841135d52a10b44a9bf37748f0431d73cb789c" -DCMAKE_MODULE_PATH="R:/.conan/data/libcurl/7.73.0/_/_/build/a4841135d52a10b44a9bf37748f0431d73cb789c" -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" -DCONAN_EXPORTED="1" -DBUILD_TESTING="False" -DBUILD_CURL_EXE="False" -DCURL_DISABLE_LDAP="True" -DCURL_STATICLIB="True" -DCMAKE_DEBUG_POSTFIX="" -DCMAKE_USE_SCHANNEL="False" -DCMAKE_USE_OPENSSL="True" -DCMAKE_USE_WOLFSSL="False" -DUSE_NGHTTP2="True" -DCURL_ZLIB="True" -DCURL_BROTLI="False" -DCURL_ZSTD="False" -DCMAKE_USE_LIBSSH2="False" -DENABLE_ARES="False" -DCURL_DISABLE_PROXY="False" -DUSE_LIBRTMP="False" -DCURL_DISABLE_RTSP="False" -DCURL_DISABLE_CRYPTO_AUTH="False" -DNTLM_WB_ENABLED="True" -Wno-dev R:.conan\data\libcurl\7.73.0\_\_\build\a4841135d52a10b44a9bf37748f0431d73cb789c
```

</details>



Discussion:

Resolving patch:
diff --git a/recipes/libcurl/all/conanfile.py b/recipes/libcurl/all/conanfile.py
--- a/recipes/libcurl/all/conanfile.py
+++ b/recipes/libcurl/all/conanfile.py
@@ -98,7 +98,7 @@ class LibcurlConan(ConanFile):
         "with_unix_sockets": True,
     }
 
-    generators = "cmake", "cmake_find_package_multi", "pkg_config"
+    generators = "cmake", "cmake_find_package_multi", "pkg_config", "cmake_find_package"
     _autotools = None
     _autotools_vars = None
     _cmake = None
@@ -296,14 +296,46 @@ def _patch_autotools(self):
     def _patch_cmake(self):
         if not self._is_using_cmake_build:
             return
+        cmakelists = os.path.join(self._source_subfolder, "CMakeLists.txt")
         # Custom findZstd.cmake file relies on pkg-config file, make sure that it's consumed on all platforms
         if self._has_zstd_option:
             tools.replace_in_file(os.path.join(self._source_subfolder, "CMake", "FindZstd.cmake"),
                                   "if(UNIX)", "if(TRUE)")
         # TODO: check this patch, it's suspicious
-        tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
+        tools.replace_in_file(cmakelists,
                               "include(CurlSymbolHiding)", "")
 
+        # libnghttp2
+        tools.replace_in_file(
+            cmakelists,
+            "find_package(NGHTTP2 REQUIRED)",
+            "find_package(libnghttp2 REQUIRED)",
+        )
+        tools.replace_in_file(
+            cmakelists,
+            "include_directories(${NGHTTP2_INCLUDE_DIRS})",
+            "",
+        )
+        tools.replace_in_file(
+            cmakelists,
+            "list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})",
+            "list(APPEND CURL_LIBS libnghttp2::nghttp2)",
+        )
+
+        # INTERFACE_LIBRARY (generated by the cmake_find_package generator) targets doesn't have the LOCATION property.
+        # So skipp the LOCATION check in the CMakeLists.txt
+        if tools.Version(self.version) >= "7.80.0":
+            tools.replace_in_file(
+                cmakelists,
+                'get_target_property(_lib "${_libname}" LOCATION)',
+                """get_target_property(_type "${_libname}" TYPE)
+    if(${_type} STREQUAL "INTERFACE_LIBRARY")
+      # Reading the INTERFACE_LIBRARY property on non-imported target will error out.
+      continue()
+    endif()
+    get_target_property(_lib "${_libname}" LOCATION)""",
+            )
+
     def _get_configure_command_args(self):
         yes_no = lambda v: "yes" if v else "no"
         params = [


Test patch: