summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2015-12-16 10:53:12 +0100
committerAndreas Schneider <asn@cryptomilk.org>2015-12-16 11:00:51 +0100
commite414ea43caedeffeb27bb367b5f6c41e6238052a (patch)
tree04f932cb6097376100cb72e700327fe68e2ac2c3
parent7e290214659b2b253bd7034a2f56e47d0ff032b5 (diff)
downloadcmake-e414ea43caedeffeb27bb367b5f6c41e6238052a.tar.gz
cmake-e414ea43caedeffeb27bb367b5f6c41e6238052a.tar.xz
cmake-e414ea43caedeffeb27bb367b5f6c41e6238052a.zip
Modules: Add variable for PYTHON_SITELIB and PYTHON_SITEINCasn_pythonlibs
This allows you to get the path to install python modules. Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--Modules/FindPythonLibs.cmake36
1 files changed, 36 insertions, 0 deletions
diff --git a/Modules/FindPythonLibs.cmake b/Modules/FindPythonLibs.cmake
index 68e1228ee..83f2b066a 100644
--- a/Modules/FindPythonLibs.cmake
+++ b/Modules/FindPythonLibs.cmake
@@ -1,108 +1,144 @@
#.rst:
# FindPythonLibs
# --------------
#
# 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:
#
# ::
#
# PYTHONLIBS_FOUND - have the Python libs been found
# PYTHON_LIBRARIES - path to the python library
# PYTHON_INCLUDE_PATH - path to where Python.h is found (deprecated)
# PYTHON_INCLUDE_DIRS - path to where Python.h is found
# PYTHON_DEBUG_LIBRARIES - path to the debug library (deprecated)
# PYTHONLIBS_VERSION_STRING - version of the Python libs found (since CMake 2.8.8)
#
#
#
# The Python_ADDITIONAL_VERSIONS variable can be used to specify a list
# of version numbers that should be taken into account when searching
# for Python. You need to set this variable before calling
# find_package(PythonLibs).
#
# If you'd like to specify the installation of Python to use, you should
# modify the following cache variables:
#
# ::
#
# PYTHON_LIBRARY - path to the python library
# PYTHON_INCLUDE_DIR - path to where Python.h is found
#
# If also calling find_package(PythonInterp), call find_package(PythonInterp)
# first to get the currently active Python version by default with a consistent
# version of PYTHON_LIBRARIES.
+#
+# ::
+#
+# PYTHON_SITELIB = path to the sitelib install directory
+# PYTHON_SITEINC = path to the siteinc install directory
+#
+# Note that these variable do not have a prefix set. So you should for example
+# prepend the CMAKE_INSTALL_PREFIX.
#=============================================================================
# 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 distribute this file outside of CMake, substitute the full
# License text for the above reference.)
# Use the executable's path as a hint
set(_Python_LIBRARY_PATH_HINT)
if(PYTHON_EXECUTABLE)
if(WIN32)
get_filename_component(_Python_PREFIX ${PYTHON_EXECUTABLE} PATH)
if(_Python_PREFIX)
set(_Python_LIBRARY_PATH_HINT ${_Python_PREFIX}/libs)
endif()
unset(_Python_PREFIX)
else()
get_filename_component(_Python_PREFIX ${PYTHON_EXECUTABLE} PATH)
get_filename_component(_Python_PREFIX ${_Python_PREFIX} PATH)
if(_Python_PREFIX)
set(_Python_LIBRARY_PATH_HINT ${_Python_PREFIX}/lib)
endif()
unset(_Python_PREFIX)
endif()
+
+ ### PYTHON_SITELIB
+ execute_process(
+ COMMAND
+ ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(plat_specific=True, prefix=''))"
+ OUTPUT_VARIABLE
+ PYTHON_SITELIB_OUTPUT_VARIABLE
+ RESULT_VARIABLE
+ PYTHON_SITELIB_RESULT_VARIABLE
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if (NOT PYTHON_SITELIB_RESULT_VARIABLE)
+ file(TO_CMAKE_PATH "${PYTHON_SITELIB_OUTPUT_VARIABLE}" PYTHON_SITELIB)
+ endif ()
+
+ ### PYTHON_SITEINC
+ execute_process(
+ COMMAND
+ ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_inc; print(get_python_inc(plat_specific=True, prefix=''))"
+ OUTPUT_VARIABLE
+ PYTHON_SITEINC_OUTPUT_VARIABLE
+ RESULT_VARIABLE
+ PYTHON_SITEINC_RESULT_VARIABLE
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if (NOT PYTHON_SITEINC_RESULT_VARIABLE)
+ file(TO_CMAKE_PATH "${PYTHON_SITEINC_OUTPUT_VARIABLE}" PYTHON_SITEINC)
+ endif ()
endif()
include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindFrameworks.cmake)
# Search for the python framework on Apple.
CMAKE_FIND_FRAMEWORKS(Python)
# Save CMAKE_FIND_FRAMEWORK
if(DEFINED CMAKE_FIND_FRAMEWORK)
set(_PythonLibs_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
else()
unset(_PythonLibs_CMAKE_FIND_FRAMEWORK)
endif()
# To avoid picking up the system Python.h pre-maturely.
set(CMAKE_FIND_FRAMEWORK LAST)
set(_PYTHON1_VERSIONS 1.6 1.5)
set(_PYTHON2_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
set(_PYTHON3_VERSIONS 3.6 3.5 3.4 3.3 3.2 3.1 3.0)
if(PythonLibs_FIND_VERSION)
if(PythonLibs_FIND_VERSION_COUNT GREATER 1)
set(_PYTHON_FIND_MAJ_MIN "${PythonLibs_FIND_VERSION_MAJOR}.${PythonLibs_FIND_VERSION_MINOR}")
unset(_PYTHON_FIND_OTHER_VERSIONS)
if(PythonLibs_FIND_VERSION_EXACT)
if(_PYTHON_FIND_MAJ_MIN STREQUAL PythonLibs_FIND_VERSION)
set(_PYTHON_FIND_OTHER_VERSIONS "${PythonLibs_FIND_VERSION}")
else()
set(_PYTHON_FIND_OTHER_VERSIONS "${PythonLibs_FIND_VERSION}" "${_PYTHON_FIND_MAJ_MIN}")
endif()
else()
foreach(_PYTHON_V ${_PYTHON${PythonLibs_FIND_VERSION_MAJOR}_VERSIONS})
if(NOT _PYTHON_V VERSION_LESS _PYTHON_FIND_MAJ_MIN)
list(APPEND _PYTHON_FIND_OTHER_VERSIONS ${_PYTHON_V})
endif()
endforeach()
endif()
unset(_PYTHON_FIND_MAJ_MIN)
else()
set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON${PythonLibs_FIND_VERSION_MAJOR}_VERSIONS})
endif()