Python interpreter and libraries/headers detection.
- The user can now pass its own interpreter. - Development libraries and headers can be requested. - Travis-CI switched to new container-based workers.
This commit is contained in:
@ -1,9 +0,0 @@
|
||||
#.rst:
|
||||
#
|
||||
# Detects Python interpreter.
|
||||
#
|
||||
# Variables defined::
|
||||
#
|
||||
# PYTHON_EXECUTABLE
|
||||
|
||||
find_package(PythonInterp REQUIRED)
|
36
modules/python_interpreter.cmake
Normal file
36
modules/python_interpreter.cmake
Normal file
@ -0,0 +1,36 @@
|
||||
#.rst:
|
||||
#
|
||||
# Detects Python interpreter.
|
||||
#
|
||||
# Variables used::
|
||||
#
|
||||
# PYTHON_INTERPRETER - User-set path to the Python interpreter
|
||||
#
|
||||
# Variables defined::
|
||||
#
|
||||
# PYTHONINTERP_FOUND - Was the Python executable found
|
||||
# PYTHON_EXECUTABLE - path to the Python interpreter
|
||||
# PYTHON_VERSION_STRING - Python version found e.g. 2.5.2
|
||||
# PYTHON_VERSION_MAJOR - Python major version found e.g. 2
|
||||
# PYTHON_VERSION_MINOR - Python minor version found e.g. 5
|
||||
# PYTHON_VERSION_PATCH - Python patch version found e.g. 2
|
||||
#
|
||||
# autocmake.cfg configuration::
|
||||
#
|
||||
# docopt: --python=<PYTHON_INTERPRETER> The Python interpreter (development version) to use. [default: ''].
|
||||
# define: '-DPYTHON_INTERPRETER="%s"' % arguments['--python']
|
||||
|
||||
if("${PYTHON_INTERPRETER}" STREQUAL "")
|
||||
find_package(PythonInterp REQUIRED)
|
||||
else()
|
||||
if(NOT EXISTS "${PYTHON_INTERPRETER}")
|
||||
find_program(PYTHON_EXECUTABLE NAMES ${PYTHON_INTERPRETER})
|
||||
if (NOT EXISTS "${PYTHON_EXECUTABLE}")
|
||||
set(PYTHONINTERP_FOUND FALSE)
|
||||
endif()
|
||||
else()
|
||||
set(PYTHONINTERP_FOUND TRUE)
|
||||
set(PYTHON_EXECUTABLE "${PYTHON_INTERPRETER}")
|
||||
endif()
|
||||
endif()
|
||||
find_package(PythonInterp REQUIRED)
|
85
modules/python_libs.cmake
Normal file
85
modules/python_libs.cmake
Normal file
@ -0,0 +1,85 @@
|
||||
#.rst:
|
||||
#
|
||||
# Detects Python libraries and headers.
|
||||
# Detection is done basically by hand as the proper CMake package
|
||||
# will not find libraries and headers matching the interpreter version.
|
||||
#
|
||||
# Dependencies::
|
||||
# python_interpreter - Sets the Python interpreter for headers and libraries detection
|
||||
#
|
||||
# Variables used::
|
||||
#
|
||||
# PYTHONINTERP_FOUND - Was the Python executable found
|
||||
#
|
||||
# Variables defined::
|
||||
#
|
||||
# PYTHONLIBS_FOUND - have the Python libs been found
|
||||
# PYTHON_LIBRARIES - path to the python library
|
||||
# PYTHON_INCLUDE_DIRS - path to where Python.h is found
|
||||
# PYTHONLIBS_VERSION_STRING - version of the Python libs found (since CMake 2.8.8)
|
||||
|
||||
if(PYTHONINTERP_FOUND)
|
||||
# Get Python include path from Python interpreter
|
||||
execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
|
||||
"import distutils.sysconfig, sys; sys.stdout.write(distutils.sysconfig.get_python_inc())"
|
||||
OUTPUT_VARIABLE _PYTHON_INCLUDE_PATH
|
||||
RESULT_VARIABLE _PYTHON_INCLUDE_RESULT)
|
||||
# Get Python library path from interpreter
|
||||
execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
|
||||
"from distutils.sysconfig import get_config_var; import sys; sys.stdout.write(get_config_var('LIBDIR'))"
|
||||
OUTPUT_VARIABLE _PYTHON_LIB_PATH
|
||||
RESULT_VARIABLE _PYTHON_LIB_RESULT)
|
||||
|
||||
set(PYTHON_INCLUDE_DIR ${_PYTHON_INCLUDE_PATH} CACHE PATH "Path to a directory")
|
||||
set(_PYTHON_VERSION "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
|
||||
set(_PYTHON_VERSION_NO_DOTS "${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}")
|
||||
|
||||
find_library(PYTHON_LIBRARY
|
||||
NAMES
|
||||
python${_PYTHON_VERSION_NO_DOTS}
|
||||
python${_PYTHON_VERSION}mu
|
||||
python${_PYTHON_VERSION}m
|
||||
python${_PYTHON_VERSION}u
|
||||
python${_PYTHON_VERSION}
|
||||
NO_DEFAULT_PATH
|
||||
HINTS
|
||||
"${_PYTHON_LIB_PATH}"
|
||||
DOC "Path to Python library file."
|
||||
)
|
||||
if (NOT EXISTS "${PYTHON_LIBRARY}")
|
||||
# redo with default paths
|
||||
find_library(PYTHON_LIBRARY
|
||||
NAMES
|
||||
python${_PYTHON_VERSION_NO_DOTS}
|
||||
python${_PYTHON_VERSION}mu
|
||||
python${_PYTHON_VERSION}m
|
||||
python${_PYTHON_VERSION}u
|
||||
python${_PYTHON_VERSION}
|
||||
HINTS
|
||||
"${_PYTHON_LIB_PATH}"
|
||||
DOC "Path to Python library file."
|
||||
)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(CLEAR PYTHON_EXECUTABLE)
|
||||
mark_as_advanced(FORCE PYTHON_LIBRARY)
|
||||
mark_as_advanced(FORCE PYTHON_INCLUDE_DIR)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(PythonLibs
|
||||
REQUIRED_VARS
|
||||
PYTHON_LIBRARY
|
||||
PYTHON_INCLUDE_DIR
|
||||
PYTHON_EXECUTABLE)
|
||||
|
||||
if(NOT PYTHONLIBS_FOUND)
|
||||
message(FATAL_ERROR "Could NOT find PythonLibs")
|
||||
endif()
|
||||
|
||||
# Hook-up script variables to cache variables
|
||||
set(PYTHON_LIBRARIES ${PYTHON_LIBRARY})
|
||||
set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIR})
|
||||
|
||||
include_directories(SYSTEM ${PYTHON_INCLUDE_DIRS})
|
||||
link_directories(${PYTHON_LIBRARIES})
|
Reference in New Issue
Block a user