From 7a2c126054fa6b58b68a89f5aa7a6b0e91be8de4 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 31 Mar 2021 17:35:00 +1100 Subject: [PATCH] cmake: Fix passing PYTHON path via CMake variable if using IDF as library Closes https://github.com/espressif/esp-idf/issues/6285 --- tools/cmake/build.cmake | 6 ++++-- tools/cmake/project.cmake | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 52631a1005..a6202025b0 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -130,9 +130,11 @@ function(__build_init idf_path) # Must be global so as to be accessible from any subdirectory in custom projects. add_library(__idf_build_target STATIC IMPORTED GLOBAL) - set_default(python "python") + # Set the Python path (which may be passed in via -DPYTHON=) and store in a build property + set_default(PYTHON "python") + file(TO_CMAKE_PATH ${PYTHON} PYTHON) + idf_build_set_property(PYTHON ${PYTHON}) - idf_build_set_property(PYTHON ${python}) idf_build_set_property(IDF_PATH ${idf_path}) idf_build_set_property(__PREFIX idf) diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index c9479565e5..fc0c4d87a2 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -6,12 +6,15 @@ cmake_minimum_required(VERSION 3.5) # call. include(${CMAKE_CURRENT_LIST_DIR}/idf.cmake) +# legacy variable for compatibility set(IDFTOOL ${PYTHON} "${IDF_PATH}/tools/idf.py") -# Internally, the Python interpreter is already set to 'python'. Re-set here -# to be absolutely sure. -set_default(PYTHON "python") -file(TO_CMAKE_PATH ${PYTHON} PYTHON) -idf_build_set_property(PYTHON ${PYTHON}) + +# setting PYTHON variable here for compatibility only, new code should use +# idf_build_get_property(variable PYTHON) +idf_build_get_property(PYTHON PYTHON) +if(NOT PYTHON) + message(FATAL_ERROR "Internal error, PYTHON build property not set correctly.") +endif() # On processing, checking Python required modules can be turned off if it was # already checked externally.