@@ -146,7 +146,7 @@ endfunction()
146146
147147include (CMakeDependentOption )
148148
149- set (CMAKE_INSTALL_PREFIX "/usr/ local/cytnx" CACHE PATH "Destination path for installation" )
149+ set (CMAKE_INSTALL_PREFIX "~/. local/cytnx" CACHE PATH "Destination path for installation" )
150150option (BUILD_PYTHON "Build Python API. Requires Python and pybind11 installed." ON )
151151option (BACKEND_TORCH "Use PyTorch as a backend container for tensors." OFF )
152152cmake_dependent_option (USE_MKL "Use MKL as a BLAS provider otherwise use OpenBLAS." OFF "NOT BACKEND_TORCH" OFF )
@@ -339,7 +339,7 @@ IF(BUILD_PYTHON)
339339 endif ()
340340 endif ()
341341
342- pybind11_add_module (pycytnx SHARED pybind/cytnx.cpp
342+ pybind11_add_module (pycytnx MODULE pybind/cytnx.cpp
343343 pybind/generator_py.cpp
344344 pybind/storage_py.cpp
345345 pybind/tensor_py.cpp
@@ -357,13 +357,31 @@ IF(BUILD_PYTHON)
357357 pybind/ncon_py.cpp
358358 )
359359 target_link_libraries (pycytnx PUBLIC cytnx )
360+
361+ # On macOS, Python extensions should NOT link to libpython
362+ # Use -undefined dynamic_lookup to resolve symbols from the running interpreter
363+ if (APPLE )
364+ target_link_options (pycytnx PRIVATE "-undefined" "dynamic_lookup" )
365+ endif ()
360366 set_target_properties (pycytnx PROPERTIES OUTPUT_NAME cytnx )
361367 message (STATUS "pybind11 include dir: ${CUTENSOR_LIBRARY_DIRS} " )
362368 message (STATUS "pybind11 include dir: ${CUQUANTUM_LIBRARY_DIRS} " )
363- set_target_properties (pycytnx
364- PROPERTIES
365- INSTALL_RPATH "${CUTENSOR_LIBRARY_DIRS} ;${CUQUANTUM_LIBRARY_DIRS} "
366- )
369+ message (STATUS "pybind11 include dir: ${LAPACK_LIBRARY_DIRS} " )
370+ message (STATUS "pybind11 include dir: ${LAPACKE_LIBRARY_DIRS} " )
371+ # Configure RPATH for macOS to make the Python extension relocatable
372+ if (APPLE )
373+ set_target_properties (pycytnx
374+ PROPERTIES
375+ BUILD_WITH_INSTALL_RPATH TRUE
376+ INSTALL_RPATH_USE_LINK_PATH TRUE
377+ INSTALL_RPATH "@loader_path;@loader_path/../../../lib;${CMAKE_INSTALL_PREFIX} /lib"
378+ )
379+ else ()
380+ set_target_properties (pycytnx
381+ PROPERTIES
382+ INSTALL_RPATH "${CMAKE_INSTALL_RPATH} ;${CMAKE_INSTALL_PREFIX} /lib"
383+ )
384+ endif ()
367385
368386 message (STATUS " Build Python Wrapper: YES" )
369387 message (STATUS " - Python Excutable : ${PYTHON_EXECUTABLE} " )
0 commit comments