From 451bc7609c2d6380599c71e371ccb7b183abef8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= Date: Wed, 15 Aug 2018 03:25:56 +0200 Subject: Bindings: Use python version matching the found clang python module Summary: In case both python 2.7 and 3 are installed, but clang python bindings are only installed for python 3, there will be no error message but the self check will fail. Check for clang bindings for both python2 and python3 (if installed), and use the first one found to generate the sip bindings files. Note, it is possible to e.g. use python2 to generate the sip binding files (requires clang bindings), but generate bindings for python 2, 3, or both (requires matching python-devel and python-sip-devel packages). Test Plan: install python3-clang bindings install python2-clang bindings or one of the above the matching python version is used to run sip_generator.py Reviewers: #frameworks, arojas Reviewed By: arojas Subscribers: kde-frameworks-devel, kde-buildsystem Tags: #frameworks, #build_system Differential Revision: https://phabricator.kde.org/D14914 --- find-modules/FindPythonModuleGeneration.cmake | 37 ++++++++++++++++++--------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'find-modules/FindPythonModuleGeneration.cmake') diff --git a/find-modules/FindPythonModuleGeneration.cmake b/find-modules/FindPythonModuleGeneration.cmake index 2362c454..8688787f 100644 --- a/find-modules/FindPythonModuleGeneration.cmake +++ b/find-modules/FindPythonModuleGeneration.cmake @@ -174,10 +174,6 @@ if (NOT GBP_SIP_COMMAND) _report_NOT_FOUND("The sip executable must be available to use ${CMAKE_FIND_PACKAGE_NAME}.") endif() -if (NOT GPB_PYTHON2_COMMAND) - _report_NOT_FOUND("The python2 executable is required by clang-python for the ${CMAKE_FIND_PACKAGE_NAME} Module.") -endif() - if (NOT libclang_LIBRARY) set(_LIBCLANG_MAX_MAJOR_VERSION 7) set(_LIBCLANG_MIN_MAJOR_VERSION 5) @@ -209,13 +205,30 @@ else() message(STATUS "Found ${libclang_LIBRARY}") endif() -execute_process( - COMMAND ${GPB_PYTHON2_COMMAND} ${CMAKE_CURRENT_LIST_DIR}/sip_generator.py --self-check ${libclang_LIBRARY} - RESULT_VARIABLE selfCheckErrors -) +foreach (pyversion "2" "3") + set(GPB_PYTHON_COMMAND ${GPB_PYTHON${pyversion}_COMMAND}) + if (NOT GPB_PYTHON_COMMAND) + continue() + endif() + message(STATUS "Testing if ${GPB_PYTHON_COMMAND} can be used to run sip_generator") + + execute_process( + COMMAND ${GPB_PYTHON_COMMAND} ${CMAKE_CURRENT_LIST_DIR}/sip_generator.py --self-check ${libclang_LIBRARY} + RESULT_VARIABLE selfCheckErrors + ERROR_QUIET + ) + + if (selfCheckErrors) + message(STATUS "sip_generator self-check for ${GPB_PYTHON_COMMAND} failed") + unset(GPB_PYTHON_COMMAND) + else() + message(STATUS "Self-check passed, Using ${GPB_PYTHON_COMMAND} to generate bindings") + break() + endif() +endforeach() -if (selfCheckErrors) - _report_NOT_FOUND("sip_generator failed a self-check for the ${CMAKE_FIND_PACKAGE_NAME} Module.") +if (NOT GPB_PYTHON_COMMAND) + _report_NOT_FOUND("No usable python version found to run sip_generator for the ${CMAKE_FIND_PACKAGE_NAME} Module.") endif() get_filename_component(libclang_file "${libclang_file}" REALPATH) @@ -351,7 +364,7 @@ function(ecm_generate_python_binding set(comp_flags "$;${stdFlag},;>") add_custom_command(OUTPUT ${sip_file} - COMMAND ${GPB_PYTHON2_COMMAND} ${GPB_MODULE_DIR}/sip_generator.py + COMMAND ${GPB_PYTHON_COMMAND} ${GPB_MODULE_DIR}/sip_generator.py --flags " ${inc_dirs};${sys_inc_dirs};${comp_defs};${comp_flags}" --include_filename "${hdr_filename}" ${libclang_LIBRARY} @@ -399,7 +412,7 @@ headers = sipAPI${modulename_value} add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pybuild/${pythonnamespace_value}/${modulename_value}/unified${modulename_value}.cpp" - COMMAND ${GPB_PYTHON2_COMMAND} "${GPB_MODULE_DIR}/run-sip.py" --sip ${GBP_SIP_COMMAND} + COMMAND ${GPB_PYTHON_COMMAND} "${GPB_MODULE_DIR}/run-sip.py" --sip ${GBP_SIP_COMMAND} --unify "${CMAKE_CURRENT_BINARY_DIR}/pybuild/${pythonnamespace_value}/${modulename_value}/unified${modulename_value}.cpp" --module-name "${modulename_value}" -c "${CMAKE_CURRENT_BINARY_DIR}/pybuild/${pythonnamespace_value}/${modulename_value}" -- cgit v1.2.1