-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #489 from madebr/zeromq
Add zeromq/4.3.2 recipe
- Loading branch information
Showing
7 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
} | ||
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"4.3.2": | ||
folder: all |