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

Commit 7d7427b

Browse files
authored
Merge pull request #18 from arduino-cmake/feature/3rd-party-arduino-libs
Fixed support for 3rd Party Arduino libraries
2 parents 676f245 + f0eeab9 commit 7d7427b

25 files changed

+3919
-8
lines changed

cmake/Platform/Sources/SourcesManager.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ function(get_headers_parent_directories _sources _return_var)
6464
get_filename_component(header_parent_dir ${header_source} DIRECTORY)
6565
list(APPEND parent_dirs ${header_parent_dir})
6666
endforeach ()
67-
list(REMOVE_DUPLICATES parent_dirs)
67+
if (parent_dirs) # Check parent dirs, could be none if there aren't any headers amongst sources
68+
list(REMOVE_DUPLICATES parent_dirs)
69+
endif ()
6870

6971
set(${_return_var} ${parent_dirs} PARENT_SCOPE)
7072

cmake/Platform/Targets/ArduinoLibraryTarget.cmake

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ endfunction()
7676
# _board_id - Board ID associated with the linked Core Lib.
7777
# _sources - Source and header files to create target from.
7878
#=============================================================================#
79-
function(_add_arduino_library _target_name _board_id _sources)
79+
function(add_arduino_library _target_name _board_id _sources)
8080

8181
_add_arduino_cmake_library(${_target_name} ${_board_id} "${_sources}" "${ARGN}")
8282
find_dependent_platform_libraries("${_sources}" lib_platform_libs)
@@ -94,21 +94,26 @@ endfunction()
9494
# _target_name - Name of the library target to be created. Usually library's real name.
9595
# _library_name - Name of the Arduino library to find.
9696
# _board_id - Board ID associated with the linked Core Lib.
97+
# [3RD_PARTY] - Whether library should be treated as a 3rd Party library.
9798
#=============================================================================#
9899
function(find_arduino_library _target_name _library_name _board_id)
99100

100-
convert_string_to_pascal_case(${_library_name} arduino_compliant_library_name)
101-
set(library_path "${ARDUINO_SDK_LIBRARIES_PATH}/${arduino_compliant_library_name}")
101+
cmake_parse_arguments(find_lib "3RD_PARTY" "" "" ${ARGN})
102+
103+
if (NOT find_lib_3RD_PARTY)
104+
convert_string_to_pascal_case(${_library_name} _library_name)
105+
endif ()
106+
set(library_path "${ARDUINO_SDK_LIBRARIES_PATH}/${_library_name}")
102107
set(library_properties_path "${library_path}/library.properties")
103108

104109
if (NOT EXISTS "${library_properties_path}")
105-
message(SEND_ERROR "Couldn't find library named ${arduino_compliant_library_name}")
110+
message(SEND_ERROR "Couldn't find library named ${_library_name}")
106111
else () # Library is found
107112
_get_library_architecture("${library_properties_path}" lib_arch)
108113
if (lib_arch)
109114
if ("${lib_arch}" MATCHES "UNSUPPORTED")
110115
string(CONCAT error_message
111-
"${arduino_compliant_library_name} "
116+
"${_library_name} "
112117
"library isn't supported on the platform's architecture "
113118
"${ARDUINO_CMAKE_PLATFORM_ARCHITECTURE}")
114119
message(SEND_ERROR ${error_message})
@@ -126,12 +131,12 @@ function(find_arduino_library _target_name _library_name _board_id)
126131

127132
if (NOT library_sources)
128133
set(error_message
129-
"${arduino_compliant_library_name} doesn't have any source files \
134+
"${_library_name} doesn't have any source files \
130135
under the 'src' directory")
131136
message(SEND_ERROR "${error_message}")
132137
else ()
133138
set(sources ${library_headers} ${library_sources})
134-
_add_arduino_library(${_target_name} ${_board_id} "${sources}" ARCH ${lib_arch})
139+
add_arduino_library(${_target_name} ${_board_id} "${sources}" ARCH ${lib_arch})
135140
endif ()
136141
endif ()
137142
endif ()

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ project(Examples LANGUAGES C CXX ASM)
44

55
add_subdirectory(hello-world)
66
add_subdirectory(arduino-library)
7+
add_subdirectory(custom-library)
78
add_subdirectory(blink-example)
89
add_subdirectory(servo-knob-example)
910
add_subdirectory(sketch)

0 commit comments

Comments
 (0)