Skip to content
Open
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
10 changes: 8 additions & 2 deletions cmake/DetectOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,15 @@ endif()

# ZeroMQ
if(ADIOS2_USE_ZeroMQ STREQUAL AUTO)
find_package(ZeroMQ 4.1)
find_package(ZeroMQ 4.1 CONFIG)
if(NOT ZeroMQ_FOUND)
find_package(ZeroMQ 4.1 MODULE)
endif()
elseif(ADIOS2_USE_ZeroMQ)
find_package(ZeroMQ 4.1 REQUIRED)
find_package(ZeroMQ 4.1 CONFIG)
if(NOT ZeroMQ_FOUND)
find_package(ZeroMQ 4.1 MODULE REQUIRED)
endif()
endif()
if(ZeroMQ_FOUND)
set(ADIOS2_HAVE_ZeroMQ TRUE)
Expand Down
63 changes: 21 additions & 42 deletions cmake/FindZeroMQ.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,28 @@
#
# SPDX-License-Identifier: Apache-2.0

if(ZeroMQ_FOUND)
return()
endif()

if(NOT ZeroMQ_FOUND)
if((NOT ZeroMQ_ROOT) AND (NOT (ENV{ZeroMQ_ROOT} STREQUAL "")))
set(ZeroMQ_ROOT "$ENV{ZeroMQ_ROOT}")
endif()
if(ZeroMQ_ROOT)
set(ZeroMQ_INCLUDE_OPTS HINTS ${ZeroMQ_ROOT}/include NO_DEFAULT_PATHS)
set(ZeroMQ_LIBRARY_OPTS
HINTS ${ZeroMQ_ROOT}/lib ${ZeroMQ_ROOT}/lib64
NO_DEFAULT_PATHS
)
endif()
# Use find_package instead of find_dependency because we do NOT want PkgConfig to be REQUIRED.
# If PkgConfig is missing, we simply stop without producing a fatal error.
find_package(PkgConfig QUIET)
if(NOT PkgConfig_FOUND)
return()
endif()

find_path(ZeroMQ_INCLUDE_DIR zmq.h ${ZeroMQ_INCLUDE_OPTS})
find_library(ZeroMQ_LIBRARY zmq ${ZeroMQ_LIBRARY_OPTS})
if(ZeroMQ_INCLUDE_DIR)
file(STRINGS ${ZeroMQ_INCLUDE_DIR}/zmq.h _ver_strings
REGEX "ZMQ_VERSION_[^ ]* [0-9]+"
)
foreach(v IN LISTS _ver_strings)
string(REGEX MATCH "ZMQ_VERSION_([^ ]+) ([0-9]+)" v "${v}")
set(ZeroMQ_VERSION_${CMAKE_MATCH_1} ${CMAKE_MATCH_2})
endforeach()
set(ZeroMQ_VERSION
${ZeroMQ_VERSION_MAJOR}.${ZeroMQ_VERSION_MINOR}.${ZeroMQ_VERSION_PATCH}
)
endif()
pkg_check_modules(libzmq IMPORTED_TARGET libzmq)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ZeroMQ
FOUND_VAR ZeroMQ_FOUND
VERSION_VAR ZeroMQ_VERSION
REQUIRED_VARS ZeroMQ_LIBRARY ZeroMQ_INCLUDE_DIR
)
if(ZeroMQ_FOUND)
set(ZeroMQ_INCLUDE_DIRS ${ZeroMQ_INCLUDE_DIR})
set(ZeroMQ_LIBRARIES ${ZeroMQ_LIBRARY})
if(ZeroMQ_FOUND AND NOT TARGET ZeroMQ::ZMQ)
add_library(ZeroMQ::ZMQ UNKNOWN IMPORTED)
set_target_properties(ZeroMQ::ZMQ PROPERTIES
IMPORTED_LOCATION "${ZeroMQ_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${ZeroMQ_INCLUDE_DIR}"
)
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
ZeroMQ
REQUIRED_VARS libzmq_FOUND
VERSION_VAR libzmq_VERSION
)
# Create alias target to match imported target name of the native package
# Only create the alias if ZeroMQ was successfully found.
# This prevents creating an alias when version checks failed or the module is incomplete.
if(ZeroMQ_FOUND AND TARGET PkgConfig::libzmq)
add_library(libzmq ALIAS PkgConfig::libzmq)
endif()
2 changes: 0 additions & 2 deletions examples/hello/datamanKokkos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ if(NOT TARGET adios2_core)
list(APPEND _components MPI)
endif()

find_package(ZeroMQ 4.1 QUIET)

find_package(Kokkos 3.7 QUIET)
if(Kokkos_FOUND AND DEFINED Kokkos_CXX_COMPILER)
set(CMAKE_CXX_COMPILER "${Kokkos_CXX_COMPILER}")
Expand Down
2 changes: 0 additions & 2 deletions examples/hello/datamanReader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ if(NOT TARGET adios2_core)
list(APPEND _components MPI)
endif()

find_package(ZeroMQ 4.1 QUIET)

find_package(ADIOS2 REQUIRED COMPONENTS ${_components})
endif()

Expand Down
2 changes: 0 additions & 2 deletions examples/hello/datamanWriter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ if(NOT TARGET adios2_core)
list(APPEND _components MPI)
endif()

find_package(ZeroMQ 4.1 QUIET)

find_package(ADIOS2 REQUIRED COMPONENTS ${_components})
endif()

Expand Down
2 changes: 1 addition & 1 deletion source/adios2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ if(ADIOS2_HAVE_ZeroMQ)
toolkit/zmq/zmqreqrep/ZmqReqRep.cpp
toolkit/zmq/zmqpubsub/ZmqPubSub.cpp
)
target_link_libraries(adios2_core PRIVATE ZeroMQ::ZMQ)
target_link_libraries(adios2_core PRIVATE libzmq)
endif()

if(ADIOS2_HAVE_DataMan)
Expand Down
10 changes: 5 additions & 5 deletions source/adios2/toolkit/zmq/zmqpubsub/ZmqPubSub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ ZmqPubSub::~ZmqPubSub()
void ZmqPubSub::OpenPublisher(const std::string &address)
{
m_ZmqContext = zmq_ctx_new();
if (not m_ZmqContext)
if (!m_ZmqContext)
{
helper::Throw<std::runtime_error>("Toolkit", "ZmqPubSub", "OpenPublisher",
"creating zmq context failed");
}

m_ZmqSocket = zmq_socket(m_ZmqContext, ZMQ_PUB);
if (not m_ZmqSocket)
if (!m_ZmqSocket)
{
helper::Throw<std::runtime_error>("Toolkit", "ZmqPubSub", "OpenPublisher",
"creating zmq socket failed");
Expand All @@ -59,14 +59,14 @@ void ZmqPubSub::OpenPublisher(const std::string &address)
void ZmqPubSub::OpenSubscriber(const std::string &address, const size_t bufferSize)
{
m_ZmqContext = zmq_ctx_new();
if (not m_ZmqContext)
if (!m_ZmqContext)
{
helper::Throw<std::runtime_error>("Toolkit", "ZmqPubSub", "OpenSubscriber",
"creating zmq context failed");
}

m_ZmqSocket = zmq_socket(m_ZmqContext, ZMQ_SUB);
if (not m_ZmqSocket)
if (!m_ZmqSocket)
{
helper::Throw<std::runtime_error>("Toolkit", "ZmqPubSub", "OpenSubscriber",
"creating zmq socket failed");
Expand All @@ -86,7 +86,7 @@ void ZmqPubSub::OpenSubscriber(const std::string &address, const size_t bufferSi

void ZmqPubSub::Send(std::shared_ptr<std::vector<char>> buffer)
{
if (buffer != nullptr and buffer->size() > 0)
if (buffer != nullptr && buffer->size() > 0)
{
zmq_send(m_ZmqSocket, buffer->data(), buffer->size(), ZMQ_DONTWAIT);
}
Expand Down
4 changes: 2 additions & 2 deletions source/adios2/toolkit/zmq/zmqreqrep/ZmqReqRep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace zmq
ZmqReqRep::ZmqReqRep()
{
m_Context = zmq_ctx_new();
if (not m_Context)
if (!m_Context)
{
helper::Throw<std::runtime_error>("Toolkit", "ZmqReqRep", "ZmqReqRep",
"creating zmq context failed");
Expand Down Expand Up @@ -77,7 +77,7 @@ void ZmqReqRep::OpenReplier(const std::string &address, const int timeout,
m_ReceiverBuffer.reserve(receiverBufferSize);

m_Socket = zmq_socket(m_Context, ZMQ_REP);
if (not m_Socket)
if (!m_Socket)
{
helper::Throw<std::runtime_error>("Toolkit", "ZmqReqRep", "OpenReplier",
"creating zmq socket failed");
Expand Down