From 33de60997c3b22e8c992a33f44cbeff6331a19ad Mon Sep 17 00:00:00 2001 From: Min RK Date: Mon, 29 Apr 2024 11:18:28 +0200 Subject: [PATCH] add ZMQ_PREFIX to $RPATH by default old setup.py used to try to do this --- CMakeLists.txt | 20 +++++++++++++++++++- pyproject.toml | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 62ffa841d..87910c81b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) @@ -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() @@ -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() @@ -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}") diff --git a/pyproject.toml b/pyproject.toml index 662621758..7c11d5b36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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]