mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
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 <frantisek.hrbata@espressif.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user