]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: pass PYTHON_VERSION explicitly
authorKefu Chai <kchai@redhat.com>
Thu, 18 Jul 2019 01:46:51 +0000 (09:46 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 20 Jul 2019 16:47:39 +0000 (00:47 +0800)
allow `distutils_*()` functions to choose the python according to this
parameter, instead of implicitly using the variable of ${PYTHON_VERSION}
inherited from the caller.

Signed-off-by: Kefu Chai <kchai@redhat.com>
cmake/modules/Distutils.cmake
src/ceph-volume/CMakeLists.txt
src/ceph-volume/plugin/zfs/CMakeLists.txt
src/pybind/cephfs/CMakeLists.txt
src/pybind/rados/CMakeLists.txt
src/pybind/rbd/CMakeLists.txt
src/pybind/rgw/CMakeLists.txt
src/tools/cephfs/CMakeLists.txt

index 404c515c15bbca69286819e4b9329ee5378c77aa..d664fa814bde8aa1a517ef3fb519221a16dd14fe 100644 (file)
@@ -13,7 +13,12 @@ function(distutils_install_module name)
   endforeach()
   add_custom_target(${name}-clone ALL
     DEPENDS ${py_clone})
-  cmake_parse_arguments(DU "" INSTALL_SCRIPT "" ${ARGN})
+  cmake_parse_arguments(DU "" "INSTALL_SCRIPT;PYTHON_VERSION" "" ${ARGN})
+  if(DU_PYTHON_VERSION)
+    set(python_version ${DU_PYTHON_VERSION})
+  else()
+    set(python_version 3)
+  endif()
   install(CODE "
     set(options --prefix=${CMAKE_INSTALL_PREFIX})
     if(DEFINED ENV{DESTDIR})
@@ -28,12 +33,12 @@ function(distutils_install_module name)
       endif()
     endif()
     execute_process(
-    COMMAND ${Python${PYTHON_VERSION}_EXECUTABLE}
+    COMMAND ${Python${python_version}_EXECUTABLE}
         setup.py install \${options}
     WORKING_DIRECTORY \"${CMAKE_CURRENT_BINARY_DIR}\")")
 endfunction(distutils_install_module)
 
-function(distutils_add_cython_module target name src)
+function(distutils_add_cython_module target name src python_version)
   get_property(compiler_launcher GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
   get_property(link_launcher GLOBAL PROPERTY RULE_LAUNCH_LINK)
   # When using ccache, CMAKE_C_COMPILER is ccache executable absolute path
@@ -57,12 +62,12 @@ function(distutils_add_cython_module target name src)
   set(PY_CXX ${compiler_launcher} ${CMAKE_CXX_COMPILER} ${cxx_compiler_arg1})
   set(PY_LDSHARED ${link_launcher} ${CMAKE_C_COMPILER} ${c_compiler_arg1} "-shared")
 
-  if(${Python${PYTHON_VERSION}_VERSION_MAJOR} STREQUAL "2")
+  if(${Python${python_version}_VERSION_MAJOR} STREQUAL "2")
     set(suffix_var "SO")
   else()
     set(suffix_var "EXT_SUFFIX")
   endif()
-  execute_process(COMMAND "${Python${PYTHON_VERSION}_EXECUTABLE}" -c
+  execute_process(COMMAND "${Python${python_version}_EXECUTABLE}" -c
     "from distutils import sysconfig; print(sysconfig.get_config_var('${suffix_var}'))"
     RESULT_VARIABLE result
     OUTPUT_VARIABLE ext_suffix
@@ -71,7 +76,7 @@ function(distutils_add_cython_module target name src)
   if(NOT result EQUAL 0)
     message(FATAL_ERROR "Unable to tell python extension's suffix: ${error}")
   endif()
-  set(output_dir "${CYTHON_MODULE_DIR}/lib.${Python${PYTHON_VERSION}_VERSION_MAJOR}")
+  set(output_dir "${CYTHON_MODULE_DIR}/lib.${Python${python_version}_VERSION_MAJOR}")
   set(setup_py ${CMAKE_CURRENT_SOURCE_DIR}/setup.py)
   add_custom_command(
     OUTPUT ${output_dir}/${name}${ext_suffix}
@@ -84,7 +89,7 @@ function(distutils_add_cython_module target name src)
     LDFLAGS=-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
     CYTHON_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}
     CEPH_LIBDIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
-    ${Python${PYTHON_VERSION}_EXECUTABLE} ${setup_py}
+    ${Python${python_version}_EXECUTABLE} ${setup_py}
     build --verbose --build-base ${CYTHON_MODULE_DIR}
     --build-platlib ${output_dir}
     MAIN_DEPENDENCY ${src}
@@ -94,7 +99,7 @@ function(distutils_add_cython_module target name src)
     DEPENDS ${output_dir}/${name}${ext_suffix})
 endfunction(distutils_add_cython_module)
 
-function(distutils_install_cython_module name)
+function(distutils_install_cython_module name python_version)
   get_property(compiler_launcher GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
   get_property(link_launcher GLOBAL PROPERTY RULE_LAUNCH_LINK)
   set(PY_CC "${compiler_launcher} ${CMAKE_C_COMPILER}")
@@ -120,9 +125,9 @@ function(distutils_install_cython_module name)
     endif()
     execute_process(
        COMMAND
-           ${Python${PYTHON_VERSION}_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py
+           ${Python${python_version}_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py
            build --verbose --build-base ${CYTHON_MODULE_DIR}
-           --build-platlib ${CYTHON_MODULE_DIR}/lib.${Python${PYTHON_VERSION}_VERSION_MAJOR}
+           --build-platlib ${CYTHON_MODULE_DIR}/lib.${Python${python_version}_VERSION_MAJOR}
            build_ext --cython-c-in-temp --build-temp ${CMAKE_CURRENT_BINARY_DIR} --cython-include-dirs ${PROJECT_SOURCE_DIR}/src/pybind/rados
            install \${options} --single-version-externally-managed --record /dev/null
            egg_info --egg-base ${CMAKE_CURRENT_BINARY_DIR}
index 5a9eb2ed064e5f463605e6aa1951066253dfdd6d..d1217a915c85f2f1547bf3b178e4ee4db131f50b 100644 (file)
@@ -1,7 +1,15 @@
 
 include(Distutils)
+
+if(WITH_PYTHON2)
+  set(python_version_major 2)
+else()
+  set(python_version_major 3)
+endif()
+
 distutils_install_module(ceph_volume
-  INSTALL_SCRIPT ${CMAKE_INSTALL_FULL_SBINDIR})
+  INSTALL_SCRIPT ${CMAKE_INSTALL_FULL_SBINDIR}
+  PYTHON_VERSION ${python_version_major})
 
 if(FREEBSD)
   add_subdirectory(plugin/zfs)
index da10f46fd09adc0f942c911aa048ab84c8fc511f..cafb7382e77ae62bd0f7372093225ed794bf1ed8 100644 (file)
@@ -1,3 +1,4 @@
 
 distutils_install_module(ceph_volume_zfs
-  INSTALL_SCRIPT ${CMAKE_INSTALL_FULL_SBINDIR})
+  INSTALL_SCRIPT ${CMAKE_INSTALL_FULL_SBINDIR}
+  PYTHON_VERSION ${python_version})
index 380ec21fc070ff3e4f706f28554b5e43fb516523..61cf8b4a9ff3cecde712a070aa6a8cde13b8c106 100644 (file)
@@ -1,5 +1,7 @@
 distutils_add_cython_module(cython${PYTHON_VERSION}_cephfs
   cephfs
-  ${CMAKE_CURRENT_SOURCE_DIR}/cephfs.pyx)
+  ${CMAKE_CURRENT_SOURCE_DIR}/cephfs.pyx
+  ${PYTHON_VERSION})
 add_dependencies(cython${PYTHON_VERSION}_cephfs cephfs)
-distutils_install_cython_module(cython${PYTHON_VERSION}_cephfs)
+distutils_install_cython_module(cython${PYTHON_VERSION}_cephfs
+  ${PYTHON_VERSION})
index a8ed22550f964b8a91dbc5a9fe936003b8a1df45..b16d3513b55b0fdf637632d4dc8db915fa913a29 100644 (file)
@@ -1,5 +1,7 @@
 distutils_add_cython_module(cython${PYTHON_VERSION}_rados
   rados
-  ${CMAKE_CURRENT_SOURCE_DIR}/rados.pyx)
+  ${CMAKE_CURRENT_SOURCE_DIR}/rados.pyx
+  ${PYTHON_VERSION})
 add_dependencies(cython${PYTHON_VERSION}_rados rados)
-distutils_install_cython_module(cython${PYTHON_VERSION}_rados)
+distutils_install_cython_module(cython${PYTHON_VERSION}_rados
+  ${PYTHON_VERSION})
index 4920e0ff1eeed8a7f0cea02d770fca96a3d4586e..f7d3bb4deb96e3ea52880ca97d503fc6945b0a2d 100644 (file)
@@ -1,5 +1,7 @@
 distutils_add_cython_module(cython${PYTHON_VERSION}_rbd
   rbd
-  ${CMAKE_CURRENT_SOURCE_DIR}/rbd.pyx)
+  ${CMAKE_CURRENT_SOURCE_DIR}/rbd.pyx
+  ${PYTHON_VERSION})
 add_dependencies(cython${PYTHON_VERSION}_rbd librbd)
-distutils_install_cython_module(cython${PYTHON_VERSION}_rbd)
+distutils_install_cython_module(cython${PYTHON_VERSION}_rbd
+  ${PYTHON_VERSION})
index 811af61288dd382c2aa770880969768bb2e6d6c0..2c8309cdd351ef854780588575bbda72cb2a328c 100644 (file)
@@ -1,5 +1,7 @@
 distutils_add_cython_module(cython${PYTHON_VERSION}_rgw
   rgw
-  ${CMAKE_CURRENT_SOURCE_DIR}/rgw.pyx)
+  ${CMAKE_CURRENT_SOURCE_DIR}/rgw.pyx
+  ${PYTHON_VERSION})
 add_dependencies(cython${PYTHON_VERSION}_rgw rgw)
-distutils_install_cython_module(cython${PYTHON_VERSION}_rgw)
+distutils_install_cython_module(cython${PYTHON_VERSION}_rgw
+  ${PYTHON_VERSION})
index 2cca8dc034c854def7ddbd1742b481cdad8646a2..6ffa26628f1a48ed80e107d2a76cd36eab9a2041 100644 (file)
@@ -43,7 +43,7 @@ if(WITH_CEPHFS_SHELL)
   if(NOT WITH_PYTHON3)
     message(SEND_ERROR "Please enable WITH_PYTHON3 for cephfs-shell")
   endif()
-  set(PYTHON_VERSION 3)
   include(Distutils)
-  distutils_install_module(cephfs-shell)
+  distutils_install_module(cephfs-shell
+    PYTHON_VERSION 3)
 endif()