Skip to content

Commit

Permalink
(#15670) czmq: use official tarball + fix dependencies handling
Browse files Browse the repository at this point in the history
* download official tarballs

* modernize more

* relocatable shared lib on macOS

* fix discovery of dependencies and options logic

* remove openssl from requirements

* switch to C test package since czmq is C binding of ZeroMQ after all

* do not export all symbols

* with_libmicrohttpd option instead of with_microhttpd
  • Loading branch information
SpaceIm authored Feb 12, 2023
1 parent 2a2ba02 commit 506b6d9
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 135 deletions.
8 changes: 4 additions & 4 deletions recipes/czmq/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
sources:
"4.2.1":
url: "https://github.com/zeromq/czmq/archive/v4.2.1.tar.gz"
sha256: "83457cd32a2c2615b8d7ebcf91b198cb0d8df383a2072b96835ab250164d8a83"
url: "https://github.com/zeromq/czmq/releases/download/v4.2.1/czmq-4.2.1.tar.gz"
sha256: "5d720a204c2a58645d6f7643af15d563a712dad98c9d32c1ed913377daa6ac39"
"4.2.0":
url: "https://github.com/zeromq/czmq/archive/v4.2.0.tar.gz"
sha256: "31185090b500b64855003be2450ced00efa6b58544639acfc68aa13c9ec249f8"
url: "https://github.com/zeromq/czmq/releases/download/v4.2.0/czmq-4.2.0.tar.gz"
sha256: "cfab29c2b3cc8a845749758a51e1dd5f5160c1ef57e2a41ea96e4c2dcc8feceb"
patches:
"4.2.1":
- patch_file: patches/4.2.1-0001-fix-cmake.patch
Expand Down
39 changes: 23 additions & 16 deletions recipes/czmq/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from conan import ConanFile
from conan.tools.microsoft import is_msvc
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, save
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, save
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version
import os
import textwrap

required_conan_version = ">=1.53.0"


class CzmqConan(ConanFile):
name = "czmq"
description = "High-level C binding for ZeroMQ"
Expand All @@ -24,6 +26,7 @@ class CzmqConan(ConanFile):
"with_libcurl": [True, False],
"with_lz4": [True, False],
"with_libuuid": [True, False],
"with_libmicrohttpd": [True, False],
"with_systemd": [True, False],
}
default_options = {
Expand All @@ -33,6 +36,7 @@ class CzmqConan(ConanFile):
"with_libcurl": True,
"with_lz4": True,
"with_libuuid": True,
"with_libmicrohttpd": True,
"with_systemd": False,
}

Expand All @@ -50,17 +54,19 @@ def config_options(self):
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
if not self.options.enable_drafts:
del self.options.with_libcurl
del self.options.with_libmicrohttpd

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("openssl/1.1.1s") # zdigest depends on openssl
self.requires("zeromq/4.3.4")
if self.options.enable_drafts:
if self.options.get_safe("with_libmicrohttpd"):
self.requires("libmicrohttpd/0.9.75")
if self.options.with_libcurl:
self.requires("libcurl/7.86.0")
if self.options.get_safe("with_libcurl"):
self.requires("libcurl/7.87.0")
if self.options.with_lz4:
self.requires("lz4/1.9.4")
if self.options.get_safe("with_libuuid"):
Expand All @@ -77,18 +83,20 @@ def source(self):

def generate(self):
tc = CMakeToolchain(self)
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
tc.variables["ENABLE_DRAFTS"] = self.options.enable_drafts
tc.variables["CZMQ_BUILD_SHARED"] = self.options.shared
tc.variables["CZMQ_BUILD_STATIC"] = not self.options.shared
tc.variables["CZMQ_WITH_UUID"] = self.options.get_safe("with_libuuid", False)
tc.variables["CZMQ_WITH_SYSTEMD"] = self.options.get_safe("with_systemd", False)
tc.variables["CZMQ_WITH_LZ4"] = self.options.get_safe("with_lz4", False)
tc.variables["CZMQ_WITH_LZ4"] = self.options.with_lz4
tc.variables["CZMQ_WITH_LIBCURL"] = self.options.get_safe("with_libcurl", False)
tc.variables["CZMQ_WITH_LIBMICROHTTPD"] = self.options.enable_drafts
tc.variables["CZMQ_WITH_LIBMICROHTTPD"] = self.options.get_safe("with_libmicrohttpd", False)
if Version(self.version) >= "4.2.1":
tc.variables["CZMQ_WITH_NSS"] = False
if is_msvc(self):
tc.preprocessor_definitions["_NOEXCEPT"] = "noexcept"
if self.options.shared:
tc.preprocessor_definitions["CZMQ_STATIC"] = 1
# Relocatable shared libs on macOS
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
tc.generate()

dpes = CMakeDeps(self)
Expand Down Expand Up @@ -119,17 +127,17 @@ def package(self):
def _create_cmake_module_alias_targets(self, module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent("""\
content += textwrap.dedent(f"""\
if(TARGET {aliased} AND NOT TARGET {alias})
add_library({alias} INTERFACE IMPORTED)
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""".format(alias=alias, aliased=aliased))
""")
save(self, module_file, content)

@property
def _module_file_rel_path(self):
return os.path.join("lib", "cmake", "conan-official-{}-targets.cmake".format(self.name))
return os.path.join("lib", "cmake", f"conan-official-{self.name}-targets.cmake")

@property
def _czmq_target(self):
Expand All @@ -151,4 +159,3 @@ def package_info(self):
# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.names["pkg_config"] = "libczmq"
157 changes: 86 additions & 71 deletions recipes/czmq/all/patches/4.2.0-0001-fix-cmake.patch
Original file line number Diff line number Diff line change
@@ -1,152 +1,167 @@
diff --git a/a/CMakeLists.txt b/b/CMakeLists.txt
index de4e150..93a0727 100644
--- a/a/CMakeLists.txt
+++ b/b/CMakeLists.txt
@@ -120,25 +120,26 @@ set(OPTIONAL_LIBRARIES_STATIC)
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -120,27 +120,25 @@ set(OPTIONAL_LIBRARIES_STATIC)
########################################################################
# LIBZMQ dependency
########################################################################
-find_package(libzmq REQUIRED)
-IF (LIBZMQ_FOUND)
- include_directories(${LIBZMQ_INCLUDE_DIRS})
- list(APPEND MORE_LIBRARIES ${LIBZMQ_LIBRARIES})
+find_package(ZeroMQ REQUIRED)
+IF (ZeroMQ_FOUND)
+ include_directories(${ZeroMQ_INCLUDE_DIRS})
+ list(APPEND MORE_LIBRARIES ${ZeroMQ_LIBRARIES})
+IF (1)
+ find_package(ZeroMQ REQUIRED CONFIG)
+ list(APPEND MORE_LIBRARIES $<IF:$<TARGET_EXISTS:libzmq>,libzmq,libzmq-static>)
IF (PC_LIBZMQ_FOUND)
set(pkg_config_names_private "${pkg_config_names_private} libzmq")
list(APPEND OPTIONAL_LIBRARIES_STATIC ${PC_LIBZMQ_STATIC_LDFLAGS})
ELSE (PC_LIBZMQ_FOUND)
set(pkg_config_libs_private "${pkg_config_libs_private} -lzmq")
ENDIF (PC_LIBZMQ_FOUND)
-ELSE (LIBZMQ_FOUND)
+ELSE (ZeroMQ_FOUND)
+ELSE ()
message( FATAL_ERROR "libzmq not found." )
-ENDIF (LIBZMQ_FOUND)
+ENDIF (ZeroMQ_FOUND)
+ENDIF ()

########################################################################
# UUID dependency
########################################################################
find_package(uuid)
-find_package(uuid)
-IF (UUID_FOUND)
+option(CZMQ_WITH_UUID "Build czmq with uuid" ${UUID_FOUND})
+IF (CZMQ_WITH_UUID AND UUID_FOUND)
include_directories(${UUID_INCLUDE_DIRS})
list(APPEND MORE_LIBRARIES ${UUID_LIBRARIES})
- include_directories(${UUID_INCLUDE_DIRS})
- list(APPEND MORE_LIBRARIES ${UUID_LIBRARIES})
+IF (CZMQ_WITH_UUID)
+ find_package(libuuid REQUIRED CONFIG)
+ list(APPEND MORE_LIBRARIES libuuid::libuuid)
IF (PC_UUID_FOUND)
@@ -149,13 +150,14 @@ IF (UUID_FOUND)
set(pkg_config_names_private "${pkg_config_names_private} uuid")
list(APPEND OPTIONAL_LIBRARIES_STATIC ${PC_UUID_STATIC_LDFLAGS})
@@ -148,16 +146,14 @@ IF (UUID_FOUND)
set(pkg_config_libs_private "${pkg_config_libs_private} -luuid")
ENDIF (PC_UUID_FOUND)
add_definitions(-DHAVE_UUID)
list(APPEND OPTIONAL_LIBRARIES ${UUID_LIBRARIES})
- list(APPEND OPTIONAL_LIBRARIES ${UUID_LIBRARIES})
-ENDIF (UUID_FOUND)
+ENDIF (CZMQ_WITH_UUID AND UUID_FOUND)
+ENDIF ()

########################################################################
# SYSTEMD dependency
########################################################################
find_package(systemd)
-find_package(systemd)
-IF (SYSTEMD_FOUND)
+option(CZMQ_WITH_SYSTEMD "Build czmq with systemd" ${SYSTEMD_FOUND})
+IF (CZMQ_WITH_SYSTEMD AND SYSTEMD_FOUND)
include_directories(${SYSTEMD_INCLUDE_DIRS})
list(APPEND MORE_LIBRARIES ${SYSTEMD_LIBRARIES})
- include_directories(${SYSTEMD_INCLUDE_DIRS})
- list(APPEND MORE_LIBRARIES ${SYSTEMD_LIBRARIES})
+IF (CZMQ_WITH_SYSTEMD)
+ find_package(libsystemd REQUIRED CONFIG)
+ list(APPEND MORE_LIBRARIES libsystemd::libsystemd)
IF (PC_SYSTEMD_FOUND)
@@ -166,13 +168,14 @@ IF (SYSTEMD_FOUND)
set(pkg_config_names_private "${pkg_config_names_private} libsystemd >= 200.0.0")
list(APPEND OPTIONAL_LIBRARIES_STATIC ${PC_SYSTEMD_STATIC_LDFLAGS})
@@ -165,16 +161,14 @@ IF (SYSTEMD_FOUND)
set(pkg_config_libs_private "${pkg_config_libs_private} -lsystemd")
ENDIF (PC_SYSTEMD_FOUND)
add_definitions(-DHAVE_LIBSYSTEMD)
list(APPEND OPTIONAL_LIBRARIES ${SYSTEMD_LIBRARIES})
- list(APPEND OPTIONAL_LIBRARIES ${SYSTEMD_LIBRARIES})
-ENDIF (SYSTEMD_FOUND)
+ENDIF (CZMQ_WITH_SYSTEMD AND SYSTEMD_FOUND)
+ENDIF ()

########################################################################
# LZ4 dependency
########################################################################
find_package(lz4)
-find_package(lz4)
-IF (LZ4_FOUND)
+option(CZMQ_WITH_LZ4 "Build czmq with lz4" ${LZ4_FOUND})
+IF (CZMQ_WITH_LZ4 AND LZ4_FOUND)
include_directories(${LZ4_INCLUDE_DIRS})
list(APPEND MORE_LIBRARIES ${LZ4_LIBRARIES})
- include_directories(${LZ4_INCLUDE_DIRS})
- list(APPEND MORE_LIBRARIES ${LZ4_LIBRARIES})
+IF (CZMQ_WITH_LZ4)
+ find_package(lz4 REQUIRED CONFIG)
+ list(APPEND MORE_LIBRARIES $<IF:$<TARGET_EXISTS:LZ4::lz4_shared>,LZ4::lz4_shared,LZ4::lz4_static>)
IF (PC_LZ4_FOUND)
@@ -183,13 +186,14 @@ IF (LZ4_FOUND)
set(pkg_config_names_private "${pkg_config_names_private} liblz4")
list(APPEND OPTIONAL_LIBRARIES_STATIC ${PC_LZ4_STATIC_LDFLAGS})
@@ -182,16 +176,14 @@ IF (LZ4_FOUND)
set(pkg_config_libs_private "${pkg_config_libs_private} -llz4")
ENDIF (PC_LZ4_FOUND)
add_definitions(-DHAVE_LIBLZ4)
list(APPEND OPTIONAL_LIBRARIES ${LZ4_LIBRARIES})
- list(APPEND OPTIONAL_LIBRARIES ${LZ4_LIBRARIES})
-ENDIF (LZ4_FOUND)
+ENDIF (CZMQ_WITH_LZ4 AND LZ4_FOUND)
+ENDIF ()

########################################################################
# LIBCURL dependency
########################################################################
find_package(libcurl)
-find_package(libcurl)
-IF (LIBCURL_FOUND)
+option(CZMQ_WITH_LIBCURL "Build czmq with libcurl" ${LIBCURL_FOUND})
+IF (CZMQ_WITH_LIBCURL AND LIBCURL_FOUND)
include_directories(${LIBCURL_INCLUDE_DIRS})
list(APPEND MORE_LIBRARIES ${LIBCURL_LIBRARIES})
- include_directories(${LIBCURL_INCLUDE_DIRS})
- list(APPEND MORE_LIBRARIES ${LIBCURL_LIBRARIES})
+IF (CZMQ_WITH_LIBCURL)
+ find_package(CURL REQUIRED)
+ list(APPEND MORE_LIBRARIES CURL::libcurl)
IF (PC_LIBCURL_FOUND)
@@ -200,13 +204,14 @@ IF (LIBCURL_FOUND)
set(pkg_config_names_private "${pkg_config_names_private} libcurl >= 7.28.0")
list(APPEND OPTIONAL_LIBRARIES_STATIC ${PC_LIBCURL_STATIC_LDFLAGS})
@@ -199,16 +191,14 @@ IF (LIBCURL_FOUND)
set(pkg_config_libs_private "${pkg_config_libs_private} -lcurl")
ENDIF (PC_LIBCURL_FOUND)
add_definitions(-DHAVE_LIBCURL)
list(APPEND OPTIONAL_LIBRARIES ${LIBCURL_LIBRARIES})
- list(APPEND OPTIONAL_LIBRARIES ${LIBCURL_LIBRARIES})
-ENDIF (LIBCURL_FOUND)
+ENDIF (CZMQ_WITH_LIBCURL AND LIBCURL_FOUND)
+ENDIF ()

########################################################################
# LIBMICROHTTPD dependency
########################################################################
find_package(libmicrohttpd)
-find_package(libmicrohttpd)
-IF (LIBMICROHTTPD_FOUND)
+option(CZMQ_WITH_LIBMICROHTTPD "Build czmq with libmicrohttpd" ${LIBMICROHTTPD_FOUND})
+IF (CZMQ_WITH_LIBMICROHTTPD AND LIBMICROHTTPD_FOUND)
include_directories(${LIBMICROHTTPD_INCLUDE_DIRS})
list(APPEND MORE_LIBRARIES ${LIBMICROHTTPD_LIBRARIES})
- include_directories(${LIBMICROHTTPD_INCLUDE_DIRS})
- list(APPEND MORE_LIBRARIES ${LIBMICROHTTPD_LIBRARIES})
+IF (CZMQ_WITH_LIBMICROHTTPD)
+ find_package(libmicrohttpd REQUIRED CONFIG)
+ list(APPEND MORE_LIBRARIES libmicrohttpd::libmicrohttpd)
IF (PC_LIBMICROHTTPD_FOUND)
@@ -217,7 +222,7 @@ IF (LIBMICROHTTPD_FOUND)
set(pkg_config_names_private "${pkg_config_names_private} libmicrohttpd")
list(APPEND OPTIONAL_LIBRARIES_STATIC ${PC_LIBMICROHTTPD_STATIC_LDFLAGS})
@@ -216,8 +206,7 @@ IF (LIBMICROHTTPD_FOUND)
set(pkg_config_libs_private "${pkg_config_libs_private} -lmicrohttpd")
ENDIF (PC_LIBMICROHTTPD_FOUND)
add_definitions(-DHAVE_LIBMICROHTTPD)
list(APPEND OPTIONAL_LIBRARIES ${LIBMICROHTTPD_LIBRARIES})
- list(APPEND OPTIONAL_LIBRARIES ${LIBMICROHTTPD_LIBRARIES})
-ENDIF (LIBMICROHTTPD_FOUND)
+ENDIF (CZMQ_WITH_LIBMICROHTTPD AND LIBMICROHTTPD_FOUND)
+ENDIF ()

########################################################################
# version
@@ -380,6 +385,7 @@ if (CZMQ_BUILD_SHARED)
@@ -368,7 +357,10 @@ IF (NOT MSVC)
# avoid building everything twice for shared + static
# only on *nix, as Windows needs different preprocessor defines in static builds
add_library (czmq_objects OBJECT ${czmq_sources})
+ target_link_libraries(czmq_objects PUBLIC ${MORE_LIBRARIES})
+ if(CZMQ_BUILD_SHARED)
set_property(TARGET czmq_objects PROPERTY POSITION_INDEPENDENT_CODE ON)
+ endif()
ENDIF (NOT MSVC)

# shared
@@ -380,6 +372,7 @@ if (CZMQ_BUILD_SHARED)
ENDIF (MSVC)

set_target_properties (czmq PROPERTIES
+ LINKER_LANGUAGE CXX
PUBLIC_HEADER "${public_headers}"
DEFINE_SYMBOL "CZMQ_EXPORTS"
SOVERSION "4"
@@ -501,6 +507,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/czmqConfig.cmake
@@ -501,6 +494,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/czmqConfig.cmake
########################################################################
# executables
########################################################################
+if(0) # disable executables
+if(0)
add_executable(
zmakecert
"${SOURCE_DIR}/src/zmakecert.c"
@@ -588,10 +595,12 @@ target_link_libraries(
${OPTIONAL_LIBRARIES_STATIC}
@@ -720,6 +714,7 @@ add_custom_command(
)
endif()
+endif() # disable executables

########################################################################
# tests
########################################################################
+if(0) # disable tests
set(CLASSTEST_TIMEOUT 60 CACHE STRING "Timeout of the selftest of a class")
set(TOTAL_TIMEOUT 600 CACHE STRING "Timout of the total testsuite")

@@ -687,6 +696,7 @@ foreach(TEST_CLASS ${TEST_CLASSES})
endforeach(TEST_CLASS)

include(CTest)
+endif() # disable tests
include(ClangFormat OPTIONAL)
+endif()

########################################################################
# cleanup
# summary
Loading

0 comments on commit 506b6d9

Please sign in to comment.