From 13b56cec79625ad38f71afe14819786ad803aadd Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Thu, 16 Apr 2026 11:08:37 +0200 Subject: [PATCH] fix(cmake): quote variable references in conditional expressions Closes https://github.com/espressif/esp-idf/issues/18445 --- tools/cmake/project.cmake | 14 +++++++------- tools/cmake/targets.cmake | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 45aec534f0..8899f78dcd 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -77,22 +77,22 @@ function(__parse_and_store_version_arg) cmake_parse_arguments(PROJECT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) # If the VERSION keyword exists but no version string is provided then raise a warning - if((NOT PROJECT_VERSION - OR PROJECT_VERSION STREQUAL "NOTFOUND") - AND NOT PROJECT_VERSION STREQUAL "0") + if(("${PROJECT_VERSION}" STREQUAL "" + OR "${PROJECT_VERSION}" STREQUAL "NOTFOUND") + AND NOT "${PROJECT_VERSION}" STREQUAL "0") message(STATUS "VERSION keyword not followed by a value or was followed by a value that expanded to nothing.") # Default the version to 1 in this case set(project_ver 1) else() # Check if version is valid. cmake allows the version to be in the format [.[.[.]]]] - string(REGEX MATCH "^([0-9]+(\\.[0-9]+(\\.[0-9]+(\\.[0-9]+)?)?)?)?$" version_valid ${PROJECT_VERSION}) - if(NOT version_valid AND NOT PROJECT_VERSION STREQUAL "0") + string(REGEX MATCH "^([0-9]+(\\.[0-9]+(\\.[0-9]+(\\.[0-9]+)?)?)?)?$" version_valid "${PROJECT_VERSION}") + if(NOT version_valid AND NOT "${PROJECT_VERSION}" STREQUAL "0") message(SEND_ERROR "Version \"${PROJECT_VERSION}\" format invalid.") return() endif() # Split the version string into major, minor, patch, and tweak components - string(REPLACE "." ";" version_components ${PROJECT_VERSION}) + string(REPLACE "." ";" version_components "${PROJECT_VERSION}") list(GET version_components 0 PROJECT_VERSION_MAJOR) list(LENGTH version_components version_length) if(version_length GREATER 1) @@ -733,7 +733,7 @@ macro(project project_name) # Check if version information was passed to project() via the VERSION argument set(version_keyword_present FALSE) foreach(arg ${ARGN}) - if(${arg} STREQUAL "VERSION") + if("${arg}" STREQUAL "VERSION") set(version_keyword_present TRUE) endif() endforeach() diff --git a/tools/cmake/targets.cmake b/tools/cmake/targets.cmake index aa4c85c0e2..46261c2e20 100644 --- a/tools/cmake/targets.cmake +++ b/tools/cmake/targets.cmake @@ -94,7 +94,7 @@ macro(__target_init config_file) # Check if selected target is consistent with CMake cache if(DEFINED CACHE{IDF_TARGET}) - if(NOT $CACHE{IDF_TARGET} STREQUAL ${env_idf_target}) + if(NOT $CACHE{IDF_TARGET} STREQUAL "${env_idf_target}") message(FATAL_ERROR " IDF_TARGET '$CACHE{IDF_TARGET}' in CMake" " cache does not match currently selected IDF_TARGET '${env_idf_target}'." " To change the target, clear the build directory and sdkconfig file," @@ -105,7 +105,7 @@ macro(__target_init config_file) # Check if selected target is consistent with sdkconfig __target_from_config("${config_file}" sdkconfig_target where) if(sdkconfig_target) - if(NOT ${sdkconfig_target} STREQUAL ${env_idf_target}) + if(NOT "${sdkconfig_target}" STREQUAL "${env_idf_target}") message(FATAL_ERROR " Target '${sdkconfig_target}' in sdkconfig '${where}'" " does not match currently selected IDF_TARGET '${IDF_TARGET}'." " To change the target, clear the build directory and sdkconfig file," @@ -143,7 +143,7 @@ macro(__target_set_toolchain) " the build directory and sdkconfig file, and build the project again.") endif() - if(${env_idf_toolchain} STREQUAL "clang") + if("${env_idf_toolchain}" STREQUAL "clang") # TODO IDF-14338: remove the line below since it will be set in toolchain.cmake set(IDF_TOOLCHAIN ${env_idf_toolchain} CACHE STRING "IDF Build Toolchain Type") set(toolchain_filename "toolchain-clang-${IDF_TARGET}.cmake")