]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: add WITH_PYTHON2 option
authorKefu Chai <kchai@redhat.com>
Tue, 23 Jan 2018 05:01:31 +0000 (13:01 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 26 Jan 2018 12:06:21 +0000 (20:06 +0800)
* add WITH_PYTHON2 option, so we can build python3 bindings only.
* change the default value of WITH_PYTHON3 option to "OFF", as the
option() command in cmake only allow the initial value to be "ON" or
"OFF". we could use a cached string for this option, but i think it
would be more explicit to continue using the option() command.
* fix the installation dir of "ceph_rest_api.py". please note, we still
have a *default* python version, which is specified by the last element
of ${py_vers}. for instance, ${PYTHON_VERSION} will be 3 if ${py_vers}
is 2;3. in this change, 2 is still the default python version, if both
WITH_PYTHON2 and WITH_PYTHON3 are enabled.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/CMakeLists.txt
src/pybind/CMakeLists.txt

index a672add19904b3d9cf3818af5d99eec4e380d7f3..2a337fa740270a25d14f1bd381c34abcb8d6fe96 100644 (file)
@@ -262,19 +262,14 @@ if(WITH_CEPHFS_JAVA)
 endif()
 
 # Python stuff
-find_package(PythonInterp 2 REQUIRED)
-find_package(PythonLibs 2 REQUIRED)
-
-option(WITH_PYTHON3 "build python3 bindings" "CHECK")
-if(WITH_PYTHON3 MATCHES "check|CHECK")
-  find_package(Python3Interp 3 QUIET)
-  find_package(Python3Libs 3 QUIET)
-  if(PYTHON3INTERP_FOUND AND PYTHON3LIBS_FOUND)
-    set(WITH_PYTHON3 ON)
-  else()
-    set(WITH_PYTHON3 OFF)
-  endif()
-elseif(WITH_PYTHON3)
+option(WITH_PYTHON2 "build python2 bindings" ON)
+if(WITH_PYTHON2)
+  find_package(PythonInterp 2 REQUIRED)
+  find_package(PythonLibs 2 REQUIRED)
+endif()
+
+option(WITH_PYTHON3 "build python3 bindings" OFF)
+if(WITH_PYTHON3)
   find_package(Python3Interp 3 REQUIRED)
   find_package(Python3Libs 3 REQUIRED)
 endif()
index 040b8dd4f1c5a0820663dce8486e0a0e229742eb..9a37726f9962a6f6f9310fb0148b21436629d766 100644 (file)
@@ -4,9 +4,14 @@ set(CYTHON_MODULE_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cython_modules)
 
 # Keep the default version last
 if(WITH_PYTHON3)
-  set(py_vers 3)
+  list(APPEND py_vers 3)
+endif()
+if(WITH_PYTHON2)
+  list(APPEND py_vers 2)
+endif()
+if(NOT py_vers)
+  message(FATAL_ERROR "No Python binding enabled. Please enable WITH_PYTHON2 and/or WITH_PYTHON3.")
 endif()
-list(APPEND py_vers 2)
 
 foreach(python_version ${py_vers})
   if(${python_version} EQUAL 2)
@@ -58,9 +63,14 @@ endforeach()
 
 install(FILES
   ${CMAKE_CURRENT_SOURCE_DIR}/ceph_rest_api.py
-  DESTINATION ${PYTHON_INSTDIR})
+  DESTINATION ${PYTHON${PYTHON_VERSION}_INSTDIR})
 
 if(WITH_MGR)
+  if(NOT WITH_PYTHON2 AND MGR_PYTHON_VERSION_MAJOR EQUAL 2)
+    message(FATAL_ERROR "mgr plugins require python2 binding")
+  elseif(NOT WITH_PYTHON3 AND MGR_PYTHON_VERSION_MAJOR EQUAL 3)
+    message(FATAL_ERROR "mgr plugins require python3 binding")
+  endif()
   # Location needs to match default setting for mgr_module_path, currently:
   # OPTION(mgr_module_path, OPT_STR, CEPH_PKGLIBDIR "/mgr")
   install(DIRECTORY