weechat/cmake/FindPython.cmake

104 lines
3.5 KiB
CMake
Raw Normal View History

2007-05-21 12:30:04 -04:00
#
2018-01-04 18:54:18 -05:00
# Copyright (C) 2003-2018 Sébastien Helleu <flashcode@flashtux.org>
# Copyright (C) 2009 Julien Louis <ptitlouis@sysif.net>
#
# This file is part of WeeChat, the extensible chat client.
#
# WeeChat is free software; you can redistribute it and/or modify
2007-05-21 12:30:04 -04:00
# it under the terms of the GNU General Public License as published by
2007-07-02 08:25:13 -04:00
# the Free Software Foundation; either version 3 of the License, or
2007-05-21 12:30:04 -04:00
# (at your option) any later version.
#
# WeeChat is distributed in the hope that it will be useful,
2007-05-21 12:30:04 -04:00
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with WeeChat. If not, see <https://www.gnu.org/licenses/>.
2007-05-21 12:30:04 -04:00
#
# - Find Python
# 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:
#
# PYTHON_EXECUTABLE = full path to the python binary
# PYTHON_INCLUDE_PATH = path to where python.h can be found
# PYTHON_LIBRARY = path to where libpython.so* can be found
# PYTHON_LFLAGS = python compiler options for linking
if(PYTHON_FOUND)
2007-05-21 12:30:04 -04:00
# Already in cache, be silent
set(PYTHON_FIND_QUIETLY TRUE)
endif()
2007-05-21 12:30:04 -04:00
if(ENABLE_PYTHON3)
find_program(PYTHON_EXECUTABLE
2018-07-12 13:24:56 -04:00
NAMES python3.7 python3.6 python3.5 python3.4 python3.3 python3.2 python3.1 python3.0 python3 python2.7 python2.6 python2.5 python
PATHS /usr/bin /usr/local/bin /usr/pkg/bin
)
else()
find_program(PYTHON_EXECUTABLE
NAMES python2.7 python2.6 python2.5 python
PATHS /usr/bin /usr/local/bin /usr/pkg/bin
)
endif()
2007-05-21 12:30:04 -04:00
if(PYTHON_EXECUTABLE)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import sys; from distutils.sysconfig import *; sys.stdout.write(get_config_var('INCLUDEPY'))"
2007-05-21 12:30:04 -04:00
OUTPUT_VARIABLE PYTHON_INC_DIR
)
2011-10-26 14:37:03 -04:00
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import sys; from distutils.sysconfig import *; sys.stdout.write(get_config_var('LIBPL'))"
2007-05-21 12:30:04 -04:00
OUTPUT_VARIABLE PYTHON_POSSIBLE_LIB_PATH
)
2011-10-26 14:37:03 -04:00
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import sys; from distutils.sysconfig import *; sys.stdout.write(get_config_var('LIBS') + ' ' + get_config_var('LINKFORSHARED'))"
2007-05-21 12:30:04 -04:00
OUTPUT_VARIABLE PYTHON_LFLAGS
)
2011-10-26 14:37:03 -04:00
find_path(PYTHON_INCLUDE_PATH
2007-05-21 12:30:04 -04:00
NAMES Python.h
HINTS ${PYTHON_INC_DIR}
2007-05-21 12:30:04 -04:00
)
if(ENABLE_PYTHON3)
find_library(PYTHON_LIBRARY
2018-07-12 13:24:56 -04:00
NAMES python3.7 python3.6 python3.5 python3.4 python3.3 python3.2 python3.1 python3.0 python3 python2.7 python2.6 python2.5 python
HINTS ${PYTHON_POSSIBLE_LIB_PATH}
)
else()
find_library(PYTHON_LIBRARY
NAMES python2.7 python2.6 python2.5 python
HINTS ${PYTHON_POSSIBLE_LIB_PATH}
)
endif()
2007-05-21 12:30:04 -04:00
if(PYTHON_LIBRARY AND PYTHON_INCLUDE_PATH)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import sys; sys.stdout.write(sys.version[:3])"
OUTPUT_VARIABLE PYTHON_VERSION
)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import sys; sys.stdout.write(str(sys.version_info < (2,5)))"
OUTPUT_VARIABLE PYTHON_OLD_VERSION
)
if(${PYTHON_OLD_VERSION} STREQUAL "True")
message("Python >= 2.5 is needed to build python plugin, version found: ${PYTHON_VERSION}")
else()
set(PYTHON_FOUND TRUE)
endif()
endif()
2011-10-26 14:37:03 -04:00
mark_as_advanced(
2007-05-21 12:30:04 -04:00
PYTHON_EXECUTABLE
PYTHON_INCLUDE_PATH
PYTHON_LIBRARY
PYTHON_LFLAGS
)
2011-10-26 14:37:03 -04:00
endif()