Skip to content

Commit 04dc993

Browse files
committed
cmake: split extension
Into suffix and debug postfix. Pybind11 is currently treating both as suffix, which is problematic when something else defines the DEBUG_POSTFIX because they will be concatenated. pybind11_extension sets SUFFIX to _d.something and if DEBUG_POSTFIX is set to _d. _d + _d.something = _d_d.something The issue has been reported at: pybind#4699
1 parent f3e0602 commit 04dc993

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

tools/pybind11NewTools.cmake

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,31 @@ endif()
9595

9696
# Get the suffix - SO is deprecated, should use EXT_SUFFIX, but this is
9797
# required for PyPy3 (as of 7.3.1)
98-
if(NOT DEFINED PYTHON_MODULE_EXTENSION)
98+
if(NOT DEFINED PYTHON_MODULE_EXTENSION OR NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX)
9999
execute_process(
100100
COMMAND
101101
"${${_Python}_EXECUTABLE}" "-c"
102-
"import sys, importlib; s = importlib.import_module('distutils.sysconfig' if sys.version_info < (3, 10) else 'sysconfig'); print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'))"
103-
OUTPUT_VARIABLE _PYTHON_MODULE_EXTENSION
104-
ERROR_VARIABLE _PYTHON_MODULE_EXTENSION_ERR
102+
"import sys, importlib; s = importlib.import_module('distutils.sysconfig' if sys.version_info < (3, 10) else 'sysconfig'); print((s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO')).replace('.', ';.', 1))"
103+
OUTPUT_VARIABLE _PYTHON_MODULE_EXT_SUFFIX
104+
ERROR_VARIABLE _PYTHON_MODULE_EXT_SUFFIX_ERR
105105
OUTPUT_STRIP_TRAILING_WHITESPACE)
106106

107-
if(_PYTHON_MODULE_EXTENSION STREQUAL "")
107+
if(_PYTHON_MODULE_EXT_SUFFIX STREQUAL "")
108108
message(
109109
FATAL_ERROR "pybind11 could not query the module file extension, likely the 'distutils'"
110-
"package is not installed. Full error message:\n${_PYTHON_MODULE_EXTENSION_ERR}")
110+
"package is not installed. Full error message:\n${_PYTHON_MODULE_EXT_SUFFIX_ERR}")
111111
endif()
112112

113113
# This needs to be available for the pybind11_extension function
114-
set(PYTHON_MODULE_EXTENSION
115-
"${_PYTHON_MODULE_EXTENSION}"
116-
CACHE INTERNAL "")
114+
if(NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX)
115+
list(GET _PYTHON_MODULE_EXT_SUFFIX 0 _PYTHON_MODULE_DEBUG_POSTFIX)
116+
set(PYTHON_MODULE_DEBUG_POSTFIX "${_PYTHON_MODULE_DEBUG_POSTFIX}" CACHE INTERNAL "")
117+
endif()
118+
119+
if(NOT DEFINED PYTHON_MODULE_EXTENSION)
120+
list(GET _PYTHON_MODULE_EXT_SUFFIX 1 _PYTHON_MODULE_EXTENSION)
121+
set(PYTHON_MODULE_EXTENSION "${_PYTHON_MODULE_EXTENSION}" CACHE INTERNAL "")
122+
endif()
117123
endif()
118124

119125
# Python debug libraries expose slightly different objects before 3.8
@@ -251,6 +257,5 @@ endfunction()
251257

252258
function(pybind11_extension name)
253259
# The extension is precomputed
254-
set_target_properties(${name} PROPERTIES PREFIX "" SUFFIX "${PYTHON_MODULE_EXTENSION}")
255-
260+
set_target_properties(${name} PROPERTIES PREFIX "" DEBUG_POSTFIX "${PYTHON_MODULE_DEBUG_POSTFIX}" SUFFIX "${PYTHON_MODULE_EXTENSION}")
256261
endfunction()

0 commit comments

Comments
 (0)