diff --git a/recipes/zeromq/all/CMakeLists.txt b/recipes/zeromq/all/CMakeLists.txt new file mode 100644 index 0000000000000..7069ce7c180dd --- /dev/null +++ b/recipes/zeromq/all/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 2.8.12) +project(cmake_wrapper) + +include(conanbuildinfo.cmake) +conan_basic_setup() + +if(MSVC) + add_definitions("-D_NOEXCEPT=noexcept") +endif() + +add_subdirectory(source_subfolder) diff --git a/recipes/zeromq/all/conandata.yml b/recipes/zeromq/all/conandata.yml new file mode 100644 index 0000000000000..2906b9eeb00ad --- /dev/null +++ b/recipes/zeromq/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "4.3.2": + url: "https://github.com/zeromq/libzmq/archive/v4.3.2.tar.gz" + sha256: "02ecc88466ae38cf2c8d79f09cfd2675ba299a439680b64ade733e26a349edeb" diff --git a/recipes/zeromq/all/conanfile.py b/recipes/zeromq/all/conanfile.py new file mode 100644 index 0000000000000..378bc54046c37 --- /dev/null +++ b/recipes/zeromq/all/conanfile.py @@ -0,0 +1,111 @@ +import os +from conans import ConanFile, tools, CMake + + +class ZeroMQConan(ConanFile): + name = "zeromq" + homepage = "https://github.com/zeromq/libzmq" + description = "ZeroMQ is a community of projects focused on decentralized messaging and computing" + topics = ("conan", "zmq", "libzmq", "message-queue", "asynchronous") + url = "https://github.com/conan-io/conan-center-index" + license = "LGPL-3.0" + exports_sources = ["CMakeLists.txt"] + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + "encryption": [None, "libsodium", "tweetnacl"], + } + default_options = { + "shared": False, + "fPIC": True, + "encryption": "libsodium", + } + generators = "cmake", "cmake_find_package" + + _cmake = None + _source_subfolder = "source_subfolder" + _build_subfolder = "build_subfolder" + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + del self.options.fPIC + + def requirements(self): + if self.options.encryption == "libsodium": + self.requires.add("libsodium/1.0.18") + + def source(self): + tools.get(**self.conan_data["sources"][self.version]) + os.rename("libzmq-{}".format(self.version), self._source_subfolder) + + def _configure_cmake(self): + if self._cmake: + return self._cmake + self._cmake = CMake(self) + self._cmake.definitions["ENABLE_CURVE"] = self.options.encryption is not None + self._cmake.definitions["WITH_LIBSODIUM"] = self.options.encryption == "libsodium" + self._cmake.definitions["ZMQ_BUILD_TESTS"] = False + self._cmake.definitions["WITH_PERF_TOOL"] = False + self._cmake.definitions["BUILD_SHARED"] = self.options.shared + self._cmake.definitions["BUILD_STATIC"] = not self.options.shared + self._cmake.definitions["ENABLE_CPACK"] = False + self._cmake.configure(build_folder=self._build_subfolder) + return self._cmake + + def _patch_sources(self): + os.unlink(os.path.join(self._source_subfolder, "builds", "cmake", "Modules", "FindSodium.cmake")) + os.rename("Findlibsodium.cmake", "FindSodium.cmake") + tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"), + "SODIUM_FOUND", + "libsodium_FOUND") + tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"), + "SODIUM_INCLUDE_DIRS", + "libsodium_INCLUDE_DIRS") + tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"), + "SODIUM_LIBRARIES", + "libsodium_LIBRARIES") + + def build(self): + self._patch_sources() + cmake = self._configure_cmake() + cmake.build() + + def package(self): + self.copy(pattern="COPYING*", src=self._source_subfolder, dst="licenses") + cmake = self._configure_cmake() + cmake.install() + + tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) + tools.rmdir(os.path.join(self.package_folder, "share")) + tools.rmdir(os.path.join(self.package_folder, "CMake")) + + def package_info(self): + self.cpp_info.names["cmake_find_package"] = "ZeroMQ" + self.cpp_info.names["cmake_find_package_multi"] = "ZeroMQ" + if self.settings.compiler == "Visual Studio": + version = "_".join(self.version.split(".")) + if self.settings.build_type == "Debug": + runtime = "-gd" if self.options.shared else "-sgd" + else: + runtime = "" if self.options.shared else "-s" + library_name = "libzmq-mt%s-%s" % (runtime, version) + if not os.path.isfile(os.path.join(self.package_folder, "lib", library_name)): + # unfortunately Visual Studio and Ninja generators produce different file names + toolset = {"12": "v120", + "14": "v140", + "15": "v141", + "16": "v142"}.get(str(self.settings.compiler.version)) + library_name = "libzmq-%s-mt%s-%s" % (toolset, runtime, version) + self.cpp_info.libs = [library_name] + self.cpp_info.system_libs = ["iphlpapi", "ws2_32"] + else: + self.cpp_info.libs = ["zmq"] + if self.settings.os == "Linux": + self.cpp_info.system_libs.extend(["pthread", "rt", "m"]) + if not self.options.shared: + self.cpp_info.defines.append("ZMQ_STATIC") diff --git a/recipes/zeromq/all/test_package/CMakeLists.txt b/recipes/zeromq/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..65017f5551258 --- /dev/null +++ b/recipes/zeromq/all/test_package/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 2.8.12) +project(test_package) + +set(CMAKE_VERBOSE_MAKEFILE TRUE) + +option(WITH_LIBSODIUM "zeromq is built with libsodium") + +include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") +conan_basic_setup() + +find_package(ZeroMQ REQUIRED) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} ZeroMQ::ZeroMQ) + +if(WITH_LIBSODIUM) + target_compile_definitions(${PROJECT_NAME} PRIVATE "WITH_LIBSODIUM") +endif() diff --git a/recipes/zeromq/all/test_package/conanfile.py b/recipes/zeromq/all/test_package/conanfile.py new file mode 100644 index 0000000000000..2ec4389efb8ee --- /dev/null +++ b/recipes/zeromq/all/test_package/conanfile.py @@ -0,0 +1,18 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake", "cmake_find_package" + + def build(self): + cmake = CMake(self) + cmake.definitions["WITH_LIBSODIUM"] = self.options["zeromq"].encryption == "libsodium" + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self.settings): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/zeromq/all/test_package/test_package.cpp b/recipes/zeromq/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..4ca88779568e5 --- /dev/null +++ b/recipes/zeromq/all/test_package/test_package.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +int main() try +{ + void *context = zmq_ctx_new(); + void *requester = zmq_socket(context, ZMQ_REQ); +#if defined(WITH_LIBSODIUM) + int is_server = 0; + if (0 != zmq_setsockopt(requester, ZMQ_CURVE_SERVER, &is_server, sizeof(is_server))) + throw std::runtime_error("zmq_setsockopt with ZMQ_CURVE_SERVER failed"); +#endif + zmq_close(requester); + zmq_ctx_destroy (context); + + return EXIT_SUCCESS; +} +catch (std::runtime_error & e) { + std::cerr << e.what() << std::endl; + return EXIT_FAILURE; +} diff --git a/recipes/zeromq/config.yml b/recipes/zeromq/config.yml new file mode 100644 index 0000000000000..ef8763e534823 --- /dev/null +++ b/recipes/zeromq/config.yml @@ -0,0 +1,3 @@ +versions: + "4.3.2": + folder: all