From 3d059843ff23118c8bfa642132b76f269a38b4ed Mon Sep 17 00:00:00 2001 From: meshula Date: Tue, 14 Feb 2023 16:47:39 -0800 Subject: [PATCH] Python crashed. FATAL ERROR: Failed axiom: Py_IsInitialized() PXR_PY_UNDEFINED_DYNAMIC_LOOKUP might be explicitly set when packaging wheels, or when cross compiling to a Python environment that is not the current interpreter environment. If it was not explicitly set to ON or OFF, then determine whether Python was statically linked to its runtime library by fetching the sysconfig variable LDLIBRARY, and set the variable accordingly. If the variable does not exist, PXR_PY_UNDEFINED_DYNAMIC_LOOKUP will default to OFF. On Windows, LDLIBRARY does not exist, as the default will always be OFF. Fixes #1620 (Internal change: 2263328) --- cmake/defaults/Packages.cmake | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/cmake/defaults/Packages.cmake b/cmake/defaults/Packages.cmake index 84bd48becf..b0623d1d58 100644 --- a/cmake/defaults/Packages.cmake +++ b/cmake/defaults/Packages.cmake @@ -76,6 +76,28 @@ if(PXR_ENABLE_PYTHON_SUPPORT) file(TO_CMAKE_PATH ${PYTHON_INCLUDE_DIRS} PYTHON_INCLUDE_DIRS) endif() + # PXR_PY_UNDEFINED_DYNAMIC_LOOKUP might be explicitly set when + # packaging wheels, or when cross compiling to a Python environment + # that is not the current interpreter environment. + # If it was not explicitly set to ON or OFF, then determine whether + # Python was statically linked to its runtime library by fetching the + # sysconfig variable LDLIBRARY, and set the variable accordingly. + # If the variable does not exist, PXR_PY_UNDEFINED_DYNAMIC_LOOKUP will + # default to OFF. On Windows, LDLIBRARY does not exist, as the default + # will always be OFF. + if((NOT WIN32) AND (NOT DEFINED PXR_PY_UNDEFINED_DYNAMIC_LOOKUP)) + execute_process(COMMAND ${PYTHON_EXECUTABLE} "-c" "import sysconfig;print(sysconfig.get_config_var('LDLIBRARY'))" + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE PXR_PYTHON_LINKED_LIBRARY + ) + get_filename_component(PXR_PYTHON_LINKED_LIBRARY_EXT ${PXR_PYTHON_LINKED_LIBRARY} LAST_EXT) + if(PXR_PYTHON_LINKED_LIBRARY_EXT STREQUAL ".a") + set(PXR_PY_UNDEFINED_DYNAMIC_LOOKUP ON) + message(STATUS + "PXR_PY_UNDEFINED_DYNAMIC_LOOKUP wasn't specified, forced ON because Python statically links ${PXR_PYTHON_LINKED_LIBRARY}") + endif() + endif() + # This option indicates that we don't want to explicitly link to the # python libraries. See BUILDING.md for details. if(PXR_PY_UNDEFINED_DYNAMIC_LOOKUP AND NOT WIN32) @@ -97,7 +119,7 @@ if(PXR_ENABLE_PYTHON_SUPPORT) # Manually specify VS2022, 2019, and 2017 as USD's supported compiler versions if(WIN32) - set(Boost_COMPILER "-vc143;-vc142;-vc141") + set(Boost_COMPILER "-vc143;-vc142;-vc141") endif() # As of boost 1.67 the boost_python component name includes the @@ -112,7 +134,7 @@ if(PXR_ENABLE_PYTHON_SUPPORT) set(python_version_nodot "${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}") find_package(Boost COMPONENTS - python${python_version_nodot} + python${python_version_nodot} REQUIRED ) set(Boost_PYTHON_LIBRARY "${Boost_PYTHON${python_version_nodot}_LIBRARY}")