Hello,

similar to what I implemented in FindPerlLibs.cmake some years ago, I've added 
PYTHON_SITELIB to FindPythonLibs. With PYTHON_SITELIB you have the location 
where to install the python modules you built with cmake.

Example:

find_package(PythonInterp)
find_package(PythonLibs)

python_add_module(my_py my_py.c)
install(TARGETS my_py DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON_SITELIB})


Please review and push. Thanks.


Cheers,


        -- andreas

-- 
Andreas Schneider                   GPG-ID: CC014E3D
www.cryptomilk.org                [email protected]
>From e414ea43caedeffeb27bb367b5f6c41e6238052a Mon Sep 17 00:00:00 2001
From: Andreas Schneider <[email protected]>
Date: Wed, 16 Dec 2015 10:53:12 +0100
Subject: [PATCH] Modules: Add variable for PYTHON_SITELIB and PYTHON_SITEINC

This allows you to get the path to install python modules.

Signed-off-by: Andreas Schneider <[email protected]>
---
 Modules/FindPythonLibs.cmake | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/Modules/FindPythonLibs.cmake b/Modules/FindPythonLibs.cmake
index 68e1228..83f2b06 100644
--- a/Modules/FindPythonLibs.cmake
+++ b/Modules/FindPythonLibs.cmake
@@ -35,6 +35,14 @@
 # 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.
@@ -66,6 +74,34 @@ if(PYTHON_EXECUTABLE)
     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)
-- 
2.6.4

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to