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

Add zeromq/4.3.2 recipe #489

Merged
merged 7 commits into from
Jan 28, 2020
Merged
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
11 changes: 11 additions & 0 deletions recipes/zeromq/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions recipes/zeromq/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"4.3.2":
url: "https://github.com/zeromq/libzmq/archive/v4.3.2.tar.gz"
sha256: "02ecc88466ae38cf2c8d79f09cfd2675ba299a439680b64ade733e26a349edeb"
111 changes: 111 additions & 0 deletions recipes/zeromq/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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"],
uilianries marked this conversation as resolved.
Show resolved Hide resolved
}
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")
18 changes: 18 additions & 0 deletions recipes/zeromq/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
18 changes: 18 additions & 0 deletions recipes/zeromq/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions recipes/zeromq/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <zmq.h>
#include <cstdlib>
#include <iostream>
#include <stdexcept>

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;
}
3 changes: 3 additions & 0 deletions recipes/zeromq/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"4.3.2":
folder: all