aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2017-05-24 14:15:17 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2017-07-12 12:44:41 +0000
commit8ae4d5827d1ccd463b99aaf54c2e8cb482094c91 (patch)
tree729f4acdf7f3cc6a106f119a174330387976b219 /sources
parent64838a9a171a8665ba0ad604870f8f4046cdf142 (diff)
Improve suffix names for shared libraries and cmake config files
This change decouples the naming of general shared libraries, python module extensions, and cmake configuration files. All of them are now computed depending on the python version and python build configuration, and can also be manually set via CMake variables. The module extensions names now use the most detailed 'import' prefix, which usually informs whether a debug or release python was used, or the Python ABI flags (for Python >= 3.2). When a debug Python interpreter is used for building PySide2, the preprocessor define Py_Debug is now correctly propagated to PySide2 sources, which fixes previous crashes in debug builds. This affects only Linux and macOS builds. There is a subsequent change for making it work for Windows builds. All in all, this now allows proper mixing of debug / release versions of the Python interpreter with debug / release versions of PySide2 on Linux and macOS. Task-number: PYSIDE-508 Change-Id: I88a05c3ada0fb32c7c29bdb86d7a2c15acc963b8 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources')
-rw-r--r--sources/pyside2/CMakeLists.txt120
-rw-r--r--sources/pyside2/libpyside/CMakeLists.txt6
-rw-r--r--sources/pyside2/libpyside/PySide2Config-spec.cmake.in8
-rw-r--r--sources/pyside2/libpyside/PySide2Config.cmake.in8
-rw-r--r--sources/pyside2/libpyside/pyside2.pc.in2
-rw-r--r--sources/pyside2/tests/pysidetest/CMakeLists.txt1
-rw-r--r--sources/shiboken2/CMakeLists.txt170
-rw-r--r--sources/shiboken2/data/CMakeLists.txt4
-rw-r--r--sources/shiboken2/data/Shiboken2Config-spec.cmake.in10
-rw-r--r--sources/shiboken2/data/Shiboken2Config.cmake.in8
-rw-r--r--sources/shiboken2/data/shiboken2.pc.in2
-rw-r--r--sources/shiboken2/libshiboken/CMakeLists.txt2
-rw-r--r--sources/shiboken2/shibokenmodule/CMakeLists.txt5
-rw-r--r--sources/shiboken2/tests/minimalbinding/CMakeLists.txt1
-rw-r--r--sources/shiboken2/tests/otherbinding/CMakeLists.txt2
-rw-r--r--sources/shiboken2/tests/samplebinding/CMakeLists.txt2
-rw-r--r--sources/shiboken2/tests/smartbinding/CMakeLists.txt2
17 files changed, 179 insertions, 174 deletions
diff --git a/sources/pyside2/CMakeLists.txt b/sources/pyside2/CMakeLists.txt
index 1c0c5c93..4ac5afa8 100644
--- a/sources/pyside2/CMakeLists.txt
+++ b/sources/pyside2/CMakeLists.txt
@@ -21,90 +21,60 @@ else()
find_package(PythonLibs 2.6)
endif()
-# Queries the python sysconfig for the abi flags which need to be inserted into extension suffixes.
-# Only present starting with Python 3.2.
-# Corresponding configure switches to single letter flags:
-# --with-pymalloc -> m
-# --with-pydebug -> d
-# --with-unicode -> u (rare)
-macro(get_python3_abi_flags)
- if (NOT PYTHON_ABI_FLAGS)
- execute_process(
- COMMAND ${PYTHON_EXECUTABLE} -c "if True:
- import sysconfig
- print(sysconfig.get_config_var('abiflags'))
- "
- OUTPUT_VARIABLE PYTHON_ABI_FLAGS
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- endif()
- message("PYTHON_ABI_FLAGS: " ${PYTHON_ABI_FLAGS})
-endmacro()
+macro(get_python_extension_suffix)
+ # Result of imp.get_suffixes() depends on the platform, but generally looks something like:
+ # [('.cpython-34m-x86_64-linux-gnu.so', 'rb', 3), ('.cpython-34m.so', 'rb', 3),
+ # ('.abi3.so', 'rb', 3), ('.so', 'rb', 3), ('.py', 'r', 1), ('.pyc', 'rb', 2)]
+ # We pick the first most detailed one, strip of the file extension part.
-macro(get_python_multi_arch_suffix)
- # TODO: This part needs testing to check if it is available on Windows.
- # It is present on macOS, but is not used yet.
- # Result is something like 'x86_64-linux-gnu'.
- if (NOT PYTHON_MULTIARCH_SUFFIX)
- execute_process(
- COMMAND ${PYTHON_EXECUTABLE} -c "if True:
- import sysconfig
- print(sysconfig.get_config_var('MULTIARCH'))
- "
- OUTPUT_VARIABLE PYTHON_MULTIARCH_SUFFIX
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- endif()
- message("PYTHON_MULTIARCH_SUFFIX: " ${PYTHON_MULTIARCH_SUFFIX})
-endmacro()
-
-macro(get_python2_release_suffix)
- # Result of imp.get_suffixes() is something like:
- # [('_d.so', 'rb', 3), ('module_d.so', 'rb', 3), ('.x86_64-linux-gnu_d.so', 'rb', 3)]
- # or alternatively the same but withut the '_d' part.
- # The list comprehension is used to choose which suffix to include in library names.
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "if True:
- import imp
- print('_d' if any([tup[0].endswith('_d.so') for tup in imp.get_suffixes()]) else '')
+ import imp, re
+ first_suffix = imp.get_suffixes()[0][0]
+ res = re.search(r'^(.+)\\.', first_suffix)
+ if res:
+ first_suffix = res.group(1)
+ else:
+ first_suffix = ''
+ print(first_suffix)
"
- OUTPUT_VARIABLE PYTHON_MODULE_RELEASE_SUFFIX
+ OUTPUT_VARIABLE PYTHON_EXTENSION_SUFFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)
- message("PYTHON_MODULE_RELEASE_SUFFIX: " ${PYTHON_MODULE_RELEASE_SUFFIX})
+ message("PYTHON_EXTENSION_SUFFIX: " ${PYTHON_EXTENSION_SUFFIX})
endmacro()
-if (UNIX AND NOT APPLE)
+# Note the quirk that UNIX includes Apple!
+if (UNIX)
if (NOT PYTHON_EXTENSION_SUFFIX)
- get_python_multi_arch_suffix()
- # The suffix added to .so libraries should be differenet between Python 2 and 3.
- # The position of the multiarch suffix is different, and the way the debug flag is set
- # computed differently.
- # In Python 2 there is no standard way to query if the python interpeter was built in debug or
- # release build (sysconfig.get_config_var('Py_Debug') can have a different value than you would
- # expect if you do a custom Python build). The solution to query for the import
- # suffixes and check if _d is present there. It is present on Linux distribution
- # packages of Python, but not in custom built Python builds, because the distros apply their
- # custom patches too append the '_d's.
- # In Python 3 (starting with 3.2) there is a standard way to check if '_d' needs to be added,
- # as well as any other letters, by querying the abiflags sysconfig variable.
- if (PYTHON_VERSION_MAJOR EQUAL 2)
- get_python2_release_suffix()
- # The suffix of Python module files (e.g. QtCore.x86_64-linux-gnu_d.so) as well as library
- # libraries (e.g. libpyside2.x86_64-linux-gnu.so).
- if(PYTHON_MULTIARCH_SUFFIX)
- set(PYTHON_EXTENSION_SUFFIX ".${PYTHON_MULTIARCH_SUFFIX}")
- endif()
- set(PYTHON_EXTENSION_SUFFIX "${PYTHON_EXTENSION_SUFFIX}${PYTHON_MODULE_RELEASE_SUFFIX}")
- elseif (PYTHON_VERSION_MAJOR EQUAL 3)
- get_python3_abi_flags()
- set(PYTHON_EXTENSION_SUFFIX ".cpython-${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}${PYTHON_ABI_FLAGS}")
- if(PYTHON_MULTIARCH_SUFFIX)
- set(PYTHON_EXTENSION_SUFFIX "${PYTHON_EXTENSION_SUFFIX}-${PYTHON_MULTIARCH_SUFFIX}")
- endif()
- else()
- message(FATAL_ERROR "Unsupported PYTHON_VERSION=${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.${PYTHON_VERSION_PATCH}!")
- endif()
+ get_python_extension_suffix()
endif()
- message("PYTHON_EXTENSION_SUFFIX: " ${PYTHON_EXTENSION_SUFFIX})
-endif ()
+
+ if (NOT PYTHON_CONFIG_SUFFIX)
+ if (PYTHON_VERSION_MAJOR EQUAL 2)
+ set(PYTHON_CONFIG_SUFFIX "-python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
+ if (PYTHON_EXTENSION_SUFFIX)
+ set(PYTHON_CONFIG_SUFFIX "${PYTHON_CONFIG_SUFFIX}${PYTHON_EXTENSION_SUFFIX}")
+ endif()
+ elseif (PYTHON_VERSION_MAJOR EQUAL 3)
+ set(PYTHON_CONFIG_SUFFIX "${PYTHON_EXTENSION_SUFFIX}")
+ endif()
+ endif()
+
+ if (NOT PYTHON_SHARED_LIBRARY_SUFFIX)
+ set(PYTHON_SHARED_LIBRARY_SUFFIX "${PYTHON_CONFIG_SUFFIX}")
+
+ # Append a "v" to disambiguate the python version and the pyside version in the
+ # shared library file name.
+ if (APPLE AND PYTHON_VERSION_MAJOR EQUAL 2)
+ set(PYTHON_SHARED_LIBRARY_SUFFIX "${PYTHON_SHARED_LIBRARY_SUFFIX}v")
+ endif()
+ endif()
+
+
+ message(STATUS "PYTHON_EXTENSION_SUFFIX: ${PYTHON_EXTENSION_SUFFIX}")
+ message(STATUS "PYTHON_CONFIG_SUFFIX: ${PYTHON_CONFIG_SUFFIX}")
+ message(STATUS "PYTHON_SHARED_LIBRARY_SUFFIX: ${PYTHON_SHARED_LIBRARY_SUFFIX}")
+endif()
find_package(Shiboken2 2.0.0 REQUIRED)
find_package(Qt5 5.6.0 REQUIRED COMPONENTS Core)
diff --git a/sources/pyside2/libpyside/CMakeLists.txt b/sources/pyside2/libpyside/CMakeLists.txt
index 481062ca..05e38330 100644
--- a/sources/pyside2/libpyside/CMakeLists.txt
+++ b/sources/pyside2/libpyside/CMakeLists.txt
@@ -100,7 +100,7 @@ target_link_libraries(pyside2
set_target_properties(pyside2 PROPERTIES
VERSION ${BINDING_API_VERSION}
SOVERSION "${BINDING_API_MAJOR_VERSION}.${BINDING_API_MINOR_VERSION}"
- OUTPUT_NAME "pyside2${pyside2_SUFFIX}${SHIBOKEN_PYTHON_EXTENSION_SUFFIX}"
+ OUTPUT_NAME "pyside2${pyside2_SUFFIX}${SHIBOKEN_PYTHON_SHARED_LIBRARY_SUFFIX}"
DEFINE_SYMBOL PYSIDE_EXPORTS)
if(Qt5Core_VERSION VERSION_GREATER "5.7.1")
@@ -146,7 +146,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/pyside2.pc.in"
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/PySide2Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/PySide2Config.cmake" @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/PySide2Config-spec.cmake.in"
- "${CMAKE_CURRENT_BINARY_DIR}/PySide2Config${SHIBOKEN_PYTHON_EXTENSION_SUFFIX}.cmake" @ONLY)
+ "${CMAKE_CURRENT_BINARY_DIR}/PySide2Config${SHIBOKEN_PYTHON_CONFIG_SUFFIX}.cmake" @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/PySide2ConfigVersion.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/PySide2ConfigVersion.cmake" @ONLY)
@@ -160,7 +160,7 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pyside2${pyside2_SUFFIX}.pc"
DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/PySide2Config.cmake"
DESTINATION "${LIB_INSTALL_DIR}/cmake/PySide2-${BINDING_API_VERSION}")
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/PySide2Config${SHIBOKEN_PYTHON_EXTENSION_SUFFIX}.cmake"
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/PySide2Config${SHIBOKEN_PYTHON_CONFIG_SUFFIX}.cmake"
DESTINATION "${LIB_INSTALL_DIR}/cmake/PySide2-${BINDING_API_VERSION}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/PySide2ConfigVersion.cmake"
DESTINATION "${LIB_INSTALL_DIR}/cmake/PySide2-${BINDING_API_VERSION}")
diff --git a/sources/pyside2/libpyside/PySide2Config-spec.cmake.in b/sources/pyside2/libpyside/PySide2Config-spec.cmake.in
index 205b6f10..822b8e4c 100644
--- a/sources/pyside2/libpyside/PySide2Config-spec.cmake.in
+++ b/sources/pyside2/libpyside/PySide2Config-spec.cmake.in
@@ -6,13 +6,13 @@
SET(PYSIDE_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/include/PySide2@pyside2_SUFFIX@")
# Platform specific library names
if(MSVC)
- SET(PYSIDE_LIBRARY "@LIB_INSTALL_DIR@/@CMAKE_SHARED_LIBRARY_PREFIX@pyside2@pyside2_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@@SHIBOKEN_PYTHON_EXTENSION_SUFFIX@.lib")
+ SET(PYSIDE_LIBRARY "@LIB_INSTALL_DIR@/@CMAKE_SHARED_LIBRARY_PREFIX@pyside2@pyside2_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@@PYTHON_SHARED_LIBRARY_SUFFIX@.lib")
elseif(CYGWIN)
- SET(PYSIDE_LIBRARY "@LIB_INSTALL_DIR@/@CMAKE_SHARED_LIBRARY_PREFIX@pyside2@pyside2_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@@SHIBOKEN_PYTHON_EXTENSION_SUFFIX@@CMAKE_IMPORT_LIBRARY_SUFFIX@")
+ SET(PYSIDE_LIBRARY "@LIB_INSTALL_DIR@/@CMAKE_SHARED_LIBRARY_PREFIX@pyside2@pyside2_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@@PYTHON_SHARED_LIBRARY_SUFFIX@@CMAKE_IMPORT_LIBRARY_SUFFIX@")
elseif(WIN32)
- SET(PYSIDE_LIBRARY "@CMAKE_INSTALL_PREFIX@/bin/@CMAKE_SHARED_LIBRARY_PREFIX@pyside2@pyside2_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@@SHIBOKEN_PYTHON_EXTENSION_SUFFIX@@CMAKE_SHARED_LIBRARY_SUFFIX@")
+ SET(PYSIDE_LIBRARY "@CMAKE_INSTALL_PREFIX@/bin/@CMAKE_SHARED_LIBRARY_PREFIX@pyside2@pyside2_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@@PYTHON_SHARED_LIBRARY_SUFFIX@@CMAKE_SHARED_LIBRARY_SUFFIX@")
else()
- SET(PYSIDE_LIBRARY "@LIB_INSTALL_DIR@/@CMAKE_SHARED_LIBRARY_PREFIX@pyside2@pyside2_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@@SHIBOKEN_PYTHON_EXTENSION_SUFFIX@@CMAKE_SHARED_LIBRARY_SUFFIX@")
+ SET(PYSIDE_LIBRARY "@LIB_INSTALL_DIR@/@CMAKE_SHARED_LIBRARY_PREFIX@pyside2@pyside2_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@@PYTHON_SHARED_LIBRARY_SUFFIX@@CMAKE_SHARED_LIBRARY_SUFFIX@")
endif()
SET(PYSIDE_PYTHONPATH "@SITE_PACKAGE@")
SET(PYSIDE_TYPESYSTEMS "@CMAKE_INSTALL_PREFIX@/share/PySide2@pyside2_SUFFIX@/typesystems")
diff --git a/sources/pyside2/libpyside/PySide2Config.cmake.in b/sources/pyside2/libpyside/PySide2Config.cmake.in
index cf3e6d1a..352a8999 100644
--- a/sources/pyside2/libpyside/PySide2Config.cmake.in
+++ b/sources/pyside2/libpyside/PySide2Config.cmake.in
@@ -1,5 +1,5 @@
-if (NOT PYTHON_BASENAME)
- message(STATUS "PySide2Config: Using default python: @SHIBOKEN_PYTHON_EXTENSION_SUFFIX@")
- SET(PYTHON_BASENAME @SHIBOKEN_PYTHON_EXTENSION_SUFFIX@)
+if (NOT PYTHON_CONFIG_SUFFIX)
+ message(STATUS "PySide2Config: Using default python: @SHIBOKEN_PYTHON_CONFIG_SUFFIX@")
+ SET(PYTHON_CONFIG_SUFFIX @SHIBOKEN_PYTHON_CONFIG_SUFFIX@)
endif()
-include(@LIB_INSTALL_DIR@/cmake/PySide2-@BINDING_API_VERSION@/PySide2Config${PYTHON_BASENAME}.cmake)
+include(@LIB_INSTALL_DIR@/cmake/PySide2-@BINDING_API_VERSION@/PySide2Config${PYTHON_CONFIG_SUFFIX}.cmake)
diff --git a/sources/pyside2/libpyside/pyside2.pc.in b/sources/pyside2/libpyside/pyside2.pc.in
index 4f396ac7..4f8b5e6e 100644
--- a/sources/pyside2/libpyside/pyside2.pc.in
+++ b/sources/pyside2/libpyside/pyside2.pc.in
@@ -8,7 +8,7 @@ pythonpath=@SITE_PACKAGE@
Name: PySide2@pyside2_SUFFIX@
Description: Support library for Python bindings of Qt5-based libraries.
Version: @BINDING_API_VERSION_FULL@
-Libs: -L${libdir} -lpyside2@pyside2_SUFFIX@@SHIBOKEN_PYTHON_EXTENSION_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@
+Libs: -L${libdir} -lpyside2@pyside2_SUFFIX@@SHIBOKEN_PYTHON_CONFIG_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@
Cflags: -I${includedir}
Requires: shiboken2
diff --git a/sources/pyside2/tests/pysidetest/CMakeLists.txt b/sources/pyside2/tests/pysidetest/CMakeLists.txt
index 68916490..0702d608 100644
--- a/sources/pyside2/tests/pysidetest/CMakeLists.txt
+++ b/sources/pyside2/tests/pysidetest/CMakeLists.txt
@@ -88,6 +88,7 @@ target_link_libraries(pysidetest
add_library(testbinding MODULE ${testbinding_SRC})
set_property(TARGET testbinding PROPERTY PREFIX "")
+set_property(TARGET testbinding PROPERTY OUTPUT_NAME "testbinding${PYTHON_EXTENSION_SUFFIX}")
if(WIN32)
set_target_properties(testbinding PROPERTIES SUFFIX ".pyd")
endif()
diff --git a/sources/shiboken2/CMakeLists.txt b/sources/shiboken2/CMakeLists.txt
index 96d4ec5c..549974b8 100644
--- a/sources/shiboken2/CMakeLists.txt
+++ b/sources/shiboken2/CMakeLists.txt
@@ -36,89 +36,60 @@ message("PYTHONINTERP_FOUND: " ${PYTHONINTERP_FOUND})
message("PYTHON_EXECUTABLE: " ${PYTHON_EXECUTABLE})
message("PYTHON_VERSION: " ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.${PYTHON_VERSION_PATCH})
-# Queries the python sysconfig for the abi flags which need to be inserted into extension suffixes.
-# Only present starting with Python 3.2.
-# Corresponding configure switches to single letter flags:
-# --with-pymalloc -> m
-# --with-pydebug -> d
-# --with-unicode -> u (rare)
-macro(get_python3_abi_flags)
- if (NOT PYTHON_ABI_FLAGS)
- execute_process(
- COMMAND ${PYTHON_EXECUTABLE} -c "if True:
- import sysconfig
- print(sysconfig.get_config_var('abiflags'))
- "
- OUTPUT_VARIABLE PYTHON_ABI_FLAGS
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- endif()
- message("PYTHON_ABI_FLAGS: " ${PYTHON_ABI_FLAGS})
-endmacro()
+macro(get_python_extension_suffix)
+ # Result of imp.get_suffixes() depends on the platform, but generally looks something like:
+ # [('.cpython-34m-x86_64-linux-gnu.so', 'rb', 3), ('.cpython-34m.so', 'rb', 3),
+ # ('.abi3.so', 'rb', 3), ('.so', 'rb', 3), ('.py', 'r', 1), ('.pyc', 'rb', 2)]
+ # We pick the first most detailed one, strip of the file extension part.
-macro(get_python_multi_arch_suffix)
- # TODO: This part needs testing to check if it is available on Windows.
- # It is present on macOS, but is not used yet.
- # Result is something like 'x86_64-linux-gnu'.
- if (NOT PYTHON_MULTIARCH_SUFFIX)
- execute_process(
- COMMAND ${PYTHON_EXECUTABLE} -c "if True:
- import sysconfig
- print(sysconfig.get_config_var('MULTIARCH'))
- "
- OUTPUT_VARIABLE PYTHON_MULTIARCH_SUFFIX
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- endif()
- message("PYTHON_MULTIARCH_SUFFIX: " ${PYTHON_MULTIARCH_SUFFIX})
-endmacro()
-
-macro(get_python2_release_suffix)
- # Result of imp.get_suffixes() is something like:
- # [('_d.so', 'rb', 3), ('module_d.so', 'rb', 3), ('.x86_64-linux-gnu_d.so', 'rb', 3)]
- # or alternatively the same but withut the '_d' part.
- # The list comprehension is used to choose which suffix to include in library names.
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "if True:
- import imp
- print('_d' if any([tup[0].endswith('_d.so') for tup in imp.get_suffixes()]) else '')
+ import imp, re
+ first_suffix = imp.get_suffixes()[0][0]
+ res = re.search(r'^(.+)\\.', first_suffix)
+ if res:
+ first_suffix = res.group(1)
+ else:
+ first_suffix = ''
+ print(first_suffix)
"
- OUTPUT_VARIABLE PYTHON_MODULE_RELEASE_SUFFIX
+ OUTPUT_VARIABLE PYTHON_EXTENSION_SUFFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)
- message("PYTHON_MODULE_RELEASE_SUFFIX: " ${PYTHON_MODULE_RELEASE_SUFFIX})
+ message("PYTHON_EXTENSION_SUFFIX: " ${PYTHON_EXTENSION_SUFFIX})
endmacro()
# Note the quirk that UNIX includes Apple!
-if (UNIX AND NOT APPLE)
+if (UNIX)
if (NOT PYTHON_EXTENSION_SUFFIX)
- get_python_multi_arch_suffix()
- # The suffix added to .so libraries should be differenet between Python 2 and 3.
- # The position of the multiarch suffix is different, and the way the debug flag is set
- # computed differently.
- # In Python 2 there is no standard way to query if the python interpeter was built in debug or
- # release build (sysconfig.get_config_var('Py_Debug') can have a different value than you would
- # expect if you do a custom Python build). The solution is to query for the import
- # suffixes and check if _d is present there. It is present on Linux distribution
- # packages of Python, but not in custom built Python builds, because the distros apply their
- # custom patches too append the '_d's.
- # In Python 3 (starting with 3.2) there is a standard way to check if '_d' needs to be added,
- # as well as any other letters, by querying the abiflags sysconfig variable.
- if (PYTHON_VERSION_MAJOR EQUAL 2)
- get_python2_release_suffix()
- if(PYTHON_MULTIARCH_SUFFIX)
- set(PYTHON_EXTENSION_SUFFIX ".${PYTHON_MULTIARCH_SUFFIX}")
- endif()
- set(PYTHON_EXTENSION_SUFFIX "${PYTHON_EXTENSION_SUFFIX}${PYTHON_MODULE_RELEASE_SUFFIX}")
- elseif (PYTHON_VERSION_MAJOR EQUAL 3)
- get_python3_abi_flags()
- set(PYTHON_EXTENSION_SUFFIX ".cpython-${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}${PYTHON_ABI_FLAGS}")
- if(PYTHON_MULTIARCH_SUFFIX)
- set(PYTHON_EXTENSION_SUFFIX "${PYTHON_EXTENSION_SUFFIX}-${PYTHON_MULTIARCH_SUFFIX}")
- endif()
- else()
- message(FATAL_ERROR "Unsupported PYTHON_VERSION=${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.${PYTHON_VERSION_PATCH}!")
- endif()
+ get_python_extension_suffix()
endif()
- message(STATUS "PYTHON_EXTENSION_SUFFIX: ${PYTHON_EXTENSION_SUFFIX}")
-endif ()
+
+ if (NOT PYTHON_CONFIG_SUFFIX)
+ if (PYTHON_VERSION_MAJOR EQUAL 2)
+ set(PYTHON_CONFIG_SUFFIX "-python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
+ if (PYTHON_EXTENSION_SUFFIX)
+ set(PYTHON_CONFIG_SUFFIX "${PYTHON_CONFIG_SUFFIX}${PYTHON_EXTENSION_SUFFIX}")
+ endif()
+ elseif (PYTHON_VERSION_MAJOR EQUAL 3)
+ set(PYTHON_CONFIG_SUFFIX "${PYTHON_EXTENSION_SUFFIX}")
+ endif()
+ endif()
+
+ if (NOT PYTHON_SHARED_LIBRARY_SUFFIX)
+ set(PYTHON_SHARED_LIBRARY_SUFFIX "${PYTHON_CONFIG_SUFFIX}")
+
+ # Append a "v" to disambiguate the python version and the shiboken version in the
+ # shared library file name.
+ if (APPLE AND PYTHON_VERSION_MAJOR EQUAL 2)
+ set(PYTHON_SHARED_LIBRARY_SUFFIX "${PYTHON_SHARED_LIBRARY_SUFFIX}v")
+ endif()
+ endif()
+
+
+ message(STATUS "PYTHON_EXTENSION_SUFFIX: ${PYTHON_EXTENSION_SUFFIX}")
+ message(STATUS "PYTHON_CONFIG_SUFFIX: ${PYTHON_CONFIG_SUFFIX}")
+ message(STATUS "PYTHON_SHARED_LIBRARY_SUFFIX: ${PYTHON_SHARED_LIBRARY_SUFFIX}")
+endif()
if (NOT PYTHON_SITE_PACKAGES)
execute_process(
@@ -184,11 +155,56 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake"
add_custom_target(uninstall "${CMAKE_COMMAND}"
-P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
+
+# Detect if the python libs were compiled in debug mode
+# On Linux distros there is no standard way to check that.
+execute_process(
+ COMMAND ${PYTHON_EXECUTABLE} -c "if True:
+ is_py_debug = False
+ import sys
+ try:
+ sys_py_debug = sys.pydebug
+ if sys_py_debug:
+ is_py_debug = True
+ except:
+ pass
+
+ try:
+ from distutils import sysconfig
+ config_py_debug = sysconfig.get_config_var('Py_DEBUG')
+ if config_py_debug:
+ is_py_debug = True
+ except:
+ pass
+
+ print(bool(is_py_debug))
+ "
+ OUTPUT_VARIABLE PYTHON_WITH_DEBUG
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+# Detect if python interpeter was compiled with COUNT_ALLOCS define
+# Linux distros are inconsistent in setting the sysconfig.get_config_var('COUNT_ALLOCS') value
+execute_process(
+ COMMAND ${PYTHON_EXECUTABLE} -c "if True:
+ count_allocs = False
+ import sys
+ try:
+ if sys.getcounts:
+ count_allocs = True
+ except:
+ pass
+
+ print(bool(count_allocs))
+ "
+ OUTPUT_VARIABLE PYTHON_WITH_COUNT_ALLOCS
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
set(SHIBOKEN_BUILD_TYPE "Release")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(NOT PYTHON_DEBUG_LIBRARIES)
message(WARNING "Python debug shared library not found; assuming python was built with shared library support disabled.")
endif()
+
if(NOT PYTHON_WITH_DEBUG)
message(WARNING "Compiling shiboken2 with debug enabled, but the python executable was not compiled with debug support.")
else()
@@ -196,12 +212,20 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(SBK_ADD_PY_DEBUG_DEFINITION "add_definitions(\"-DPy_DEBUG\")")
set(SBK_PKG_CONFIG_PY_DEBUG_DEFINITION " -DPy_DEBUG")
endif()
+
+ if (PYTHON_WITH_COUNT_ALLOCS)
+ add_definitions("-DCOUNT_ALLOCS")
+ set(SBK_ADD_PY_DEBUG_DEFINITION "${SBK_ADD_PY_DEBUG_DEFINITION} \nadd_definitions(\"-DCOUNT_ALLOCS\")")
+ set(SBK_PKG_CONFIG_PY_DEBUG_DEFINITION "${SBK_PKG_CONFIG_PY_DEBUG_DEFINITION} -DCOUNT_ALLOCS")
+ endif()
+
set(SBK_PYTHON_LIBRARIES ${PYTHON_DEBUG_LIBRARIES})
set(SHIBOKEN_BUILD_TYPE "Debug")
else()
set(SBK_PYTHON_LIBRARIES ${PYTHON_LIBRARIES})
add_definitions("-DNDEBUG")
endif()
+
if(APPLE)
set(SBK_PYTHON_LIBRARIES "-undefined dynamic_lookup")
endif()
diff --git a/sources/shiboken2/data/CMakeLists.txt b/sources/shiboken2/data/CMakeLists.txt
index c36cb148..d248ceb3 100644
--- a/sources/shiboken2/data/CMakeLists.txt
+++ b/sources/shiboken2/data/CMakeLists.txt
@@ -11,7 +11,7 @@ get_target_property(SHIBOKEN_GENERATOR shiboken2 OUTPUT_NAME)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Shiboken2Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/Shiboken2Config.cmake" @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Shiboken2Config-spec.cmake.in"
- "${CMAKE_CURRENT_BINARY_DIR}/Shiboken2Config${PYTHON_EXTENSION_SUFFIX}.cmake" @ONLY)
+ "${CMAKE_CURRENT_BINARY_DIR}/Shiboken2Config${PYTHON_CONFIG_SUFFIX}.cmake" @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Shiboken2ConfigVersion.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/Shiboken2ConfigVersion.cmake" @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/shiboken2.pc.in"
@@ -19,7 +19,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/shiboken2.pc.in"
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Shiboken2Config.cmake"
DESTINATION "${LIB_INSTALL_DIR}/cmake/Shiboken2-${shiboken2_VERSION}")
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Shiboken2Config${PYTHON_EXTENSION_SUFFIX}.cmake"
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Shiboken2Config${PYTHON_CONFIG_SUFFIX}.cmake"
DESTINATION "${LIB_INSTALL_DIR}/cmake/Shiboken2-${shiboken2_VERSION}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Shiboken2ConfigVersion.cmake"
DESTINATION "${LIB_INSTALL_DIR}/cmake/Shiboken2-${shiboken2_VERSION}")
diff --git a/sources/shiboken2/data/Shiboken2Config-spec.cmake.in b/sources/shiboken2/data/Shiboken2Config-spec.cmake.in
index 1aac9caa..9a30d7b4 100644
--- a/sources/shiboken2/data/Shiboken2Config-spec.cmake.in
+++ b/sources/shiboken2/data/Shiboken2Config-spec.cmake.in
@@ -7,13 +7,13 @@
SET(SHIBOKEN_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/include/shiboken2@shiboken2_SUFFIX@")
if(MSVC)
- SET(SHIBOKEN_LIBRARY "@LIB_INSTALL_DIR@/@CMAKE_SHARED_LIBRARY_PREFIX@shiboken2@shiboken2_SUFFIX@@PYTHON_EXTENSION_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@.lib")
+ SET(SHIBOKEN_LIBRARY "@LIB_INSTALL_DIR@/@CMAKE_SHARED_LIBRARY_PREFIX@shiboken2@shiboken2_SUFFIX@@PYTHON_SHARED_LIBRARY_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@.lib")
elseif(CYGWIN)
- SET(SHIBOKEN_LIBRARY "@LIB_INSTALL_DIR@/@CMAKE_IMPORT_LIBRARY_PREFIX@shiboken2@shiboken2_SUFFIX@@PYTHON_EXTENSION_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@@CMAKE_IMPORT_LIBRARY_SUFFIX@")
+ SET(SHIBOKEN_LIBRARY "@LIB_INSTALL_DIR@/@CMAKE_IMPORT_LIBRARY_PREFIX@shiboken2@shiboken2_SUFFIX@@PYTHON_SHARED_LIBRARY_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@@CMAKE_IMPORT_LIBRARY_SUFFIX@")
elseif(WIN32)
- SET(SHIBOKEN_LIBRARY "@CMAKE_INSTALL_PREFIX@/bin/@CMAKE_SHARED_LIBRARY_PREFIX@shiboken2@shiboken2_SUFFIX@@PYTHON_EXTENSION_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@@CMAKE_SHARED_LIBRARY_SUFFIX@")
+ SET(SHIBOKEN_LIBRARY "@CMAKE_INSTALL_PREFIX@/bin/@CMAKE_SHARED_LIBRARY_PREFIX@shiboken2@shiboken2_SUFFIX@@PYTHON_SHARED_LIBRARY_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@@CMAKE_SHARED_LIBRARY_SUFFIX@")
else()
- SET(SHIBOKEN_LIBRARY "@LIB_INSTALL_DIR@/@CMAKE_SHARED_LIBRARY_PREFIX@shiboken2@shiboken2_SUFFIX@@PYTHON_EXTENSION_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@@CMAKE_SHARED_LIBRARY_SUFFIX@")
+ SET(SHIBOKEN_LIBRARY "@LIB_INSTALL_DIR@/@CMAKE_SHARED_LIBRARY_PREFIX@shiboken2@shiboken2_SUFFIX@@PYTHON_SHARED_LIBRARY_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@@CMAKE_SHARED_LIBRARY_SUFFIX@")
endif()
SET(SHIBOKEN_PYTHON_INCLUDE_DIR "@SBK_PYTHON_INCLUDE_DIR@")
SET(SHIBOKEN_PYTHON_INCLUDE_DIR "@SBK_PYTHON_INCLUDE_DIR@")
@@ -23,6 +23,8 @@ SET(SHIBOKEN_PYTHON_VERSION_MINOR "@PYTHON_VERSION_MINOR@")
SET(SHIBOKEN_PYTHON_VERSION_PATCH "@PYTHON_VERSION_PATCH@")
SET(SHIBOKEN_PYTHON_LIBRARIES "@SBK_PYTHON_LIBRARIES@")
SET(SHIBOKEN_PYTHON_EXTENSION_SUFFIX "@PYTHON_EXTENSION_SUFFIX@")
+SET(SHIBOKEN_PYTHON_SHARED_LIBRARY_SUFFIX "@PYTHON_SHARED_LIBRARY_SUFFIX@")
+SET(SHIBOKEN_PYTHON_CONFIG_SUFFIX "@PYTHON_CONFIG_SUFFIX@")
message(STATUS "libshiboken built for @SHIBOKEN_BUILD_TYPE@")
@SBK_ADD_PY_DEBUG_DEFINITION@
diff --git a/sources/shiboken2/data/Shiboken2Config.cmake.in b/sources/shiboken2/data/Shiboken2Config.cmake.in
index 5f7ecaec..515b0d13 100644
--- a/sources/shiboken2/data/Shiboken2Config.cmake.in
+++ b/sources/shiboken2/data/Shiboken2Config.cmake.in
@@ -1,5 +1,5 @@
-if (NOT PYTHON_EXTENSION_SUFFIX)
- message(STATUS "Shiboken2Config: Using default python: @PYTHON_EXTENSION_SUFFIX@")
- SET(PYTHON_EXTENSION_SUFFIX @PYTHON_EXTENSION_SUFFIX@)
+if (NOT PYTHON_CONFIG_SUFFIX)
+ message(STATUS "Shiboken2Config: Using default python: @PYTHON_CONFIG_SUFFIX@")
+ SET(PYTHON_CONFIG_SUFFIX @PYTHON_CONFIG_SUFFIX@)
endif()
-include(@LIB_INSTALL_DIR@/cmake/Shiboken2-@shiboken2_VERSION@/Shiboken2Config${PYTHON_EXTENSION_SUFFIX}.cmake)
+include(@LIB_INSTALL_DIR@/cmake/Shiboken2-@shiboken2_VERSION@/Shiboken2Config${PYTHON_CONFIG_SUFFIX}.cmake)
diff --git a/sources/shiboken2/data/shiboken2.pc.in b/sources/shiboken2/data/shiboken2.pc.in
index aec210c5..99a26298 100644
--- a/sources/shiboken2/data/shiboken2.pc.in
+++ b/sources/shiboken2/data/shiboken2.pc.in
@@ -9,5 +9,5 @@ python_include_dir=@SBK_PYTHON_INCLUDE_DIR@
Name: shiboken2
Description: Support library for Python bindings created with the Shiboken2 generator.
Version: @shiboken2_VERSION@
-Libs: @SBK_PYTHON_LIBRARIES@ -L${libdir} -lshiboken2@shiboken2_SUFFIX@@PYTHON_EXTENSION_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@
+Libs: @SBK_PYTHON_LIBRARIES@ -L${libdir} -lshiboken2@shiboken2_SUFFIX@@PYTHON_SHARED_LIBRARY_SUFFIX@@LIBRARY_OUTPUT_SUFFIX@
Cflags: -I@SBK_PYTHON_INCLUDE_DIR@ -I${includedir}/@shiboken2_SUFFIX@@SBK_PKG_CONFIG_PY_DEBUG_DEFINITION@
diff --git a/sources/shiboken2/libshiboken/CMakeLists.txt b/sources/shiboken2/libshiboken/CMakeLists.txt
index 9ec49d5b..6d2d1c88 100644
--- a/sources/shiboken2/libshiboken/CMakeLists.txt
+++ b/sources/shiboken2/libshiboken/CMakeLists.txt
@@ -45,7 +45,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
${SPARSEHASH_INCLUDE_PATH})
add_library(libshiboken SHARED ${libshiboken_SRC})
target_link_libraries(libshiboken ${SBK_PYTHON_LIBRARIES})
-set_target_properties(libshiboken PROPERTIES OUTPUT_NAME "shiboken2${shiboken2_SUFFIX}${PYTHON_EXTENSION_SUFFIX}"
+set_target_properties(libshiboken PROPERTIES OUTPUT_NAME "shiboken2${shiboken2_SUFFIX}${PYTHON_SHARED_LIBRARY_SUFFIX}"
VERSION ${libshiboken_VERSION}
SOVERSION ${libshiboken_SOVERSION}
DEFINE_SYMBOL LIBSHIBOKEN_EXPORTS)
diff --git a/sources/shiboken2/shibokenmodule/CMakeLists.txt b/sources/shiboken2/shibokenmodule/CMakeLists.txt
index 7e90b51a..5e8e39d5 100644
--- a/sources/shiboken2/shibokenmodule/CMakeLists.txt
+++ b/sources/shiboken2/shibokenmodule/CMakeLists.txt
@@ -24,7 +24,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
${libshiboken_BINARY_DIR})
add_library(shibokenmodule MODULE ${sample_SRC})
set_property(TARGET shibokenmodule PROPERTY PREFIX "")
-set_property(TARGET shibokenmodule PROPERTY OUTPUT_NAME "shiboken2")
+set_property(TARGET shibokenmodule PROPERTY OUTPUT_NAME "shiboken2${PYTHON_EXTENSION_SUFFIX}")
+
if(WIN32)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set_property(TARGET shibokenmodule PROPERTY OUTPUT_NAME "shiboken2_d")
@@ -37,4 +38,4 @@ target_link_libraries(shibokenmodule
add_dependencies(shibokenmodule shiboken2)
-install(TARGETS shibokenmodule DESTINATION ${PYTHON_SITE_PACKAGES}) \ No newline at end of file
+install(TARGETS shibokenmodule DESTINATION ${PYTHON_SITE_PACKAGES})
diff --git a/sources/shiboken2/tests/minimalbinding/CMakeLists.txt b/sources/shiboken2/tests/minimalbinding/CMakeLists.txt
index fb0b2cc7..7edb0290 100644
--- a/sources/shiboken2/tests/minimalbinding/CMakeLists.txt
+++ b/sources/shiboken2/tests/minimalbinding/CMakeLists.txt
@@ -29,6 +29,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
${libshiboken_SOURCE_DIR})
add_library(minimal MODULE ${minimal_SRC})
set_property(TARGET minimal PROPERTY PREFIX "")
+set_property(TARGET minimal PROPERTY OUTPUT_NAME "minimal${PYTHON_EXTENSION_SUFFIX}")
if(WIN32)
set_property(TARGET minimal PROPERTY SUFFIX ".pyd")
endif()
diff --git a/sources/shiboken2/tests/otherbinding/CMakeLists.txt b/sources/shiboken2/tests/otherbinding/CMakeLists.txt
index ac7178e5..7d4dd5b5 100644
--- a/sources/shiboken2/tests/otherbinding/CMakeLists.txt
+++ b/sources/shiboken2/tests/otherbinding/CMakeLists.txt
@@ -35,6 +35,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
${libshiboken_SOURCE_DIR})
add_library(other MODULE ${other_SRC})
set_property(TARGET other PROPERTY PREFIX "")
+set_property(TARGET other PROPERTY OUTPUT_NAME "other${PYTHON_EXTENSION_SUFFIX}")
+
if(WIN32)
set_property(TARGET other PROPERTY SUFFIX ".pyd")
endif()
diff --git a/sources/shiboken2/tests/samplebinding/CMakeLists.txt b/sources/shiboken2/tests/samplebinding/CMakeLists.txt
index f897712f..1b97bd0e 100644
--- a/sources/shiboken2/tests/samplebinding/CMakeLists.txt
+++ b/sources/shiboken2/tests/samplebinding/CMakeLists.txt
@@ -136,6 +136,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
${libshiboken_SOURCE_DIR})
add_library(sample MODULE ${sample_SRC})
set_property(TARGET sample PROPERTY PREFIX "")
+set_property(TARGET sample PROPERTY OUTPUT_NAME "sample${PYTHON_EXTENSION_SUFFIX}")
+
if(WIN32)
set_property(TARGET sample PROPERTY SUFFIX ".pyd")
endif()
diff --git a/sources/shiboken2/tests/smartbinding/CMakeLists.txt b/sources/shiboken2/tests/smartbinding/CMakeLists.txt
index e9c52d44..aab2121d 100644
--- a/sources/shiboken2/tests/smartbinding/CMakeLists.txt
+++ b/sources/shiboken2/tests/smartbinding/CMakeLists.txt
@@ -30,6 +30,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
${libshiboken_SOURCE_DIR})
add_library(smart MODULE ${smart_SRC})
set_property(TARGET smart PROPERTY PREFIX "")
+set_property(TARGET smart PROPERTY OUTPUT_NAME "smart${PYTHON_EXTENSION_SUFFIX}")
+
if(WIN32)
set_property(TARGET smart PROPERTY SUFFIX ".pyd")
endif()