|
1 | | -cmake_minimum_required(VERSION 3.12 FATAL_ERROR) #FindPython |
| 1 | +cmake_minimum_required(VERSION 3.13 FATAL_ERROR) |
| 2 | +# 3.12: FindPython |
| 3 | +# 3.13: target_link_options |
2 | 4 |
|
3 | 5 | find_package(IRODS REQUIRED) |
4 | 6 | set(IRODS_PLUGIN_REVISION "1") |
@@ -41,10 +43,10 @@ find_package(OpenSSL REQUIRED COMPONENTS Crypto SSL) |
41 | 43 | find_package(nlohmann_json "3.6.1" REQUIRED) |
42 | 44 | find_package(Python "${IRODS_PYTHON_VERSION}" REQUIRED COMPONENTS Development) |
43 | 45 |
|
| 46 | +get_target_property(__PYTHON_IMPORTED_LOCATION Python::Python IMPORTED_LOCATION) |
44 | 47 | if (NOT IRODS_PYTHON_SONAME) |
45 | 48 | get_target_property(IRODS_PYTHON_SONAME Python::Python IMPORTED_SONAME) |
46 | 49 | if (NOT IRODS_PYTHON_SONAME) |
47 | | - get_target_property(__PYTHON_IMPORTED_LOCATION Python::Python IMPORTED_LOCATION) |
48 | 50 | if (__PYTHON_IMPORTED_LOCATION) |
49 | 51 | if (IS_SYMLINK "${__PYTHON_IMPORTED_LOCATION}") |
50 | 52 | file(READ_SYMLINK "${__PYTHON_IMPORTED_LOCATION}" __PYTHON_LIBRARY_PATH) |
@@ -203,9 +205,40 @@ target_link_libraries( |
203 | 205 | irods_common |
204 | 206 | irods_server |
205 | 207 | nlohmann_json::nlohmann_json |
206 | | - Python::Python |
207 | 208 | ) |
208 | 209 |
|
| 210 | +# Since we are embedding Python rather than just creating extension modules, we must link to |
| 211 | +# libpython. However, the build-time linker will silently drop libpython unless we pass |
| 212 | +# --no-as-needed just before libpython. Furthermore, Python::Python might specify multiple |
| 213 | +# libraries, and other libraries may be passed after libpython. To mitigate this, we toggle off |
| 214 | +# --as-needed just for Python::Python's IMPORTED_LOCATION. If we can't fetch IMPORTED_LOCATION, we |
| 215 | +# just toggle it for Python::Python. |
| 216 | +if (__PYTHON_IMPORTED_LOCATION) |
| 217 | + target_link_libraries( |
| 218 | + ${PLUGIN} |
| 219 | + PRIVATE |
| 220 | + Python::Python |
| 221 | + -Wl,--no-as-needed |
| 222 | + "${__PYTHON_IMPORTED_LOCATION}" |
| 223 | + -Wl,--as-needed |
| 224 | + ) |
| 225 | +else() |
| 226 | + target_link_libraries( |
| 227 | + ${PLUGIN} |
| 228 | + PRIVATE |
| 229 | + -Wl,--no-as-needed |
| 230 | + Python::Python |
| 231 | + -Wl,--as-needed |
| 232 | + ) |
| 233 | +endif() |
| 234 | + |
| 235 | +# Disable lazy-loading |
| 236 | +target_link_options( |
| 237 | + ${PLUGIN} |
| 238 | + PRIVATE |
| 239 | + -Wl,-z,now |
| 240 | + ) |
| 241 | + |
209 | 242 | target_compile_definitions( |
210 | 243 | ${PLUGIN} |
211 | 244 | PRIVATE |
|
0 commit comments