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

[paho-mqtt-c] Explicit lib list + remove excessive build system patch #4356

Merged
merged 22 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from 21 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
18 changes: 5 additions & 13 deletions recipes/paho-mqtt-c/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,22 @@ patches:
"1.3.0":
- patch_file: "patches/0001-fix-MinGW-and-OSX-builds-for-1-3-0.patch"
base_path: "source_subfolder"
- patch_file: "patches/0003-fix-cmake-install.patch"
- patch_file: "patches/0004-fix-cmake-find-openssl.patch"
base_path: "source_subfolder"
"1.3.1":
- patch_file: "patches/0002-fix-MinGW-and-OSX-builds-for-1-3-1.patch"
base_path: "source_subfolder"
- patch_file: "patches/0003-fix-cmake-install.patch"
- patch_file: "patches/0004-fix-cmake-find-openssl.patch"
base_path: "source_subfolder"
"1.3.4":
- patch_file: "patches/0002-fix-MinGW-and-OSX-builds-for-1-3-4.patch"
base_path: "source_subfolder"
- patch_file: "patches/0004-fix-cmake-install.patch"
base_path: "source_subfolder"
"1.3.5":
- patch_file: "patches/0002-fix-MinGW-and-OSX-builds-for-1-3-5.patch"
base_path: "source_subfolder"
- patch_file: "patches/0004-fix-cmake-install.patch"
- patch_file: "patches/0003-allow-static-windows-runtimes.patch"
base_path: "source_subfolder"
"1.3.6":
- patch_file: "patches/0002-fix-MinGW-and-OSX-builds-for-1-3-5.patch"
base_path: "source_subfolder"
- patch_file: "patches/0004-fix-cmake-install.patch"
- patch_file: "patches/0003-allow-static-windows-runtimes.patch"
base_path: "source_subfolder"
"1.3.8":
- patch_file: "patches/0002-fix-MinGW-and-OSX-builds-for-1-3-5.patch"
base_path: "source_subfolder"
- patch_file: "patches/0005-fix-cmake-install-for-1-3-8.patch"
- patch_file: "patches/0003-allow-static-windows-runtimes.patch"
base_path: "source_subfolder"
100 changes: 66 additions & 34 deletions recipes/paho-mqtt-c/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
import os
from conans import CMake, ConanFile, tools
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.29.1"


class PahoMqttcConan(ConanFile):
name = "paho-mqtt-c"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/eclipse/paho.mqtt.c"
topics = ("MQTT", "IoT", "eclipse", "SSL", "paho", "C")
topics = ("mqtt", "iot", "eclipse", "ssl", "tls", "paho", "c")
license = "EPL-2.0"
description = "Eclipse Paho MQTT C client library for Linux, Windows and MacOS"
exports_sources = ["CMakeLists.txt", "patches/*"]
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False],
"fPIC": [True, False],
"ssl": [True, False],
"samples": [True, False],
"asynchronous": [True, False]}
default_options = {"shared": False,
"fPIC": True,
"ssl": True,
"asynchronous" : True,
"samples": False}
options = {
"shared": [True, False],
"fPIC": [True, False],
"ssl": [True, False],
"asynchronous": [True, False],
"samples": [True, False, "deprecated"]
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
}
default_options = {
"shared": False,
"fPIC": True,
"ssl": True,
"asynchronous": True,
"samples": "deprecated"
}

_cmake = None

Expand All @@ -32,20 +39,22 @@ def _source_subfolder(self):
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
# There is unsureness if static linking before 1.3.4 did every work.
# If you need it, teak here, on Linux and OSX you might have success.
if tools.Version(self.version) < "1.3.4":
self.options.shared = True

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx
if self.options.shared == False and self.settings.os == "Windows" and tools.Version(self.version) < "1.3.4":
raise ConanInvalidConfiguration("Static linking in Windows did not work before version 1.3.4")

if self.options.samples != "deprecated":
self.output.warn("samples option is deprecated and they are no longer provided in the package.")

if not self.options.shared and tools.Version(self.version) < "1.3.4":
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
raise ConanInvalidConfiguration("{}/{} does not support static linking".format(self.name, self.version))

def requirements(self):
if self.options.ssl:
self.requires("openssl/1.1.1i")
self.requires("openssl/1.1.1k")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
Expand All @@ -63,39 +72,45 @@ def _configure_cmake(self):
self._cmake.definitions["PAHO_BUILD_ASYNC"] = self.options.asynchronous
self._cmake.definitions["PAHO_BUILD_STATIC"] = not self.options.shared
self._cmake.definitions["PAHO_BUILD_SHARED"] = self.options.shared
self._cmake.definitions["PAHO_BUILD_SAMPLES"] = self.options.samples
self._cmake.definitions["PAHO_BUILD_SAMPLES"] = False
self._cmake.definitions["PAHO_WITH_SSL"] = self.options.ssl
if self.options.ssl:
self._cmake.definitions["OPENSSL_SEARCH_PATH"] = self.deps_cpp_info["openssl"].rootpath
self._cmake.definitions["OPENSSL_ROOT_DIR"] = self.deps_cpp_info["openssl"].rootpath
self._cmake.definitions["OPENSSL_SEARCH_PATH"] = self.deps_cpp_info["openssl"].rootpath.replace("\\", "/")
self._cmake.definitions["OPENSSL_ROOT_DIR"] = self.deps_cpp_info["openssl"].rootpath.replace("\\", "/")
self._cmake.configure()
return self._cmake

def build(self):
def _patch_source(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
if not self.options.get_safe("fPIC", True):
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "CMakeLists.txt"), "POSITION_INDEPENDENT_CODE ON", "")

def build(self):
self._patch_source()
cmake = self._configure_cmake()
cmake.build()
cmake.build(target=self._cmake_target)

def package(self):
self.copy("edl-v10", src=self._source_subfolder, dst="licenses")
if self.version in ['1.3.0', '1.3.1']:
eplfile = "epl-v10"
else:
eplfile = "epl-v20" # EPL changed to V2
self.copy(eplfile, src=self._source_subfolder, dst="licenses")
self.copy(self._epl_file, src=self._source_subfolder, dst="licenses")
self.copy("notice.html", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "share"))
# Manually copy since the CMake installs everything
self.copy("*.h", src=self._source_subfolder, dst="include", keep_path=False)
self.copy(os.path.join("lib", "*{}.*".format(self._lib_target)), dst="lib", keep_path=False)
self.copy(os.path.join("bin", "*{}.*".format(self._lib_target)), dst="bin", keep_path=False)
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.pdb")
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.pdb")
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved

def package_id(self):
del self.info.options.samples

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "eclipse-paho-mqtt-c"
self.cpp_info.names["cmake_find_package_multi"] = "eclipse-paho-mqtt-c"
self.cpp_info.components["_paho-mqtt-c"].names["cmake_find_package"] = self._cmake_target
self.cpp_info.components["_paho-mqtt-c"].names["cmake_find_package_multi"] = self._cmake_target
self.cpp_info.components["_paho-mqtt-c"].libs = tools.collect_libs(self)
self.cpp_info.components["_paho-mqtt-c"].libs = [self._lib_target]
if self.settings.os == "Windows":
if not self.options.shared:
self.cpp_info.components["_paho-mqtt-c"].system_libs.append("ws2_32")
Expand All @@ -111,9 +126,14 @@ def package_info(self):
self.cpp_info.components["_paho-mqtt-c"].system_libs.extend(["c"])
else:
self.cpp_info.components["_paho-mqtt-c"].system_libs.extend(["c", "pthread"])

if self.options.ssl:
self.cpp_info.components["_paho-mqtt-c"].requires = ["openssl::openssl"]

@property
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would help reading if all the properties would be defined on the top, before used
but that might be personal taste

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just after their first usage. At least, close to their usage.

def _epl_file(self):
return "epl-v10" if self.version in ['1.3.0', '1.3.1'] else "epl-v20" # EPL changed to V2

@property
def _cmake_target(self):
target = "paho-mqtt3"
Expand All @@ -123,3 +143,15 @@ def _cmake_target(self):
if not self.options.shared:
target += "-static"
return target

@property
def _lib_target(self):
target = "paho-mqtt3"
target += "a" if self.options.asynchronous else "c"
if self.options.ssl:
target += "s"
if not self.options.shared:
# https://github.com/eclipse/paho.mqtt.c/blob/317fb008e1541838d1c29076d2bc5c3e4b6c4f53/src/CMakeLists.txt#L154
if tools.Version(self.version) < "1.3.2" or self.settings.os == "Windows":
target += "-static"
return target
Loading