Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libssh2: do not rely on _WINDLL or DLL_EXPORT defines #23683

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions recipes/libssh2/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ sources:
"1.8.2":
sha256: 088307d9f6b6c4b8c13f34602e8ff65d21c2dc4d55284dfe15d502c4ee190d67
url: https://github.com/libssh2/libssh2/releases/download/libssh2-1.8.2/libssh2-1.8.2.tar.gz
"1.8.0":
sha256: 39f34e2f6835f4b992cafe8625073a88e5a28ba78f83e8099610a7b3af4676d4
url: https://github.com/libssh2/libssh2/releases/download/libssh2-1.8.0/libssh2-1.8.0.tar.gz
patches:
"1.11.0":
- patch_file: "patches/001-1.11.0-fix-dll-defines.patch"
patch_description: "Do not rely on _WINDLL or DLL_EXPORT defines for DLLs"
patch_type: "conan"
"1.10.0":
- patch_file: "patches/001-1.8.2-fix-dll-defines.patch"
patch_description: "Do not rely on _WINDLL define for DLLs"
patch_type: "conan"
"1.9.0":
- patch_file: "patches/001-1.8.2-fix-dll-defines.patch"
patch_description: "Do not rely on _WINDLL define for DLLs"
patch_type: "conan"
"1.8.2":
- patch_file: "patches/001-1.8.2-fix-dll-defines.patch"
patch_description: "Do not rely on _WINDLL define for DLLs"
patch_type: "conan"
12 changes: 8 additions & 4 deletions recipes/libssh2/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def generate(self):
tc.cache_variables['BUILD_TESTING'] = not self.conf.get("tools.build:skip_test", default=True, check_type=bool)
tc.cache_variables["BUILD_STATIC_LIBS"] = not self.options.shared
tc.cache_variables["BUILD_SHARED_LIBS"] = self.options.shared
# Ensure DLL symbols are exported correctly
tc.cache_variables["HIDE_SYMBOLS"] = True # sets -DLIBSSH2_EXPORTS
if Version(self.version) < "1.11" and self.options.shared:
tc.preprocessor_definitions["LIBSSH2_EXPORTS"] = ""
# To install relocatable shared lib on Macos by default
tc.variables["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
# Workaround until github.com/conan-io/conan/pull/12600 is merged
Expand Down Expand Up @@ -126,16 +130,16 @@ def package_info(self):
self.cpp_info.set_property("cmake_file_name", "Libssh2")
self.cpp_info.set_property("cmake_target_name", "Libssh2::libssh2")
self.cpp_info.set_property("pkg_config_name", "libssh2")
# TODO: back to global scope in conan v2 once cmake_find_package_* generators removed

self.cpp_info.components["_libssh2"].libs = collect_libs(self)
if self.settings.os == "Windows":
self.cpp_info.components["_libssh2"].system_libs.append("ws2_32")
elif self.settings.os in ["Linux", "FreeBSD"]:
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.components["_libssh2"].set_property("cmake_target_name", "Libssh2::libssh2")
self.cpp_info.components["_libssh2"].set_property("pkg_config_name", "libssh2")
if self.options.shared:
self.cpp_info.components["_libssh2"].defines.append("LIBSSH2_EXPORTS")

if self.options.with_zlib:
self.cpp_info.components["_libssh2"].requires.append("zlib::zlib")
if self.options.crypto_backend == "openssl":
Expand Down
11 changes: 11 additions & 0 deletions recipes/libssh2/all/patches/001-1.11.0-fix-dll-defines.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- include/libssh2.h
+++ include/libssh2.h
@@ -105,7 +105,7 @@
/* Allow alternate API prefix from CFLAGS or calling app */
#ifndef LIBSSH2_API
# ifdef LIBSSH2_WIN32
-# if defined(LIBSSH2_EXPORTS) || defined(DLL_EXPORT) || defined(_WINDLL)
+# if defined(LIBSSH2_EXPORTS)
# ifdef LIBSSH2_LIBRARY
# define LIBSSH2_API __declspec(dllexport)
# else
11 changes: 11 additions & 0 deletions recipes/libssh2/all/patches/001-1.8.2-fix-dll-defines.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- include/libssh2.h
+++ include/libssh2.h
@@ -100,7 +100,7 @@
/* Allow alternate API prefix from CFLAGS or calling app */
#ifndef LIBSSH2_API
# ifdef LIBSSH2_WIN32
-# ifdef _WINDLL
+# ifdef LIBSSH2_EXPORTS
# ifdef LIBSSH2_LIBRARY
# define LIBSSH2_API __declspec(dllexport)
# else
5 changes: 2 additions & 3 deletions recipes/libssh2/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"
generators = "CMakeDeps", "CMakeToolchain"

def requirements(self):
self.requires(self.tested_reference_str)
Expand All @@ -22,5 +21,5 @@ def layout(self):

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
2 changes: 0 additions & 2 deletions recipes/libssh2/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ versions:
folder: all
"1.8.2":
folder: all
"1.8.0":
folder: all