Skip to content

Commit 60dafe5

Browse files
pillo79facchinm
authored andcommitted
cmake: package_helper: add -R option to run additional commands
The 'package_helper.cmake' script is used to load a certain subset of Zephyr modules, as required by the caller. Some use cases may require additional commands to be executed in the same context after the modules have been loaded, because not enough information is reported or saved in the build directory by default. This patch adds a new '-R' option to 'package_helper.cmake', which allows the caller to specify a script to be executed in the current context after the modules have been loaded. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
1 parent 08497a2 commit 60dafe5

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

cmake/package_helper.cmake

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
# The build directory will default to current working directory but can be
2020
# controlled with: '-B <path-to-build>'
2121
#
22+
# After the modules have been loaded, additional commands can be optionally
23+
# executed in the current context by providing the '-R <path-to-script>' option.
24+
#
2225
# For example, if you were invoking CMake for 'hello_world' sample as:
2326
# $ cmake -DBOARD=<board> -B build -S samples/hello_world
2427
#
@@ -49,10 +52,12 @@ foreach(i RANGE ${CMAKE_ARGC})
4952
if(CMAKE_ARGV${i} MATCHES "^-B(.*)")
5053
set(argB ${CMAKE_MATCH_1})
5154
set(argB_index ${i})
52-
elseif()
5355
elseif(CMAKE_ARGV${i} MATCHES "^-S(.*)")
5456
set(argS_index ${i})
5557
set(argS ${CMAKE_MATCH_1})
58+
elseif(CMAKE_ARGV${i} MATCHES "^-R(.*)")
59+
set(argR_index ${i})
60+
set(argR ${CMAKE_MATCH_1})
5661
endif()
5762
endforeach()
5863

@@ -76,6 +81,16 @@ if(DEFINED argS_index)
7681
endif()
7782
endif()
7883

84+
if(DEFINED argR_index)
85+
if(DEFINED argR)
86+
set(RUN_SCRIPT ${argR})
87+
else()
88+
# value of -R follows in next index
89+
math(EXPR argR_value_index "${argR_index} + 1")
90+
set(RUN_SCRIPT ${CMAKE_ARGV${argR_value_index}})
91+
endif()
92+
endif()
93+
7994
if(NOT DEFINED APPLICATION_SOURCE_DIR)
8095
message(FATAL_ERROR
8196
"Source directory not defined, please use '-S <path-to-source>' to the "
@@ -99,3 +114,7 @@ endif()
99114

100115
string(REPLACE ";" "," MODULES "${MODULES}")
101116
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} COMPONENTS zephyr_default:${MODULES})
117+
118+
if (DEFINED RUN_SCRIPT)
119+
include(${RUN_SCRIPT})
120+
endif()

0 commit comments

Comments
 (0)