Skip to content

Commit

Permalink
add ZMQ_PREFIX to $RPATH by default
Browse files Browse the repository at this point in the history
old setup.py used to try to do this
  • Loading branch information
minrk committed Apr 29, 2024
1 parent acfcaf1 commit 33de609
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 19 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ endif()
# legacy pyzmq env options, no PYZMQ_ prefix
set(ZMQ_PREFIX "auto" CACHE STRING "libzmq installation prefix or 'bundled'")
option(ZMQ_DRAFT_API "whether to build the libzmq draft API" OFF)
option(PYZMQ_LIBZMQ_RPATH "Add $ZMQ_PREFIX/lib to $RPATH (true by default). Set to false if libzmq will be bundled or relocated and RPATH is handled separately" ON)

# anything new should start with PYZMQ_
option(PYZMQ_LIBZMQ_NO_BUNDLE "Prohibit building bundled libzmq. Useful for repackaging, to allow default search for libzmq and requiring it to succeed." OFF)
Expand All @@ -37,7 +38,7 @@ endif()
# get options from env

# handle booleans
foreach(_optname ZMQ_DRAFT_API PYZMQ_NO_BUNDLE)
foreach(_optname ZMQ_DRAFT_API PYZMQ_NO_BUNDLE PYZMQ_LIBZMQ_RPATH)
if (DEFINED ENV{${_optname}})
if ("$ENV{${_optname}}" STREQUAL "1" OR "$ENV{${_optname}}" STREQUAL "ON")
set(${_optname} TRUE)
Expand Down Expand Up @@ -115,6 +116,12 @@ if (ZMQ_PREFIX STREQUAL "auto")
set(ZeroMQ_FOUND TRUE)
set(libzmq_target "PkgConfig::libzmq")
message(CHECK_PASS "found: -L${libzmq_LIBRARY_DIRS} -l${libzmq_LIBRARIES}")
if (PYZMQ_LIBZMQ_RPATH)
foreach(LIBZMQ_LIB_DIR IN LISTS libzmq_LIBRARY_DIRS)
message(STATUS " Adding ${LIBZMQ_LIB_DIR} to RPATH, set PYZMQ_LIBZMQ_RPATH=OFF if this is not what you want.")
list(APPEND CMAKE_INSTALL_RPATH "${LIBZMQ_LIB_DIR}")
endforeach()
endif()
else()
message(CHECK_FAIL "no")
endif()
Expand All @@ -130,6 +137,12 @@ if (ZMQ_PREFIX STREQUAL "auto")
if (LIBZMQ_LIBRARY AND LIBZMQ_INCLUDE_DIR)
set(ZeroMQ_FOUND TRUE)
message(CHECK_PASS "${LIBZMQ_LIBRARY}")
# NOTE: we _could_ set RPATH here. Should we? Unclear.
if (PYZMQ_LIBZMQ_RPATH)
get_filename_component(LIBZMQ_LIB_DIR "${LIBZMQ_LIBRARY}" DIRECTORY)
message(STATUS " Adding ${LIBZMQ_LIB_DIR} to RPATH, set PYZMQ_LIBZMQ_RPATH=OFF if this is not what you want.")
list(APPEND CMAKE_INSTALL_RPATH "${LIBZMQ_LIB_DIR}")
endif()
endif()
endif()

Expand Down Expand Up @@ -157,6 +170,11 @@ elseif (NOT ZMQ_PREFIX STREQUAL "bundled")
)
if (LIBZMQ_LIBRARY AND LIBZMQ_INCLUDE_DIR)
message(CHECK_PASS "${LIBZMQ_LIBRARY}")
if (PYZMQ_LIBZMQ_RPATH)
# add prefix to RPATH
message(STATUS " Adding ${ZMQ_PREFIX}/lib to RPATH, set PYZMQ_LIBZMQ_RPATH=OFF if this is not what you want.")
list(APPEND CMAKE_INSTALL_RPATH "${ZMQ_PREFIX}/lib")
endif()
else()
message(CHECK_FAIL "no")
message(FATAL_ERROR "libzmq not found in ZMQ_PREFIX=${ZMQ_PREFIX}")
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ musllinux-x86_64-image = "musllinux_1_1"

[tool.cibuildwheel.linux.environment]
ZMQ_PREFIX = "/usr/local"
PYZMQ_LIBZMQ_RPATH = "OFF"
CFLAGS = "-Wl,-strip-all"
CXXFLAGS = "-Wl,-strip-all"

Expand All @@ -166,6 +167,7 @@ before-all = "bash tools/install_libzmq.sh"

[tool.cibuildwheel.macos.environment]
ZMQ_PREFIX = "/tmp/zmq"
PYZMQ_LIBZMQ_RPATH = "OFF"
MACOSX_DEPLOYMENT_TARGET = "10.9"

[tool.cibuildwheel.windows]
Expand Down

0 comments on commit 33de609

Please sign in to comment.