Skip to content

Commit

Permalink
libssh2 fix issues with mbedtls on Windows (#25860)
Browse files Browse the repository at this point in the history
* libssh2 fix issues with mbedtls on Windows

* fix to support more versions
  • Loading branch information
jcar87 authored Nov 6, 2024
1 parent baec825 commit f7a9ac9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions recipes/libssh2/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from conan import ConanFile
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir, collect_libs
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir, collect_libs, replace_in_file
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version
import os

required_conan_version = ">=1.53.0"
required_conan_version = ">=2.7"


class Libssh2Conan(ConanFile):
Expand Down Expand Up @@ -43,6 +43,11 @@ def export_sources(self):
def layout(self):
cmake_layout(self, src_folder="src")

@property
def _mbedtls_cmake_package_name(self):
pkg_name = "mbedTLS" if Version(self.version) < "1.11.1" else "MbedTLS"
return pkg_name

def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["ENABLE_ZLIB_COMPRESSION"] = self.options.with_zlib
Expand All @@ -66,6 +71,8 @@ def generate(self):
tc.generate()

deps = CMakeDeps(self)
deps.set_property("mbedtls", "cmake_file_name", self._mbedtls_cmake_package_name)
deps.set_property("mbedtls", "cmake_additional_variables_prefixes", ["MBEDTLS"])
deps.generate()

def config_options(self):
Expand Down Expand Up @@ -97,6 +104,9 @@ def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
apply_conandata_patches(self)

cmakelists = os.path.join("src", "CMakeLists.txt") if Version(self.version) <= "1.10" else "CMakeLists.txt"
replace_in_file(self, os.path.join(self.source_folder, cmakelists), "MBEDTLS_FOUND", f"{self._mbedtls_cmake_package_name}_FOUND")

def build(self):
cmake = CMake(self)
cmake.configure()
Expand All @@ -123,10 +133,6 @@ def package_info(self):
self.cpp_info.components["_libssh2"].system_libs.extend(["pthread", "dl"])

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["cmake_find_package"] = "Libssh2"
self.cpp_info.names["cmake_find_package_multi"] = "Libssh2"
self.cpp_info.components["_libssh2"].names["cmake_find_package"] = "libssh2"
self.cpp_info.components["_libssh2"].names["cmake_find_package_multi"] = "libssh2"
self.cpp_info.components["_libssh2"].set_property("cmake_target_name", "Libssh2::libssh2")
self.cpp_info.components["_libssh2"].set_property("pkg_config_name", "libssh2")
if self.options.with_zlib:
Expand Down

0 comments on commit f7a9ac9

Please sign in to comment.