From 0ffb07df1e45118e90a3cd4973033361c476130c Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Fri, 11 Jul 2025 12:27:46 +0200 Subject: [PATCH] fix(cmakev2/utilities): make the PATHS option optional in __get_absolute_paths With the default signature of `cmake_parse_arguments`, without using `PARSE_ARGV`, it's not possible to determine if options were not specified or set as an empty string (or empty list)[1]. If an empty string is passed to the `PATHS` option, the variable parsed by `cmake_parse_arguments` is not defined. This issue can be addressed by using `PARSE_ARGV`, but this approach only works for functions and requires CMake version 3.31 or newer. Additionally, when `PARSE_ARGV` is used for multiple value option, the values are not concatenated into a single list, which is inconvenient, as the lists are instead escaped. If the `PATHS` option is not defined, set it to an empty string. This allows passing an empty string, as well as a mix of lists and individual strings, through PATHS. The behaviour can be seen with a simple example: $ cmake -P test.cmake ```test.cmake cmake_minimum_required(VERSION 3.22) function(test) set(options) set(one_value) set(multi_value PATHS) cmake_parse_arguments(ARG "${options}" "${one_value}" "${multi_value}" ${ARGN}) #cmake_parse_arguments(PARSE_ARGV 0 ARG "${options}" "${one_value}" "${multi_value}") message("PATHS: ${ARG_PATHS}") endfunction() test(PATHS "one;two;three" "four" "five;six" "seven") ``` ``` PATHS: one;two;three;four;five;six;seven vs PATHS: one\;two\;three;four;five\;six;seven ``` Also update the current usage of __get_absolute_paths, as the check for empty PATHS is no longer necessary. [1] https://cmake.org/cmake/help/latest/policy/CMP0174.html#policy:CMP0174 Signed-off-by: Frantisek Hrbata --- tools/cmakev2/component.cmake | 6 +----- tools/cmakev2/utilities.cmake | 8 ++++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/tools/cmakev2/component.cmake b/tools/cmakev2/component.cmake index 3136ef2d394..746d6d9c982 100644 --- a/tools/cmakev2/component.cmake +++ b/tools/cmakev2/component.cmake @@ -106,12 +106,8 @@ function(__get_component_paths) idf_die("OUTPUT option is required") endif() - set(include_paths "") - set(exclude_paths "") __get_absolute_paths(PATHS "${ARG_PATHS}" OUTPUT include_paths) - if(DEFINED ARG_EXCLUDE_PATHS) - __get_absolute_paths(PATHS "${ARG_EXCLUDE_PATHS}" OUTPUT exclude_paths) - endif() + __get_absolute_paths(PATHS "${ARG_EXCLUDE_PATHS}" OUTPUT exclude_paths) if(ARG_CHECK) foreach(path IN LISTS include_paths) diff --git a/tools/cmakev2/utilities.cmake b/tools/cmakev2/utilities.cmake index dd678924844..34ef335de6e 100644 --- a/tools/cmakev2/utilities.cmake +++ b/tools/cmakev2/utilities.cmake @@ -147,14 +147,14 @@ function(__get_absolute_paths) set(multi_value PATHS) cmake_parse_arguments(ARG "${options}" "${one_value}" "${multi_value}" ${ARGN}) - if(NOT DEFINED ARG_PATHS) - idf_die("PATHS option is required") - endif() - if(NOT DEFINED ARG_OUTPUT) idf_die("OUTPUT option is required") endif() + if(NOT DEFINED ARG_PATHS) + set(ARG_PATHS "") + endif() + set(absolute_paths "") foreach(path IN LISTS ARG_PATHS) get_filename_component(path_abs ${path} ABSOLUTE)