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

Commit 641cc97

Browse files
committed
Added-back header-only related code to find_library API.
Also modified `add_arduino_header_only_library` API to accept unlimited source files (headers) as unparsed arguments, as is done with the 'Executable' API.
1 parent 2e66839 commit 641cc97

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

cmake/Platform/Libraries/LibrariesFinder.cmake

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#=============================================================================#
1111
function(find_arduino_library _target_name _library_name _board_id)
1212

13-
set(argument_options "3RD_PARTY")
13+
set(argument_options "3RD_PARTY" "HEADER_ONLY")
1414
cmake_parse_arguments(parsed_args "${argument_options}" "" "" ${ARGN})
1515

1616
if (NOT parsed_args_3RD_PARTY)
@@ -26,24 +26,32 @@ function(find_arduino_library _target_name _library_name _board_id)
2626
if (${library_properties_file} MATCHES "NOTFOUND")
2727
message(SEND_ERROR "Couldn't find library named ${_library_name}")
2828
else () # Library is found
29+
2930
get_filename_component(library_path ${library_properties_file} DIRECTORY)
3031

3132
find_library_header_files("${library_path}" library_headers)
33+
3234
if (NOT library_headers)
33-
set(error_message "Couldn't find any header files for the ${_library_name} library")
34-
message(SEND_ERROR "${error_message}")
35+
message(SEND_ERROR "Couldn't find any header files for the ${_library_name} library")
3536
else ()
36-
find_library_source_files("${library_path}" library_sources)
37-
if (NOT library_sources)
38-
string(CONCAT error_message
39-
"Couldn't find any source files for the ${_library_name} library - "
40-
"Is it a header-only library?\n"
41-
"If so, please pass the HEADER_ONLY option as an argument to the function")
42-
message(SEND_ERROR "${error_message}")
37+
38+
if (parsed_args_HEADER_ONLY)
39+
add_arduino_header_only_library(${_target_name} ${_board_id} ${library_headers})
4340
else ()
44-
set(sources ${library_headers} ${library_sources})
45-
add_arduino_library(${_target_name} ${_board_id} ${library_path} "${sources}"
46-
LIB_PROPS_FILE ${library_properties_file})
41+
find_library_source_files("${library_path}" library_sources)
42+
43+
if (NOT library_sources)
44+
message(SEND_ERROR "Couldn't find any source files for the "
45+
"${_library_name} library - Is it a header-only library?"
46+
"If so, please pass the HEADER_ONLY option "
47+
"as an argument to the function")
48+
else ()
49+
set(sources ${library_headers} ${library_sources})
50+
51+
add_arduino_library(${_target_name} ${_board_id} ${library_path} "${sources}"
52+
LIB_PROPS_FILE ${library_properties_file})
53+
endif ()
54+
4755
endif ()
4856
endif ()
4957
endif ()

cmake/Platform/Targets/ArduinoLibraryTarget.cmake

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ function(add_arduino_library _target_name _board_id _library_root_dir _sources)
2020

2121
endfunction()
2222

23+
#=============================================================================#
24+
# Creates a header-only library target for the given name and sources.
25+
# _target_name - Name of the "executable" target.
26+
# _board_id - Board ID associated with the linked Core Lib.
27+
#=============================================================================#
2328
function(add_arduino_header_only_library _target_name _board_id)
2429

25-
cmake_parse_arguments(parsed_args "ARCH" "" "HEADERS" ${ARGN})
30+
set(headers ${ARGN})
2631

27-
_add_arduino_cmake_library(${_target_name} ${_board_id} "${parsed_args_HEADERS}"
28-
INTERFACE ${parsed_args_ARCH})
32+
_add_arduino_cmake_library(${_target_name} ${_board_id} "${headers}" INTERFACE)
2933

3034
endfunction()
3135

0 commit comments

Comments
 (0)