diff options
author | Christian Tismer <ctismer@gmail.com> | 2015-12-02 20:08:57 +0100 |
---|---|---|
committer | Christian Tismer <ctismer@gmail.com> | 2015-12-02 20:08:57 +0100 |
commit | fc7e44469a6252c59a1919842a553c0c30d2ad87 (patch) | |
tree | bed856ce2dc029aeaa6bc5e507a908f93257d698 | |
parent | 5d3a6eb462c24bc35639ad6c5bf44ba1d579c59f (diff) | |
parent | fb1d8437442fdbc8c3b31a8bb8e31f641c9a916e (diff) |
Merge branch 'python3_unix_fix'
* python3_unix_fix:
fixing the python3 build on unixen.
-rw-r--r-- | CMakeLists.txt | 23 | ||||
-rw-r--r-- | cmake/Modules/FindPython3Interp.cmake | 48 | ||||
-rw-r--r-- | cmake/Modules/FindPython3InterpWithDebug.cmake | 56 | ||||
-rw-r--r-- | cmake/Modules/FindPython3Libs.cmake | 210 | ||||
-rw-r--r-- | cmake/Modules/FindPythonInterpWithDebug.cmake | 6 |
5 files changed, 8 insertions, 335 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e473749..b491ecc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,26 +20,15 @@ option(BUILD_TESTS "Build tests." TRUE) option(USE_PYTHON3 "Use python3 libraries to build shiboken2." FALSE) if (USE_PYTHON3) - find_package(Python3Libs) - find_package(Python3Interp) - find_package(Python3InterpWithDebug) - #use common vars - set(PYTHONLIBS_FOUND ${PYTHON3LIBS_FOUND}) - set(PYTHON_LIBRARIES ${PYTHON3_LIBRARIES}) - set(PYTHON_INCLUDE_DIRS ${PYTHON3_INCLUDE_DIRS}) - set(PYTHON_DEBUG_LIBRARIES ${PYTHON3_DEBUG_LIBRARIES}) - set(PYTHONINTERP_FOUND ${PYTHON3INTERP_FOUND}) - set(PYTHON_EXECUTABLE ${PYTHON3_EXECUTABLE}) - set(PYTHON_VERSION_MAJOR ${PYTHON3_VERSION_MAJOR}) - set(PYTHON_VERSION_MINOR ${PYTHON3_VERSION_MINOR}) - set(PYTHON_VERSION_PATCH ${PYTHON3_VERSION_PATCH}) + find_package(PythonInterp 3.3) + find_package(PythonLibs 3.3) + find_package(PythonInterpWithDebug 3.3) else() - find_package(PythonInterp) + find_package(PythonInterp 2.6) find_package(PythonLibs 2.6) - find_package(PythonInterpWithDebug) + find_package(PythonInterpWithDebug 2.6) endif() - if (NOT PYTHON_SITE_PACKAGES) execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "if True: @@ -151,5 +140,3 @@ add_custom_target(dist bzip2 -f9 "${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar" && echo "Source package created at ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2." WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) - - diff --git a/cmake/Modules/FindPython3Interp.cmake b/cmake/Modules/FindPython3Interp.cmake deleted file mode 100644 index 373982e..0000000 --- a/cmake/Modules/FindPython3Interp.cmake +++ /dev/null @@ -1,48 +0,0 @@ -# - Find python interpreter -# This module finds if Python interpreter is installed and determines where the -# executables are. This code sets the following variables: -# -# PYTHONINTERP3_FOUND - Was the Python executable found -# PYTHON3_EXECUTABLE - path to the Python interpreter -# - -#============================================================================= -# Copyright 2005-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distributed this file outside of CMake, substitute the full -# License text for the above reference.) - -FIND_PROGRAM(PYTHON3_EXECUTABLE - NAMES python3.2mu python3.2m python3.2u python3.2 python3.1 python3.0 python3 - PATHS - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.2\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.1\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.0\\InstallPath] - ) - -FIND_PROGRAM(PYTHON3_DBG_EXECUTABLE - NAMES python3.2dmu python3.2dm python3.2du python3.2d python3.1-dbg python3.0-dbg python3-dbg - PATHS - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.2\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.1\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.0\\InstallPath] - ) - - -# handle the QUIETLY and REQUIRED arguments and set PYTHONINTERP_FOUND to TRUE if -# all listed variables are TRUE -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Python3Interp DEFAULT_MSG PYTHON3_EXECUTABLE) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Python3InterpDbg DEFAULT_MSG PYTHON3_DBG_EXECUTABLE) - -MARK_AS_ADVANCED(PYTHON3_EXECUTABLE) -MARK_AS_ADVANCED(PYTHON3_DBG_EXECUTABLE) - - diff --git a/cmake/Modules/FindPython3InterpWithDebug.cmake b/cmake/Modules/FindPython3InterpWithDebug.cmake deleted file mode 100644 index 7f4d44c..0000000 --- a/cmake/Modules/FindPython3InterpWithDebug.cmake +++ /dev/null @@ -1,56 +0,0 @@ -INCLUDE(FindPython3Interp) -INCLUDE(FindPython3Libs) - -find_package(Python3Interp REQUIRED) - -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - # This is for Debian - set(PYTHON3_EXECUTABLE_TMP "${PYTHON3_DBG_EXECUTABLE}") - - # Fall back to the standard interpreter. - if(NOT EXISTS "${PYTHON3_EXECUTABLE_TMP}") - set(PYTHON3_EXECUTABLE_TMP "${PYTHON3_EXECUTABLE}") - endif() - - set(PYTHON3_EXECUTABLE "${PYTHON3_EXECUTABLE_TMP}") -endif() - -# Detect if the python libs were compiled in debug mode -execute_process( - COMMAND ${PYTHON3_EXECUTABLE} -c "if True: - from distutils import sysconfig - print(bool(sysconfig.get_config_var('Py_DEBUG'))) - " - OUTPUT_VARIABLE PYTHON_WITH_DEBUG - OUTPUT_STRIP_TRAILING_WHITESPACE) - -message("PYTHON WITH DEBUG: ${PYTHON3_EXECUTABLE}") - -execute_process( - COMMAND ${PYTHON3_EXECUTABLE} -c "if True: - import sys - from distutils import sysconfig - vr = sys.version_info - prefix = '-python%d.%d' % (vr[0], vr[1]) - suffix = prefix + '-dbg' if bool(sysconfig.get_config_var('Py_DEBUG')) else prefix - suffix = ('.' + sysconfig.get_config_var('SOABI') - if vr.major == 3 and vr.minor >= 2 and 'SOABI' in sysconfig.get_config_vars() - else suffix) - print(suffix) - " - OUTPUT_VARIABLE PYTHON_SUFFIX - OUTPUT_STRIP_TRAILING_WHITESPACE) - -#Fix missing variable on UNIX env -if(NOT PYTHON3_DEBUG_LIBRARIES AND UNIX) - string(REPLACE "-dbg" "" PYTHON_NAME_AUX ${PYTHON_SUFFIX}) - string(REPLACE "-python" "python" PYTHON_NAME ${PYTHON_NAME_AUX}) - find_library(LIBRARY_FOUND ${PYTHON_NAME}_d) - if (LIBRARY_FOUND) - set(PYTHON3_DEBUG_LIBRARIES "${LIBRARY_FOUND}") - else() - set(PYTHON3_DEBUG_LIBRARIES "${PYTHON3_LIBRARIES}") - endif() -endif() - - diff --git a/cmake/Modules/FindPython3Libs.cmake b/cmake/Modules/FindPython3Libs.cmake deleted file mode 100644 index 20a82ba..0000000 --- a/cmake/Modules/FindPython3Libs.cmake +++ /dev/null @@ -1,210 +0,0 @@ -# - Find python libraries -# This module finds if Python is installed and determines where the -# include files and libraries are. It also determines what the name of -# the library is. This code sets the following variables: -# -# PYTHONLIBS3_FOUND - have the Python libs been found -# PYTHON3_LIBRARIES - path to the python library -# PYTHON3_INCLUDE_DIRS - path to where Python.h is found -# PYTHON3_DEBUG_LIBRARIES - path to the debug library -# - -#============================================================================= -# Copyright 2001-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distributed this file outside of CMake, substitute the full -# License text for the above reference.) - -INCLUDE(CMakeFindFrameworks) -# Is there a python3 framework? How do we search for it? -# Search for the python framework on Apple. -# CMAKE_FIND_FRAMEWORKS(Python) - -FOREACH(_CURRENT_VERSION 3.4 3.3 3.2 3.1 3.0) - IF(_CURRENT_VERSION GREATER 3.1) - SET(_32FLAGS "m" "u" "mu" "dm" "du" "dmu" "") - ELSE() - SET(_32FLAGS "") - ENDIF() - FOREACH(_COMPILATION_FLAGS ${_32FLAGS}) - STRING(REPLACE "." "" _CURRENT_VERSION_NO_DOTS ${_CURRENT_VERSION}) - IF(WIN32) - IF(_CURRENT_VERSION GREATER 3.1) - FIND_LIBRARY(PYTHON3_DEBUG_LIBRARY - NAMES python${_CURRENT_VERSION_NO_DOTS}d${_COMPILATION_FLAGS} python - PATHS - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs/Debug - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs ) - ELSE() - FIND_LIBRARY(PYTHON3_DEBUG_LIBRARY - NAMES python${_CURRENT_VERSION_NO_DOTS}${_COMPILATION_FLAGS}_d python - PATHS - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs/Debug - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs ) - ENDIF() - ENDIF(WIN32) - - FIND_LIBRARY(PYTHON3_LIBRARY - NAMES python${_CURRENT_VERSION_NO_DOTS}${_COMPILATION_FLAGS} python${_CURRENT_VERSION}${_COMPILATION_FLAGS} - PATHS - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs - # Avoid finding the .dll in the PATH. We want the .lib. - NO_SYSTEM_ENVIRONMENT_PATH - ) - # Look for the static library in the Python config directory - FIND_LIBRARY(PYTHON3_LIBRARY - NAMES python${_CURRENT_VERSION_NO_DOTS}${_COMPILATION_FLAGS} python${_CURRENT_VERSION}${_COMPILATION_FLAGS} - # Avoid finding the .dll in the PATH. We want the .lib. - NO_SYSTEM_ENVIRONMENT_PATH - # This is where the static library is usually located - PATH_SUFFIXES python${_CURRENT_VERSION}/config - ) - - IF(_CURRENT_VERSION GREATER 3.1) - FIND_LIBRARY(PYTHON3_DEBUG_LIBRARY - NAMES python${_CURRENT_VERSION_NO_DOTS}d${_COMPILATION_FLAGS} python${_CURRENT_VERSION}d${_COMPILATION_FLAGS} - PATHS - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs - # Avoid finding the .dll in the PATH. We want the .lib. - NO_SYSTEM_ENVIRONMENT_PATH - ) - # Look for the static library in the Python config directory - FIND_LIBRARY(PYTHON3_DEBUG_LIBRARY - NAMES python${_CURRENT_VERSION_NO_DOTS}d${_COMPILATION_FLAGS} python${_CURRENT_VERSION}d${_COMPILATION_FLAGS} - # Avoid finding the .dll in the PATH. We want the .lib. - NO_SYSTEM_ENVIRONMENT_PATH - # This is where the static library is usually located - PATH_SUFFIXES python${_CURRENT_VERSION}/config - ) - ENDIF() - -# SET(PYTHON_FRAMEWORK_INCLUDES) -# IF(Python_FRAMEWORKS AND NOT PYTHON_INCLUDE_DIR) -# FOREACH(dir ${Python_FRAMEWORKS}) -# SET(PYTHON_FRAMEWORK_INCLUDES ${PYTHON_FRAMEWORK_INCLUDES} -# ${dir}/Versions/${_CURRENT_VERSION}/include/python${_CURRENT_VERSION}) -# ENDFOREACH(dir) -# ENDIF(Python_FRAMEWORKS AND NOT PYTHON_INCLUDE_DIR) - - FIND_PATH(PYTHON3_INCLUDE_DIR - NAMES Python.h - PATHS - ${PYTHON_FRAMEWORK_INCLUDES} - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include - PATH_SUFFIXES - python${_CURRENT_VERSION}${_COMPILATION_FLAGS} - ) - - # For backward compatibility, set PYTHON_INCLUDE_PATH, but make it internal. - SET(PYTHON_INCLUDE_PATH "${PYTHON_INCLUDE_DIR}" CACHE INTERNAL - "Path to where Python.h is found (deprecated)") - ENDFOREACH(_COMPILATION_FLAGS) -ENDFOREACH(_CURRENT_VERSION) - -MARK_AS_ADVANCED( - PYTHON3_DEBUG_LIBRARY - PYTHON3_LIBRARY - PYTHON3_INCLUDE_DIR -) - -# We use PYTHON3_INCLUDE_DIR, PYTHON3_LIBRARY and PYTHON3_DEBUG_LIBRARY for the -# cache entries because they are meant to specify the location of a single -# library. We now set the variables listed by the documentation for this -# module. -SET(PYTHON3_INCLUDE_DIRS "${PYTHON3_INCLUDE_DIR}") -SET(PYTHON3_LIBRARIES "${PYTHON3_LIBRARY}") -SET(PYTHON3_DEBUG_LIBRARIES "${PYTHON3_DEBUG_LIBRARY}") - - -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Python3Libs DEFAULT_MSG PYTHON3_LIBRARIES PYTHON3_INCLUDE_DIRS) - - -# PYTHON_ADD_MODULE(<name> src1 src2 ... srcN) is used to build modules for python. -# PYTHON_WRITE_MODULES_HEADER(<filename>) writes a header file you can include -# in your sources to initialize the static python modules - -GET_PROPERTY(_TARGET_SUPPORTS_SHARED_LIBS - GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS) - -FUNCTION(PYTHON3_ADD_MODULE _NAME ) - OPTION(PYTHON3_ENABLE_MODULE_${_NAME} "Add module ${_NAME}" TRUE) - OPTION(PYTHON3_MODULE_${_NAME}_BUILD_SHARED - "Add module ${_NAME} shared" ${_TARGET_SUPPORTS_SHARED_LIBS}) - - # Mark these options as advanced - MARK_AS_ADVANCED(PYTHON3_ENABLE_MODULE_${_NAME} - PYTHON3_MODULE_${_NAME}_BUILD_SHARED) - - IF(PYTHON3_ENABLE_MODULE_${_NAME}) - IF(PYTHON3_MODULE_${_NAME}_BUILD_SHARED) - SET(PY_MODULE_TYPE MODULE) - ELSE(PYTHON3_MODULE_${_NAME}_BUILD_SHARED) - SET(PY_MODULE_TYPE STATIC) - SET_PROPERTY(GLOBAL APPEND PROPERTY PY_STATIC_MODULES_LIST ${_NAME}) - ENDIF(PYTHON3_MODULE_${_NAME}_BUILD_SHARED) - - SET_PROPERTY(GLOBAL APPEND PROPERTY PY_MODULES_LIST ${_NAME}) - ADD_LIBRARY(${_NAME} ${PY_MODULE_TYPE} ${ARGN}) -# TARGET_LINK_LIBRARIES(${_NAME} ${PYTHON_LIBRARIES}) - - ENDIF(PYTHON3_ENABLE_MODULE_${_NAME}) -ENDFUNCTION(PYTHON3_ADD_MODULE) - -FUNCTION(PYTHON3_WRITE_MODULES_HEADER _filename) - - GET_PROPERTY(PY_STATIC_MODULES_LIST GLOBAL PROPERTY PY_STATIC_MODULES_LIST) - - GET_FILENAME_COMPONENT(_name "${_filename}" NAME) - STRING(REPLACE "." "_" _name "${_name}") - STRING(TOUPPER ${_name} _nameUpper) - - SET(_filenameTmp "${_filename}.in") - FILE(WRITE ${_filenameTmp} "/*Created by cmake, do not edit, changes will be lost*/\n") - FILE(APPEND ${_filenameTmp} -"#ifndef ${_nameUpper} -#define ${_nameUpper} - -#include <Python.h> - -#ifdef __cplusplus -extern \"C\" { -#endif /* __cplusplus */ - -") - - FOREACH(_currentModule ${PY_STATIC_MODULES_LIST}) - FILE(APPEND ${_filenameTmp} "extern void init${PYTHON_MODULE_PREFIX}${_currentModule}(void);\n\n") - ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST}) - - FILE(APPEND ${_filenameTmp} -"#ifdef __cplusplus -} -#endif /* __cplusplus */ - -") - - - FOREACH(_currentModule ${PY_STATIC_MODULES_LIST}) - FILE(APPEND ${_filenameTmp} "int ${_name}_${_currentModule}(void) \n{\n static char name[]=\"${PYTHON_MODULE_PREFIX}${_currentModule}\"; return PyImport_AppendInittab(name, init${PYTHON_MODULE_PREFIX}${_currentModule});\n}\n\n") - ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST}) - - FILE(APPEND ${_filenameTmp} "void ${_name}_LoadAllPythonModules(void)\n{\n") - FOREACH(_currentModule ${PY_STATIC_MODULES_LIST}) - FILE(APPEND ${_filenameTmp} " ${_name}_${_currentModule}();\n") - ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST}) - FILE(APPEND ${_filenameTmp} "}\n\n") - FILE(APPEND ${_filenameTmp} "#ifndef EXCLUDE_LOAD_ALL_FUNCTION\nvoid CMakeLoadAllPythonModules(void)\n{\n ${_name}_LoadAllPythonModules();\n}\n#endif\n\n#endif\n") - -# with CONFIGURE_FILE() cmake complains that you may not use a file created using FILE(WRITE) as input file for CONFIGURE_FILE() - EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_filenameTmp}" "${_filename}" OUTPUT_QUIET ERROR_QUIET) - -ENDFUNCTION(PYTHON3_WRITE_MODULES_HEADER) - diff --git a/cmake/Modules/FindPythonInterpWithDebug.cmake b/cmake/Modules/FindPythonInterpWithDebug.cmake index 06572e2..df01366 100644 --- a/cmake/Modules/FindPythonInterpWithDebug.cmake +++ b/cmake/Modules/FindPythonInterpWithDebug.cmake @@ -1,4 +1,4 @@ -find_program(PYTHON_EXECUTABLE NAMES python2.7 python2.6 python2.5) +find_program(PYTHON_EXECUTABLE NAMES python3.6 python3.5 python3.4 python3.3 python3.2 python2.7 python2.6 python2.5) if (NOT PYTHON_EXECUTABLE) find_package(PythonInterp REQUIRED) @@ -28,7 +28,7 @@ endif() execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "if True: from distutils import sysconfig - print bool(sysconfig.get_config_var('Py_DEBUG')) + print(bool(sysconfig.get_config_var('Py_DEBUG'))) " OUTPUT_VARIABLE PYTHON_WITH_DEBUG OUTPUT_STRIP_TRAILING_WHITESPACE) @@ -39,7 +39,7 @@ execute_process( from distutils import sysconfig vr = sys.version_info suffix = '-dbg' if bool(sysconfig.get_config_var('Py_DEBUG')) else '' - print '-python%d.%d%s' % (vr[0], vr[1], suffix) + print('-python%d.%d%s' % (vr[0], vr[1], suffix)) " OUTPUT_VARIABLE PYTHON_SUFFIX OUTPUT_STRIP_TRAILING_WHITESPACE) |