From 7c6b995cb4d8bc45b4fc3f63308e2afd4c8dc7c3 Mon Sep 17 00:00:00 2001 From: Peter van der Perk Date: Sat, 21 Aug 2021 17:29:58 +0200 Subject: [PATCH] [Kconfig] Replace find_executable by python module, moved python check before calling kconfig --- CMakeLists.txt | 42 +++++++++++++++++++++--------------------- cmake/kconfig.cmake | 13 +++++++------ 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0e3fcfe69..c8ea0dfa4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,6 +143,27 @@ set(CONFIG "px4_sitl_default" CACHE STRING "desired configuration") include(px4_add_module) set(config_module_list) +# Find Python +# If using catkin, Python 2 is found since it points +# to the Python libs installed with the ROS distro +if (NOT CATKIN_DEVEL_PREFIX) + find_package(PythonInterp 3) + # We have a custom error message to tell users how to install python3. + if (NOT PYTHONINTERP_FOUND) + message(FATAL_ERROR "Python 3 not found. Please install Python 3:\n" + " Ubuntu: sudo apt install python3 python3-dev python3-pip\n" + " macOS: brew install python") + endif() +else() + find_package(PythonInterp REQUIRED) +endif() + +option(PYTHON_COVERAGE "Python code coverage" OFF) +if(PYTHON_COVERAGE) + message(STATUS "python coverage enabled") + set(PYTHON_EXECUTABLE coverage run -p) +endif() + include(px4_config) include(kconfig) message(STATUS "PX4 config: ${PX4_CONFIG}") @@ -283,27 +304,6 @@ if (CATKIN_DEVEL_PREFIX) endif() endif() -# Python -# If using catkin, Python 2 is found since it points -# to the Python libs installed with the ROS distro -if (NOT CATKIN_DEVEL_PREFIX) - find_package(PythonInterp 3) - # We have a custom error message to tell users how to install python3. - if (NOT PYTHONINTERP_FOUND) - message(FATAL_ERROR "Python 3 not found. Please install Python 3:\n" - " Ubuntu: sudo apt install python3 python3-dev python3-pip\n" - " macOS: brew install python") - endif() -else() - find_package(PythonInterp REQUIRED) -endif() - -option(PYTHON_COVERAGE "Python code coverage" OFF) -if(PYTHON_COVERAGE) - message(STATUS "python coverage enabled") - set(PYTHON_EXECUTABLE coverage run -p) -endif() - #============================================================================= # get chip and chip manufacturer # diff --git a/cmake/kconfig.cmake b/cmake/kconfig.cmake index f584921f88..ca09dad150 100644 --- a/cmake/kconfig.cmake +++ b/cmake/kconfig.cmake @@ -1,15 +1,16 @@ set(BOARD_DEFCONFIG ${PX4_CONFIG_FILE} CACHE FILEPATH "path to defconfig" FORCE) set(BOARD_CONFIG ${PX4_BINARY_DIR}/boardconfig CACHE FILEPATH "path to config" FORCE) -find_program(MENUCONFIG_PATH menuconfig) -find_program(GUICONFIG_PATH guiconfig) -find_program(DEFCONFIG_PATH defconfig) -find_program(SAVEDEFCONFIG_PATH savedefconfig) -if(NOT MENUCONFIG_PATH OR NOT GUICONFIG_PATH OR NOT DEFCONFIG_PATH OR NOT SAVEDEFCONFIG_PATH) - message(STATUS "kconfiglib is not installed\n" +execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import menuconfig" RESULT_VARIABLE ret) +if(ret EQUAL "1") + message(FATAL_ERROR "kconfiglib is not installed or not in PATH\n" "please install using \"pip3 install kconfiglib\"\n") endif() +set(MENUCONFIG_PATH ${PYTHON_EXECUTABLE} -m menuconfig CACHE INTERNAL "menuconfig program" FORCE) +set(GUICONFIG_PATH ${PYTHON_EXECUTABLE} -m guiconfig CACHE INTERNAL "guiconfig program" FORCE) +set(DEFCONFIG_PATH ${PYTHON_EXECUTABLE} -m defconfig CACHE INTERNAL "defconfig program" FORCE) +set(SAVEDEFCONFIG_PATH ${PYTHON_EXECUTABLE} -m savedefconfig CACHE INTERNAL "savedefconfig program" FORCE) set(COMMON_KCONFIG_ENV_SETTINGS PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}