Skip to content
Snippets Groups Projects
Commit bccda895 authored by Andreas Dedner's avatar Andreas Dedner
Browse files

[!799] [cmake] Force ".so" suffix for pybind11 module libraries on macOS

Merge branch 'feature/python-force-library-so-suffix-for-macos' into 'master'

ref:core/dune-common\> The issue is discussed in this old thread on
stackoverflow:
[https://stackoverflow.com/questions/2488016/how-to-make-python-load-dylib-on-osx]

Somehow Python refuses to import dynamic libraries with the suffix .dylib (I
get an import error) which is the common suffix for shared libs in macOS.
Telling CMake to use .so instead as suggested in the stackoverflow thread
works for me.

The Python libs on for my Python 3.7 from homebrew all have .so endings just
like in the stackoverflow answer.

Fixes [#201]

See merge request [!799]

  [https://stackoverflow.com/questions/2488016/how-to-make-python-load-dylib-on-osx]:
    https://stackoverflow.com/questions/2488016/how-to-make-python-load-dylib-on-osx
  [#201]: gitlab.dune-project.org/NoneNone/issues/201
  [!799]: gitlab.dune-project.org/core/dune-common/merge_requests/799


Closes #201
parents f5d55718 eefd7050
Branches
Tags
1 merge request!799[cmake] Force ".so" suffix for pybind11 module libraries on macOS
Pipeline #28078 passed
......@@ -72,6 +72,17 @@ function(dune_add_pybind11_module)
add_library(${PYBIND11_MODULE_NAME} SHARED ${PYBIND11_MODULE_SOURCES})
set_target_properties(${PYBIND11_MODULE_NAME} PROPERTIES PREFIX "")
# force '.so' as library suffix on macOS due to a problem in Python
# https://stackoverflow.com/questions/2488016/how-to-make-python-load-dylib-on-osx
# and add -undefined dynamic_lookup flag to linker
# https://pybind11.readthedocs.io/en/stable/compiling.html#building-manually
if (APPLE)
set_target_properties(${PYBIND11_MODULE_NAME} PROPERTIES SUFFIX ".so")
target_link_options(${PYBIND11_MODULE_NAME} PRIVATE "-undefined")
target_link_options(${PYBIND11_MODULE_NAME} PRIVATE "dynamic_lookup")
endif()
target_compile_definitions(${PYBIND11_MODULE_NAME} PRIVATE ${PYBIND11_MODULE_COMPILE_DEFINITIONS})
dune_target_enable_all_packages(${PYBIND11_MODULE_NAME})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment