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

Commit c6c21cb

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents 30e4236 + 40245d1 commit c6c21cb

File tree

95 files changed

+25139
-65
lines changed

Some content is hidden

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

95 files changed

+25139
-65
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#=============================================================================#
2+
# Recursively finds header files under the given path, excluding those that don't belong to a library,
3+
# such as files under the 'exmaples' directory (In case sources reside under lib's root directory).
4+
# _base_path - Top-Directory path to search source files in.
5+
# _return_var - Name of variable in parent-scope holding the return value.
6+
# Returns - List of source files in the given path
7+
#=============================================================================#
8+
function(find_library_header_files _base_path _return_var)
9+
10+
if (EXISTS ${_base_path}/src) # 'src' sub-dir exists and should contain sources
11+
# Headers are always searched recursively under the 'src' sub-dir
12+
find_header_files(${_base_path}/src headers RECURSE)
13+
else ()
14+
find_header_files(${_base_path} headers)
15+
endif ()
16+
17+
set(${_return_var} "${headers}" PARENT_SCOPE)
18+
19+
endfunction()
20+
21+
#=============================================================================#
22+
# Recursively finds source files under the given path, excluding those that don't belong to a library,
23+
# such as files under the 'exmaples' directory (In case sources reside under lib's root directory).
24+
# _base_path - Top-Directory path to search source files in.
25+
# _return_var - Name of variable in parent-scope holding the return value.
26+
# Returns - List of source files in the given path
27+
#=============================================================================#
28+
function(find_library_source_files _base_path _return_var)
29+
30+
if (EXISTS ${_base_path}/src)
31+
# Sources are always searched recursively under the 'src' sub-dir
32+
find_source_files(${_base_path}/src sources RECURSE)
33+
else ()
34+
find_source_files(${_base_path} sources)
35+
endif ()
36+
37+
set(${_return_var} "${sources}" PARENT_SCOPE)
38+
39+
endfunction()

cmake/Platform/Sources/SourceSeeker.cmake

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#=============================================================================#
22
# Finds source files matching the given pattern under the given path.
33
# Search could also be recursive (With sub-directories) if the optional 'RECURSE' option is passed.
4-
# _base_path - Top-Directory path to search source files in.
5-
# _return_var - Name of variable in parent-scope holding the return value.
6-
# Returns - List of sources in the given path
4+
# _base_path - Top-Directory path to search source files in.
5+
# [RECURSE] - Whether search should be done recursively or not.
6+
# _return_var - Name of variable in parent-scope holding the return value.
7+
# Returns - List of sources in the given path
78
#=============================================================================#
89
function(_find_sources _base_path _pattern _return_var)
910

@@ -29,9 +30,10 @@ endfunction()
2930
# Finds header files matching the pre-defined header-file pattern under the given path.
3031
# This functions searchs explicitly for header-files such as '*.h'.
3132
# Search could also be recursive (With sub-directories) if the optional 'RECURSE' option is passed.
32-
# _base_path - Top-Directory path to search source files in.
33-
# _return_var - Name of variable in parent-scope holding the return value.
34-
# Returns - List of header files in the given path
33+
# _base_path - Top-Directory path to search source files in.
34+
# [RECURSE] - Whether search should be done recursively or not.
35+
# _return_var - Name of variable in parent-scope holding the return value.
36+
# Returns - List of header files in the given path
3537
#=============================================================================#
3638
function(find_header_files _base_path _return_var)
3739

@@ -44,9 +46,10 @@ endfunction()
4446
# Finds source files matching the pre-defined source-file pattern under the given path.
4547
# This functions searchs explicitly for source-files such as '*.c'.
4648
# Search could also be recursive (With sub-directories) if the optional 'RECURSE' option is passed.
47-
# _base_path - Top-Directory path to search source files in.
48-
# _return_var - Name of variable in parent-scope holding the return value.
49-
# Returns - List of source files in the given path
49+
# _base_path - Top-Directory path to search source files in.
50+
# [RECURSE] - Whether search should be done recursively or not.
51+
# _return_var - Name of variable in parent-scope holding the return value.
52+
# Returns - List of source files in the given path
5053
#=============================================================================#
5154
function(find_source_files _base_path _return_var)
5255

@@ -55,43 +58,14 @@ function(find_source_files _base_path _return_var)
5558

5659
endfunction()
5760

58-
#=============================================================================#
59-
# Recursively finds header files under the given path, excluding those that don't belong to a library,
60-
# such as files under the 'exmaples' directory (In case sources reside under lib's root directory).
61-
# _base_path - Top-Directory path to search source files in.
62-
# _return_var - Name of variable in parent-scope holding the return value.
63-
# Returns - List of source files in the given path
64-
#=============================================================================#
65-
function(find_library_header_files _base_path _return_var)
66-
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}")
69-
set(${_return_var} "${headers}" PARENT_SCOPE)
70-
71-
endfunction()
72-
73-
#=============================================================================#
74-
# Recursively finds source files under the given path, excluding those that don't belong to a library,
75-
# such as files under the 'exmaples' directory (In case sources reside under lib's root directory).
76-
# _base_path - Top-Directory path to search source files in.
77-
# _return_var - Name of variable in parent-scope holding the return value.
78-
# Returns - List of source files in the given path
79-
#=============================================================================#
80-
function(find_library_source_files _base_path _return_var)
81-
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}")
84-
set(${_return_var} "${sources}" PARENT_SCOPE)
85-
86-
endfunction()
87-
8861
#=============================================================================#
8962
# Finds sketch files matching the pre-defined sketch-file pattern under the given path.
9063
# This functions searchs explicitly for sketch-files such as '*.ino'.
9164
# Search could also be recursive (With sub-directories) if the optional 'RECURSE' option is passed.
92-
# _base_path - Top-Directory path to search source files in.
93-
# _return_var - Name of variable in parent-scope holding the return value.
94-
# Returns - List of header files in the given path
65+
# _base_path - Top-Directory path to search source files in.
66+
# [RECURSE] - Whether search should be done recursively or not.
67+
# _return_var - Name of variable in parent-scope holding the return value.
68+
# Returns - List of header files in the given path
9569
#=============================================================================#
9670
function(find_sketch_files _base_path _return_var)
9771

cmake/Platform/Sources/SourcesManager.cmake

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,64 @@
11
include(SourceSeeker)
22
include(ExampleSourcesSeeker)
3+
include(ArduinoLibrarySourcesSeeker)
4+
5+
#=============================================================================#
6+
# Appends all sources and headers under the given directory to the givne target.
7+
# This could also be done recursively if the RECURSE option is provided.
8+
# _target_name - Name of the target which sources will be appended to.
9+
# [DIRS] - Indefinite list of directories which its' sources should be appended.
10+
# [RECURSE] - Whether search should be done recursively or not.
11+
# This affects all given directories.
12+
#=============================================================================#
13+
function(target_source_directories _target_name)
14+
15+
cmake_parse_arguments(parsed_args "RECURSE" "" "DIRS" ${ARGN})
16+
17+
if (NOT TARGET ${_target_name})
18+
message(FATAL_ERROR "Can't add sources to the ${_target_name} target as it doesn't exist!")
19+
endif ()
20+
21+
if (NOT parsed_args_DIRS)
22+
message(FATAL_ERROR "Source dirctories must be provided with the DIRS keyword before them!")
23+
endif ()
24+
25+
set(source_dirs ${parsed_args_DIRS})
26+
27+
list(REMOVE_DUPLICATES source_dirs)
28+
29+
if (parsed_args_RECURSE) # Search recursively
30+
foreach (source_dir ${source_dirs})
31+
find_header_files(${source_dir} headers RECURSE)
32+
find_source_files(${source_dir} sources RECURSE)
33+
34+
list(APPEND collective_headers ${headers})
35+
list(APPEND collective_sources ${sources})
36+
endforeach ()
37+
else ()
38+
foreach (source_dir ${source_dirs})
39+
find_header_files(${source_dir} headers)
40+
find_source_files(${source_dir} sources)
41+
42+
list(APPEND collective_headers ${headers})
43+
list(APPEND collective_sources ${sources})
44+
endforeach ()
45+
endif ()
46+
47+
if (collective_headers)
48+
list(REMOVE_DUPLICATES collective_headers)
49+
endif ()
50+
51+
if (collective_sources)
52+
list(REMOVE_DUPLICATES collective_sources)
53+
endif ()
54+
55+
# Treat headers' parent directories as include directories of the target
56+
get_headers_parent_directories("${collective_headers}" include_dirs)
57+
target_include_directories(${_target_name} PUBLIC ${include_dirs})
58+
59+
target_sources(${_target_name} PUBLIC ${collective_sources})
60+
61+
endfunction()
362

463
#=============================================================================#
564
# Gets all '#include' lines of the given source file.

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/PlatformLibraryTarget.cmake

Lines changed: 8 additions & 6 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

@@ -47,11 +48,12 @@ function(link_platform_library _target_name _library_name _board_id)
4748

4849
if (NOT TARGET ${_library_name})
4950
_add_platform_library(${_library_name} ${_board_id})
51+
get_core_lib_target_name(${_board_id} core_lib_target)
52+
_link_arduino_cmake_library(${_target_name} ${_library_name}
53+
PUBLIC
54+
BOARD_CORE_TARGET ${core_lib_target})
55+
else ()
56+
target_link_libraries(${_target_name} PUBLIC ${_library_name})
5057
endif ()
5158

52-
get_core_lib_target_name(${_board_id} core_lib_target)
53-
_link_arduino_cmake_library(${_target_name} ${_library_name}
54-
PUBLIC
55-
BOARD_CORE_TARGET ${core_lib_target})
56-
5759
endfunction()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_minimum_required(VERSION 3.8.2)
2+
3+
project(3rd_Party_Arduino_Library)
4+
get_board_id(board_id nano atmega328)
5+
6+
add_arduino_executable(3rd_Party_Arduino_Library ${board_id} testNeoPixel.cpp testGFX.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+
target_source_directories(Adafruit_GFX
15+
DIRS libraries/Adafruit-GFX-Library/Fonts)
16+
17+
link_arduino_library(3rd_Party_Arduino_Library Adafruit_NeoPixel ${board_id})
18+
link_arduino_library(3rd_Party_Arduino_Library Adafruit_GFX ${board_id})

0 commit comments

Comments
 (0)