Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions cmake/Platform/Sources/ArduinoLibrarySourcesSeeker.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#=============================================================================#
# Recursively finds header files under the given path, excluding those that don't belong to a library,
# such as files under the 'exmaples' directory (In case sources reside under lib's root directory).
# _base_path - Top-Directory path to search source files in.
# _return_var - Name of variable in parent-scope holding the return value.
# Returns - List of source files in the given path
#=============================================================================#
function(find_library_header_files _base_path _return_var)

if (EXISTS ${_base_path}/src) # 'src' sub-dir exists and should contain sources
# Headers are always searched recursively under the 'src' sub-dir
find_header_files(${_base_path}/src headers RECURSE)
else ()
find_header_files(${_base_path} headers)
endif ()

set(${_return_var} "${headers}" PARENT_SCOPE)

endfunction()

#=============================================================================#
# Recursively finds source files under the given path, excluding those that don't belong to a library,
# such as files under the 'exmaples' directory (In case sources reside under lib's root directory).
# _base_path - Top-Directory path to search source files in.
# _return_var - Name of variable in parent-scope holding the return value.
# Returns - List of source files in the given path
#=============================================================================#
function(find_library_source_files _base_path _return_var)

if (EXISTS ${_base_path}/src)
# Sources are always searched recursively under the 'src' sub-dir
find_source_files(${_base_path}/src sources RECURSE)
else ()
find_source_files(${_base_path} sources)
endif ()

set(${_return_var} "${sources}" PARENT_SCOPE)

endfunction()
58 changes: 16 additions & 42 deletions cmake/Platform/Sources/SourceSeeker.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#=============================================================================#
# Finds source files matching the given pattern under the given path.
# Search could also be recursive (With sub-directories) if the optional 'RECURSE' option is passed.
# _base_path - Top-Directory path to search source files in.
# _return_var - Name of variable in parent-scope holding the return value.
# Returns - List of sources in the given path
# _base_path - Top-Directory path to search source files in.
# [RECURSE] - Whether search should be done recursively or not.
# _return_var - Name of variable in parent-scope holding the return value.
# Returns - List of sources in the given path
#=============================================================================#
function(_find_sources _base_path _pattern _return_var)

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

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

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

endfunction()

#=============================================================================#
# Recursively finds header files under the given path, excluding those that don't belong to a library,
# such as files under the 'exmaples' directory (In case sources reside under lib's root directory).
# _base_path - Top-Directory path to search source files in.
# _return_var - Name of variable in parent-scope holding the return value.
# Returns - List of source files in the given path
#=============================================================================#
function(find_library_header_files _base_path _return_var)

find_header_files(${_base_path} headers RECURSE) # Library headers are always searched recursively
list(FILTER headers EXCLUDE REGEX "${ARDUINO_CMAKE_EXCLUDED_LIBRARY_SOURCES_PATTERN}")
set(${_return_var} "${headers}" PARENT_SCOPE)

endfunction()

#=============================================================================#
# Recursively finds source files under the given path, excluding those that don't belong to a library,
# such as files under the 'exmaples' directory (In case sources reside under lib's root directory).
# _base_path - Top-Directory path to search source files in.
# _return_var - Name of variable in parent-scope holding the return value.
# Returns - List of source files in the given path
#=============================================================================#
function(find_library_source_files _base_path _return_var)

find_source_files(${_base_path} sources RECURSE) # Library sources are always searched recursively
list(FILTER sources EXCLUDE REGEX "${ARDUINO_CMAKE_EXCLUDED_LIBRARY_SOURCES_PATTERN}")
set(${_return_var} "${sources}" PARENT_SCOPE)

endfunction()

#=============================================================================#
# Finds sketch files matching the pre-defined sketch-file pattern under the given path.
# This functions searchs explicitly for sketch-files such as '*.ino'.
# Search could also be recursive (With sub-directories) if the optional 'RECURSE' option is passed.
# _base_path - Top-Directory path to search source files in.
# _return_var - Name of variable in parent-scope holding the return value.
# Returns - List of header files in the given path
# _base_path - Top-Directory path to search source files in.
# [RECURSE] - Whether search should be done recursively or not.
# _return_var - Name of variable in parent-scope holding the return value.
# Returns - List of header files in the given path
#=============================================================================#
function(find_sketch_files _base_path _return_var)

Expand Down
59 changes: 59 additions & 0 deletions cmake/Platform/Sources/SourcesManager.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,64 @@
include(SourceSeeker)
include(ExampleSourcesSeeker)
include(ArduinoLibrarySourcesSeeker)

#=============================================================================#
# Appends all sources and headers under the given directory to the givne target.
# This could also be done recursively if the RECURSE option is provided.
# _target_name - Name of the target which sources will be appended to.
# [DIRS] - Indefinite list of directories which its' sources should be appended.
# [RECURSE] - Whether search should be done recursively or not.
# This affects all given directories.
#=============================================================================#
function(target_source_directories _target_name)

cmake_parse_arguments(parsed_args "RECURSE" "" "DIRS" ${ARGN})

if (NOT TARGET ${_target_name})
message(FATAL_ERROR "Can't add sources to the ${_target_name} target as it doesn't exist!")
endif ()

if (NOT parsed_args_DIRS)
message(FATAL_ERROR "Source dirctories must be provided with the DIRS keyword before them!")
endif ()

set(source_dirs ${parsed_args_DIRS})

list(REMOVE_DUPLICATES source_dirs)

if (parsed_args_RECURSE) # Search recursively
foreach (source_dir ${source_dirs})
find_header_files(${source_dir} headers RECURSE)
find_source_files(${source_dir} sources RECURSE)

list(APPEND collective_headers ${headers})
list(APPEND collective_sources ${sources})
endforeach ()
else ()
foreach (source_dir ${source_dirs})
find_header_files(${source_dir} headers)
find_source_files(${source_dir} sources)

list(APPEND collective_headers ${headers})
list(APPEND collective_sources ${sources})
endforeach ()
endif ()

if (collective_headers)
list(REMOVE_DUPLICATES collective_headers)
endif ()

if (collective_sources)
list(REMOVE_DUPLICATES collective_sources)
endif ()

# Treat headers' parent directories as include directories of the target
get_headers_parent_directories("${collective_headers}" include_dirs)
target_include_directories(${_target_name} PUBLIC ${include_dirs})

target_sources(${_target_name} PUBLIC ${collective_sources})

endfunction()

#=============================================================================#
# Gets all '#include' lines of the given source file.
Expand Down
3 changes: 0 additions & 3 deletions cmake/Platform/System/DefaultsManager.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ function(set_source_files_patterns)
"Header Files Pattern")
set(ARDUINO_CMAKE_SKETCH_FILES_PATTERN *.ino *.pde CACHE STRING
"Sketch Files Pattern")
set(ARDUINO_CMAKE_EXCLUDED_LIBRARY_SOURCES_PATTERN "examples?/.+" CACHE STRING
"Regex pattern matching all sources that should be excluded from search
when dealing with libraries")

endfunction()

Expand Down
14 changes: 8 additions & 6 deletions cmake/Platform/Targets/PlatformLibraryTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function(_add_platform_library _library_name _board_id)
find_source_files("${ARDUINO_CMAKE_PLATFORM_LIBRARIES_PATH}/${_library_name}/src" lib_source_files)
set(lib_sources ${lib_headers} ${lib_source_files})

_add_arduino_cmake_library(${_library_name} ${_board_id} "${lib_sources}")
_add_arduino_cmake_library(${_library_name} ${_board_id} "${lib_sources}"
ARCH ${ARDUINO_CMAKE_PLATFORM_ARCHITECTURE})

endfunction()

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

if (NOT TARGET ${_library_name})
_add_platform_library(${_library_name} ${_board_id})
get_core_lib_target_name(${_board_id} core_lib_target)
_link_arduino_cmake_library(${_target_name} ${_library_name}
PUBLIC
BOARD_CORE_TARGET ${core_lib_target})
else ()
target_link_libraries(${_target_name} PUBLIC ${_library_name})
endif ()

get_core_lib_target_name(${_board_id} core_lib_target)
_link_arduino_cmake_library(${_target_name} ${_library_name}
PUBLIC
BOARD_CORE_TARGET ${core_lib_target})

endfunction()
18 changes: 18 additions & 0 deletions examples/3rd-party-library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.8.2)

project(3rd_Party_Arduino_Library)
get_board_id(board_id nano atmega328)

add_arduino_executable(3rd_Party_Arduino_Library ${board_id} testNeoPixel.cpp testGFX.cpp)

add_arduino_library(Adafruit_NeoPixel ${board_id} libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp)
target_include_directories(Adafruit_NeoPixel PUBLIC libraries/Adafruit_NeoPixel)

# 'Trick' the framework to use current directory as Sketchbook, allowing us to use the 'find' API
set(ARDUINO_CMAKE_SKETCHBOOK_PATH "${CMAKE_CURRENT_LIST_DIR}")
find_arduino_library(Adafruit_GFX Adafruit-GFX-Library ${board_id} 3RD_PARTY)
target_source_directories(Adafruit_GFX
DIRS libraries/Adafruit-GFX-Library/Fonts)

link_arduino_library(3rd_Party_Arduino_Library Adafruit_NeoPixel ${board_id})
link_arduino_library(3rd_Party_Arduino_Library Adafruit_GFX ${board_id})
Loading