Skip to content

Commit 26c9792

Browse files
SwooshyCuebalanking
authored andcommitted
[#145] Identify libpython soname at configure-time
1 parent f546280 commit 26c9792

3 files changed

Lines changed: 46 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,37 @@ find_package(OpenSSL REQUIRED COMPONENTS Crypto SSL)
4141
find_package(nlohmann_json "3.6.1" REQUIRED)
4242
find_package(Python "${IRODS_PYTHON_VERSION}" REQUIRED COMPONENTS Development)
4343

44+
if (NOT IRODS_PYTHON_SONAME)
45+
get_target_property(IRODS_PYTHON_SONAME Python::Python IMPORTED_SONAME)
46+
if (NOT IRODS_PYTHON_SONAME)
47+
get_target_property(__PYTHON_IMPORTED_LOCATION Python::Python IMPORTED_LOCATION)
48+
if (__PYTHON_IMPORTED_LOCATION)
49+
if (IS_SYMLINK "${__PYTHON_IMPORTED_LOCATION}")
50+
file(READ_SYMLINK "${__PYTHON_IMPORTED_LOCATION}" __PYTHON_LIBRARY_PATH)
51+
else()
52+
set(__PYTHON_LIBRARY_PATH "${__PYTHON_IMPORTED_LOCATION}")
53+
endif()
54+
get_filename_component(IRODS_PYTHON_SONAME "${__PYTHON_LIBRARY_PATH}" NAME)
55+
else()
56+
# We might be able to use python-config before falling back to guessing like this.
57+
if (Python_VERSION_MAJOR EQUAL "3" AND Python_VERSION_MINOR LESS "8")
58+
set(__PYTHON_VERSION_SUFFIX "m")
59+
else()
60+
set(__PYTHON_VERSION_SUFFIX "")
61+
endif()
62+
set(IRODS_PYTHON_SONAME "${CMAKE_SHARED_LIBRARY_PREFIX}python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}${__PYTHON_VERSION_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}.1.0")
63+
endif()
64+
endif()
65+
message("Python SONAME detected as ${IRODS_PYTHON_SONAME}")
66+
endif()
67+
68+
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include/irods/private/re/python")
69+
configure_file(
70+
"${CMAKE_CURRENT_SOURCE_DIR}/include/irods/private/re/python/config.hpp.in"
71+
"${CMAKE_CURRENT_BINARY_DIR}/include/irods/private/re/python/config.hpp"
72+
@ONLY
73+
)
74+
4475
set(
4576
PLUGIN
4677
irods_rule_engine_plugin-python
@@ -154,6 +185,7 @@ target_include_directories(
154185
${PLUGIN}
155186
PRIVATE
156187
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
188+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
157189
${IRODS_INCLUDE_DIRS}
158190
${IRODS_EXTERNALS_FULLPATH_BOOST}/include
159191
${IRODS_EXTERNALS_FULLPATH_FMT}/include
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef IRODS_RE_PYTHON_CONFIG_HPP
2+
#define IRODS_RE_PYTHON_CONFIG_HPP
3+
4+
// include this first to fix macro redef warnings
5+
#include <pyconfig.h>
6+
7+
#cmakedefine IRODS_PYTHON_SONAME "@IRODS_PYTHON_SONAME"
8+
9+
#endif // IRODS_RE_PYTHON_CONFIG_HPP

src/main.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <irods/rsExecMyRule.hpp>
3636

3737
#include "irods/private/re/python.hpp"
38+
#include "irods/private/re/python/config.hpp"
3839

3940
#include <patchlevel.h>
4041
#pragma GCC diagnostic push
@@ -314,19 +315,14 @@ namespace
314315

315316
irods::error start(irods::default_re_ctx&, const std::string& _instance_name)
316317
{
317-
// TODO Enable config-selectable Python version
318-
#if PY_VERSION_HEX < 0x03000000
319-
void* p = dlopen(
320-
"libpython2.7.so",
321-
RTLD_LAZY | RTLD_GLOBAL); // https://mail.python.org/pipermail/new-bugs-announce/2008-November/003322.html
322-
#else
323-
void* p =
324-
dlopen("libpython3.6m.so.1.0", RTLD_LAZY | RTLD_GLOBAL); // Kludge for bionic; proper solution forthcoming.
325-
#endif
318+
#ifdef IRODS_PYTHON_SONAME
319+
// Force python library to be loaded
320+
void* p = dlopen(IRODS_PYTHON_SONAME, RTLD_LAZY | RTLD_GLOBAL);
326321
rodsLog(LOG_DEBUG, "dlopen returned: [%p]", p);
327322
if (!p) {
328323
rodsLog(LOG_DEBUG, "dlerror gives : [%s]", dlerror());
329324
}
325+
#endif
330326

331327
try {
332328
#if PY_VERSION_HEX < 0x03000000

0 commit comments

Comments
 (0)