@@ -71,8 +71,18 @@ if(PYBIND11_MASTER_PROJECT)
71
71
endif ()
72
72
73
73
# Debug check - see https://stackoverflow.com/questions/646518/python-how-to-detect-debug-Interpreter
74
- execute_process (COMMAND ${_Python} ::Python -c "import sys; print(hasattr(sys, 'gettotalrefcount'))"
75
- OUTPUT_VARIABLE PYTHON_IS_DEBUG )
74
+ execute_process (
75
+ COMMAND "${${_Python} _EXECUTABLE}" "-c"
76
+ "import sys; sys.exit(1 - hasattr(sys, 'gettotalrefcount'))"
77
+ RESULT_VARIABLE PYTHON_IS_DEBUG )
78
+
79
+ # Get the suffix - SO is deprecated, should use EXT_SUFFIX, but this is
80
+ # required for PyPy3 (as of 7.3.1)
81
+ execute_process (
82
+ COMMAND "${${_Python} _EXECUTABLE}" "-c"
83
+ "from distutils import sysconfig; print(sysconfig.get_config_var('SO'))"
84
+ OUTPUT_VARIABLE PYTHON_MODULE_EXTENSION
85
+ ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE )
76
86
77
87
# Python debug libraries expose slightly different objects before 3.8
78
88
# https://docs.python.org/3.6/c-api/intro.html#debugging-builds
@@ -121,8 +131,11 @@ else()
121
131
PROPERTY INTERFACE_LINK_LIBRARIES pybind11::python_link_helper )
122
132
endif ()
123
133
134
+ # WITHOUT_SOABI and WITH_SOABI will disable the custom extension handling used by pybind11.
135
+ # WITH_SOABI is passed on to python_add_library.
124
136
function (pybind11_add_module target_name )
125
- cmake_parse_arguments (PARSE_ARGV 1 ARG "STATIC;SHARED;MODULE;THIN_LTO;NO_EXTRAS" "" "" )
137
+ cmake_parse_arguments (PARSE_ARGV 1 ARG "STATIC;SHARED;MODULE;THIN_LTO;NO_EXTRAS;WITHOUT_SOABI"
138
+ "" "" )
126
139
127
140
if (ARG_ADD_LIBRARY_STATIC )
128
141
set (type STATIC )
@@ -133,11 +146,11 @@ function(pybind11_add_module target_name)
133
146
endif ()
134
147
135
148
if ("${_Python} " STREQUAL "Python" )
136
- python_add_library (${target_name} ${type} WITH_SOABI ${ARG_UNPARSED_ARGUMENTS} )
149
+ python_add_library (${target_name} ${type} ${ARG_UNPARSED_ARGUMENTS} )
137
150
elseif ("${_Python} " STREQUAL "Python3" )
138
- python3_add_library (${target_name} ${type} WITH_SOABI ${ARG_UNPARSED_ARGUMENTS} )
151
+ python3_add_library (${target_name} ${type} ${ARG_UNPARSED_ARGUMENTS} )
139
152
elseif ("${_Python} " STREQUAL "Python2" )
140
- python2_add_library (${target_name} ${type} WITH_SOABI ${ARG_UNPARSED_ARGUMENTS} )
153
+ python2_add_library (${target_name} ${type} ${ARG_UNPARSED_ARGUMENTS} )
141
154
else ()
142
155
message (FATAL_ERROR "Cannot detect FindPython version: ${_Python} " )
143
156
endif ()
@@ -161,6 +174,11 @@ function(pybind11_add_module target_name)
161
174
set_target_properties (${target_name} PROPERTIES CXX_VISIBILITY_PRESET "hidden"
162
175
CUDA_VISIBILITY_PRESET "hidden" )
163
176
177
+ # If we don't pass a WITH_SOABI or WITHOUT_SOABI, use our own default handling of extensions
178
+ if (NOT ARG_WITHOUT_SOABI OR "WITH_SOABI" IN_LIST ARG_UNPARSED_ARGUMENTS )
179
+ pybind11_extension (${target_name} )
180
+ endif ()
181
+
164
182
if (ARG_NO_EXTRAS )
165
183
return ()
166
184
endif ()
@@ -184,20 +202,7 @@ function(pybind11_add_module target_name)
184
202
endfunction ()
185
203
186
204
function (pybind11_extension name )
187
- set_property (TARGET ${name} PROPERTY PREFIX "" )
188
-
189
- if (CMAKE_SYSTEM_NAME STREQUAL "Windows" )
190
- set_property (TARGET ${name} PROPERTY SUFFIX ".pyd" )
191
- endif ()
205
+ # The extension is precomputed
206
+ set_target_properties (${name} PROPERTIES PREFIX "" SUFFIX "${PYTHON_MODULE_EXTENSION} " )
192
207
193
- if (${_Python} _SOABI )
194
- get_property (
195
- suffix
196
- TARGET ${name}
197
- PROPERTY SUFFIX )
198
- if (NOT suffix )
199
- set (suffix "${CMAKE_SHARED_MODULE_SUFFIX} " )
200
- endif ()
201
- set_property (TARGET ${name} PROPERTY SUFFIX ".${${_Python} _SOABI}${suffix} " )
202
- endif ()
203
208
endfunction ()
0 commit comments