Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 330dd79

Browse files
committed
Added 'QUIET' option to find_arduino_library function allowing safe-failing.
1 parent d581c33 commit 330dd79

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

cmake/Platform/Libraries/LibrariesFinder.cmake

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
macro(_cleanup_find_arduino_library)
2+
3+
unset(library_path CACHE)
4+
5+
endmacro()
6+
17
#=============================================================================#
28
# Finds an Arduino library with the given library name and creates a library target from it
39
# with the given target name.
@@ -8,10 +14,12 @@
814
# _board_id - Board ID associated with the linked Core Lib.
915
# [3RD_PARTY] - Whether library should be treated as a 3rd Party library.
1016
# [HEADER_ONLY] - Whether library should be treated as header-only library.
17+
# [QUIET] - Whether function should "fail" safely without warnings/errors
18+
# in case of an actual error.
1119
#=============================================================================#
1220
function(find_arduino_library _target_name _library_name _board_id)
1321

14-
set(argument_options "3RD_PARTY" "HEADER_ONLY")
22+
set(argument_options "3RD_PARTY" "HEADER_ONLY" "QUIET")
1523
cmake_parse_arguments(parsed_args "${argument_options}" "" "" ${ARGN})
1624

1725
if (NOT parsed_args_3RD_PARTY)
@@ -26,15 +34,21 @@ function(find_arduino_library _target_name _library_name _board_id)
2634
NO_DEFAULT_PATH
2735
NO_CMAKE_FIND_ROOT_PATH)
2836

29-
if ("${library_path}" MATCHES "NOTFOUND")
37+
if ("${library_path}" MATCHES "NOTFOUND" AND NOT parsed_args_QUIET)
3038
message(SEND_ERROR "Couldn't find library named ${_library_name}")
3139

3240
else () # Library is found
3341

3442
find_library_header_files("${library_path}" library_headers)
3543

3644
if (NOT library_headers)
37-
message(SEND_ERROR "Couldn't find any header files for the ${_library_name} library")
45+
if (parsed_args_QUIET)
46+
_cleanup_find_arduino_library()
47+
return()
48+
else ()
49+
message(SEND_ERROR "Couldn't find any header files for the "
50+
"${_library_name} library")
51+
endif ()
3852

3953
else ()
4054

@@ -46,10 +60,15 @@ function(find_arduino_library _target_name _library_name _board_id)
4660
find_library_source_files("${library_path}" library_sources)
4761

4862
if (NOT library_sources)
49-
message(SEND_ERROR "Couldn't find any source files for the "
50-
"${_library_name} library - Is it a header-only library?"
51-
"If so, please pass the HEADER_ONLY option "
52-
"as an argument to the function")
63+
if (parsed_args_QUIET)
64+
_cleanup_find_arduino_library()
65+
return()
66+
else ()
67+
message(SEND_ERROR "Couldn't find any source files for the "
68+
"${_library_name} library - Is it a header-only library?"
69+
"If so, please pass the HEADER_ONLY option "
70+
"as an argument to the function")
71+
endif ()
5372

5473
else ()
5574

@@ -65,6 +84,6 @@ function(find_arduino_library _target_name _library_name _board_id)
6584

6685
endif ()
6786

68-
unset(library_path CACHE)
87+
_cleanup_find_arduino_library()
6988

7089
endfunction()

0 commit comments

Comments
 (0)