From 5e0cfeee907a19c2554c4c1e1f0b44ba09d2df62 Mon Sep 17 00:00:00 2001 From: Robert Taylor Date: Thu, 22 Dec 2022 08:54:15 +0000 Subject: [PATCH] half written macro for statically linking libpython to binaries in manylinux --- bootstrap/cmake_modules/FindBootstrap.cmake | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/bootstrap/cmake_modules/FindBootstrap.cmake b/bootstrap/cmake_modules/FindBootstrap.cmake index 010d7093..013663b1 100644 --- a/bootstrap/cmake_modules/FindBootstrap.cmake +++ b/bootstrap/cmake_modules/FindBootstrap.cmake @@ -408,7 +408,7 @@ add_library( ${clib} ${pyCpps} ) set_target_properties( ${clib} PROPERTIES VERSION ${version} SOVERSION ${soversion}) - #target_compile_definitions( ${clib} PUBLIC Py_LIMITED_API=1) + target_compile_definitions( ${clib} PUBLIC Py_LIMITED_API=1) target_link_libraries( ${clib} ${deplibs} ) install( TARGETS ${clib} DESTINATION lib${LIB_SUFFIX} ) target_link_options( ${clib} PRIVATE "LINKER:--unresolved-symbols=ignore-in-object-files") @@ -422,7 +422,7 @@ PREFIX "" OUTPUT_NAME ${pymodule} ) - #target_compile_definitions( ${pytarget} PUBLIC Py_LIMITED_API=1) + target_compile_definitions( ${pytarget} PUBLIC Py_LIMITED_API=1) target_link_libraries( ${pytarget} ${pyDeplibs} ) install( TARGETS ${pytarget} DESTINATION ${Python_CORIOLISARCH} ) @@ -446,10 +446,25 @@ add_library( ${pymodule} MODULE ${pyCpps} ) set_target_properties( ${pymodule} PROPERTIES PREFIX "" ) target_link_libraries( ${pymodule} ${deplibs} ) - # target_compile_definitions( ${pymodule} PUBLIC Py_LIMITED_API=1) + target_compile_definitions( ${pymodule} PUBLIC Py_LIMITED_API=1) install( TARGETS ${pymodule} DESTINATION ${Python_CORIOLISARCH} ) if( NOT ("${pyIncludes}" STREQUAL "None") ) install( FILES ${pyIncludes} DESTINATION ${inc_install_dir} ) endif() endmacro( add_python_module3 ) + + + macro(target_python_executable target) + get_target_property(target_type ${target} TYPE) + if (target_type STREQUAL "EXECUTABLE") + find_package(Python3 COMPONENTS Developer.Embed) + if (Python_Development.Embed_FOUND) + target_link_libraries(${target} Python::Python) + elseif (EXISTS /opt/_internal/static-libs-for-embedding-only.tar.xz + AND NOT DEFINED Python3_PyPy_VERSION) + # We're in manylinux environment, extract the embedding static library ans use it + # Note, linking an executable that needs to embed python is the *ONLY* valid use for this! + set(_PYTHON_MANYLINUX_NAME "cpython-${Python3_VERSION}") + set(_PYTHON_MANYLINUX_STATIC_LIB "${_PYTHON_MANYLINUX_NAME}/lib/libpython-${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}" + file (ARCHIVE_EXTRACT INPUT /opt/_internal/static-libs-for-embedding-only.tar.xz