@@ -31,7 +31,53 @@ option(PYPYLON_INCLUDE_DATA_PROCESSING "Include pylon data processing support" O
31
31
set (PYPYLON_MIN_LIMITED_API_VERSION "0x03090000" CACHE STRING "Minimum Python version for limited API" )
32
32
33
33
# Find required packages
34
- find_package (Python REQUIRED COMPONENTS Interpreter Development.Module )
34
+ if (PYPYLON_USE_LIMITED_API AND Python_VERSION VERSION_GREATER_EQUAL "3.9" )
35
+ # For limited API, we need both Interpreter and Module
36
+ find_package (Python REQUIRED COMPONENTS Interpreter Development.Module )
37
+ set (Python_LIMITED_API TRUE )
38
+ add_compile_definitions (Py_LIMITED_API=${PYPYLON_MIN_LIMITED_API_VERSION} )
39
+ message (STATUS "Using Python Limited API: ${PYPYLON_MIN_LIMITED_API_VERSION} " )
40
+
41
+ # For limited API on Windows, we need to ensure python3.lib is available
42
+ if (WIN32 )
43
+ # Check if python3.lib exists in the Python installation
44
+ get_target_property (PYTHON_LIBRARY Python::Module IMPORTED_LOCATION )
45
+ if (PYTHON_LIBRARY )
46
+ get_filename_component (PYTHON_LIB_DIR ${PYTHON_LIBRARY} DIRECTORY )
47
+ set (PYTHON3_LIB "${PYTHON_LIB_DIR} /python3.lib" )
48
+ if (EXISTS "${PYTHON3_LIB} " )
49
+ message (STATUS "Found python3.lib at: ${PYTHON3_LIB} " )
50
+ else ()
51
+ message (WARNING "python3.lib not found at ${PYTHON3_LIB} , limited API may fail" )
52
+ # Try to find it in the libs directory
53
+ set (PYTHON3_LIB_ALT "${PYTHON_LIB_DIR} /libs/python3.lib" )
54
+ if (EXISTS "${PYTHON3_LIB_ALT} " )
55
+ message (STATUS "Found python3.lib at: ${PYTHON3_LIB_ALT} " )
56
+ else ()
57
+ message (WARNING "python3.lib not found in libs directory either" )
58
+ endif ()
59
+ endif ()
60
+ endif ()
61
+ endif ()
62
+
63
+ message (STATUS "Using Python::Module for limited API" )
64
+ else ()
65
+ # For regular builds, use Module
66
+ find_package (Python REQUIRED COMPONENTS Interpreter Development.Module )
67
+ message (STATUS "Using regular Python API with Python::Module" )
68
+ endif ()
69
+
70
+ # For limited API builds, ensure we're using the correct Python library
71
+ if (PYPYLON_USE_LIMITED_API AND Python_VERSION VERSION_GREATER_EQUAL "3.9" )
72
+ # When using limited API, we need to ensure the Python library is correctly configured
73
+ if (TARGET Python::Module )
74
+ # Get the Python library path and ensure it's correct
75
+ get_target_property (PYTHON_LIBRARY Python::Module IMPORTED_LOCATION )
76
+ if (PYTHON_LIBRARY )
77
+ message (STATUS "Python library for limited API: ${PYTHON_LIBRARY} " )
78
+ endif ()
79
+ endif ()
80
+ endif ()
35
81
find_package (SWIG 4.3 REQUIRED )
36
82
37
83
# Include SWIG
@@ -116,6 +162,17 @@ if(PYPYLON_USE_LIMITED_API AND Python_VERSION VERSION_GREATER_EQUAL "3.9")
116
162
set (Python_LIMITED_API TRUE )
117
163
add_compile_definitions (Py_LIMITED_API=${PYPYLON_MIN_LIMITED_API_VERSION} )
118
164
message (STATUS "Using Python Limited API: ${PYPYLON_MIN_LIMITED_API_VERSION} " )
165
+
166
+ # For limited API builds, we might need to adjust the Python library configuration
167
+ if (TARGET Python::Module )
168
+ # Ensure the Python library is correctly set for limited API
169
+ get_target_property (PYTHON_LIBRARY Python::Module IMPORTED_LOCATION )
170
+ if (PYTHON_LIBRARY )
171
+ message (STATUS "Python library configured: ${PYTHON_LIBRARY} " )
172
+ endif ()
173
+ endif ()
174
+ else ()
175
+ message (STATUS "Python Limited API disabled" )
119
176
endif ()
120
177
121
178
# Common compile definitions
0 commit comments