1# the CMake variable PYTHON_INSTALL_DIR has the same value as the Python function catkin.builder.get_python_install_dir()
2
3set(PYTHON_VERSION "$ENV{ROS_PYTHON_VERSION}" CACHE STRING "Specify specific Python version to use ('major.minor' or 'major')")
4find_package(PythonInterp ${PYTHON_VERSION} REQUIRED)
5
6message(STATUS "Using PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE}")
7
8set(_PYTHON_PATH_VERSION_SUFFIX "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
9
10set(enable_setuptools_deb_layout OFF)
11if(EXISTS "/etc/debian_version")
12  set(enable_setuptools_deb_layout ON)
13endif()
14option(SETUPTOOLS_DEB_LAYOUT "Enable debian style python package layout" ${enable_setuptools_deb_layout})
15
16if(SETUPTOOLS_DEB_LAYOUT)
17  message(STATUS "Using Debian Python package layout")
18  set(PYTHON_PACKAGES_DIR dist-packages)
19  set(SETUPTOOLS_ARG_EXTRA "--install-layout=deb")
20  # use major version only when installing 3.x with debian layout
21  if("${PYTHON_VERSION_MAJOR}" STREQUAL "3")
22    set(_PYTHON_PATH_VERSION_SUFFIX "${PYTHON_VERSION_MAJOR}")
23  endif()
24else()
25  message(STATUS "Using default Python package layout")
26  set(PYTHON_PACKAGES_DIR site-packages)
27  # setuptools is fussy about windows paths, make sure the install prefix is in native format
28  file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}" SETUPTOOLS_INSTALL_PREFIX)
29endif()
30
31if(NOT WIN32)
32  set(PYTHON_INSTALL_DIR lib/python${_PYTHON_PATH_VERSION_SUFFIX}/${PYTHON_PACKAGES_DIR}
33    CACHE INTERNAL "This needs to be in PYTHONPATH when 'setup.py install' is called.  And it needs to match.  But setuptools won't tell us where it will install things.")
34else()
35  # Windows setuptools installs to lib/site-packages not lib/python2.7/site-packages
36  set(PYTHON_INSTALL_DIR lib/${PYTHON_PACKAGES_DIR}
37    CACHE INTERNAL "This needs to be in PYTHONPATH when 'setup.py install' is called.  And it needs to match.  But setuptools won't tell us where it will install things.")
38endif()
39