Skip to content

Commit

Permalink
(#4356) [paho-mqtt-c] Explicit lib list + remove excessive build syst…
Browse files Browse the repository at this point in the history
…em patch

* [paho-mqtt-c] explicit lib list

* Update recipes/paho-mqtt-c/all/conanfile.py

Co-authored-by: SpaceIm <[email protected]>

* zap build patch + rm extra libs from package

unfortunately this causes it to build all 4 combinations but the build time is very short

* Test to see if the package_info does not account for cofig_options

* Update conanfile.py

* fix incorrect throw for invalid config

* use remove by mask

* fix patch name

* refactor epl file

* bump openssl

* del fpic when shared

* handle bin folder for windows shared

* tweak matchers

* bump openssl + fix path

* test: build target + selective install

* patch openssl lookup

might be required for 1.3.0

* more limted selection on copy

* zap pdbs

* try re-using the patch since it looks the same

* respect fPIC option

* warn + del samples

Co-authored-by: SpaceIm <[email protected]>

* selective copy of headers

Co-authored-by: SpaceIm <[email protected]>
  • Loading branch information
prince-chrismc and SpaceIm authored Apr 26, 2021
1 parent ef9b119 commit 4316ec9
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 1,351 deletions.
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"]
}
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":
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(pattern="MQTT*.h", src=os.path.join(self._source_subfolder, "src"), dst="include")
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")

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
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

0 comments on commit 4316ec9

Please sign in to comment.