* 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>
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()
# 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)
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