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

Commit 644b2f1

Browse files
committed
Modified library source-finding algorithm to match Arduino Specifications.
All sources under the 'src' sub-dir are recursively included, while all sources under library's root dir are included if 'src' sub-dir doesn't exist. Added an example to leverage new algorithm as well as the use of Sketchbook path. This led to some strange issues regarding linking the CoreLib to platform libraries - Still not sure what caused it and what exactly fixed it.
1 parent 6a097e3 commit 644b2f1

File tree

93 files changed

+25027
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+25027
-25
lines changed

cmake/Platform/Sources/SourceSeeker.cmake

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ endfunction()
6464
#=============================================================================#
6565
function(find_library_header_files _base_path _return_var)
6666

67-
find_header_files(${_base_path} headers RECURSE) # Library headers are always searched recursively
68-
list(FILTER headers EXCLUDE REGEX "${ARDUINO_CMAKE_EXCLUDED_LIBRARY_SOURCES_PATTERN}")
67+
if (EXISTS ${_base_path}/src) # 'src' sub-dir exists and should contain sources
68+
# Headers are always searched recursively under the 'src' sub-dir
69+
find_header_files(${_base_path}/src headers RECURSE)
70+
else ()
71+
find_header_files(${_base_path} headers)
72+
endif ()
73+
6974
set(${_return_var} "${headers}" PARENT_SCOPE)
7075

7176
endfunction()
@@ -79,8 +84,13 @@ endfunction()
7984
#=============================================================================#
8085
function(find_library_source_files _base_path _return_var)
8186

82-
find_source_files(${_base_path} sources RECURSE) # Library sources are always searched recursively
83-
list(FILTER sources EXCLUDE REGEX "${ARDUINO_CMAKE_EXCLUDED_LIBRARY_SOURCES_PATTERN}")
87+
if (EXISTS ${_base_path}/src)
88+
# Sources are always searched recursively under the 'src' sub-dir
89+
find_source_files(${_base_path}/src sources RECURSE)
90+
else ()
91+
find_source_files(${_base_path} sources)
92+
endif ()
93+
8494
set(${_return_var} "${sources}" PARENT_SCOPE)
8595

8696
endfunction()

cmake/Platform/System/DefaultsManager.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ function(set_source_files_patterns)
3030
"Header Files Pattern")
3131
set(ARDUINO_CMAKE_SKETCH_FILES_PATTERN *.ino *.pde CACHE STRING
3232
"Sketch Files Pattern")
33-
set(ARDUINO_CMAKE_EXCLUDED_LIBRARY_SOURCES_PATTERN "examples?/.+" CACHE STRING
34-
"Regex pattern matching all sources that should be excluded from search
35-
when dealing with libraries")
3633

3734
endfunction()
3835

cmake/Platform/Targets/ArduinoCMakeLibraryTarget.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function(_link_arduino_cmake_library _target_name _library_name)
7373
message(FATAL_ERROR "Target doesn't exist - It must be created first!")
7474
endif ()
7575

76-
set(scope_options "PRIVATE" "PUBLIC" "INTERFACE")
76+
set(scope_options "PRIVATE" "PUBLIC" "INTERFACE" "PLATFORM_LIB")
7777
cmake_parse_arguments(link_library "${scope_options}" "BOARD_CORE_TARGET" "" ${ARGN})
7878

7979
# First, include core lib's directories in library as well
@@ -85,7 +85,9 @@ function(_link_arduino_cmake_library _target_name _library_name)
8585

8686
get_target_property(core_lib_includes ${core_target} INCLUDE_DIRECTORIES)
8787
target_include_directories(${_library_name} PUBLIC "${core_lib_includes}")
88-
target_link_libraries(${_library_name} PUBLIC ${core_target})
88+
if (NOT link_library_PLATFORM_LIB)
89+
target_link_libraries(${_library_name} PUBLIC ${core_target})
90+
endif ()
8991

9092
# Now, link library to executable
9193
if (link_library_PUBLIC)

cmake/Platform/Targets/PlatformLibraryTarget.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ function(_add_platform_library _library_name _board_id)
2929
find_source_files("${ARDUINO_CMAKE_PLATFORM_LIBRARIES_PATH}/${_library_name}/src" lib_source_files)
3030
set(lib_sources ${lib_headers} ${lib_source_files})
3131

32-
_add_arduino_cmake_library(${_library_name} ${_board_id} "${lib_sources}")
32+
_add_arduino_cmake_library(${_library_name} ${_board_id} "${lib_sources}"
33+
ARCH ${ARDUINO_CMAKE_PLATFORM_ARCHITECTURE})
3334

3435
endfunction()
3536

@@ -51,7 +52,8 @@ function(link_platform_library _target_name _library_name _board_id)
5152

5253
get_core_lib_target_name(${_board_id} core_lib_target)
5354
_link_arduino_cmake_library(${_target_name} ${_library_name}
54-
PUBLIC
55+
PUBLIC PLATFORM_LIB
5556
BOARD_CORE_TARGET ${core_lib_target})
57+
#target_link_libraries(${_target_name} PUBLIC ${_library_name})
5658

5759
endfunction()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cmake_minimum_required(VERSION 3.8.2)
2+
3+
project(3rd_Party_Arduino_Library LANGUAGES C CXX ASM)
4+
get_board_id(board_id nano atmega328)
5+
6+
add_arduino_executable(3rd_Party_Arduino_Library ${board_id} test.cpp)
7+
8+
add_arduino_library(Adafruit_NeoPixel ${board_id} libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp)
9+
target_include_directories(Adafruit_NeoPixel PUBLIC libraries/Adafruit_NeoPixel)
10+
11+
# 'Trick' the framework to use current directory as Sketchbook, allowing us to use the 'find' API
12+
set(ARDUINO_CMAKE_SKETCHBOOK_PATH "${CMAKE_CURRENT_LIST_DIR}")
13+
find_arduino_library(Adafruit_GFX Adafruit-GFX-Library ${board_id} 3RD_PARTY)
14+
15+
link_arduino_library(3rd_Party_Arduino_Library Adafruit_NeoPixel ${board_id})
16+
link_arduino_library(3rd_Party_Arduino_Library Adafruit_GFX ${board_id})

0 commit comments

Comments
 (0)