From: Kefu Chai Date: Tue, 23 Jan 2018 05:01:31 +0000 (+0800) Subject: cmake: add WITH_PYTHON2 option X-Git-Tag: v13.0.2~433^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8b21ba9242eebbfc6f3795af4267bcf52b1a11d2;p=ceph.git cmake: add WITH_PYTHON2 option * 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 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a672add19904..2a337fa74027 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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() diff --git a/src/pybind/CMakeLists.txt b/src/pybind/CMakeLists.txt index 040b8dd4f1c5..9a37726f9962 100644 --- a/src/pybind/CMakeLists.txt +++ b/src/pybind/CMakeLists.txt @@ -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