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

Added partial support for generating sketch prototypes #84

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1b7663a
Improved header resolving when converting sketches to sources
MrPointer Mar 8, 2019
1b2c0d5
Separated header insertion process into a macro
MrPointer Mar 8, 2019
551a164
Concentrated sketch module under a single file
MrPointer Mar 8, 2019
d01a2eb
Refactored files structure, added header-retrieving API
MrPointer Mar 12, 2019
902c35a
Fixed header retrieval function
MrPointer Apr 5, 2019
0934622
Renamed `check_header_existence` function to `get_header_file`
MrPointer Apr 5, 2019
11399f2
Upgraded header discoverability (by targets) check
MrPointer Apr 5, 2019
2227835
Added sketch header resolving, updated library resolving to use it
MrPointer Apr 6, 2019
591ef39
Applied new CMake 'newline' cache policy to some regexes
MrPointer Apr 25, 2019
8f95591
Added function definition-declaration matching
MrPointer Apr 25, 2019
f347ad2
Added partial sketch prototype resolving
MrPointer Apr 25, 2019
b2e3e01
Added utility function to get list's max/largest index
MrPointer Apr 25, 2019
64a8afb
Added insertion of sketch prototypes to converted sources
MrPointer Apr 25, 2019
02039eb
Completely redesigned sketch-to-source conversion process
MrPointer Apr 26, 2019
d63b448
Fixed bug generating only a single prototype in converted source
MrPointer Apr 26, 2019
777f95e
Fixed `resolve_sketch_headers` to actually return headers
MrPointer Apr 26, 2019
8113934
Converted all regex from cache variables to global properties
MrPointer Apr 26, 2019
77b5642
Fixed minor bug
MrPointer Apr 26, 2019
0e5d73e
Fixed minor bug
MrPointer Apr 26, 2019
6e060ab
Updated ignore to ignore CLion + build dir
MrPointer Apr 27, 2019
59f95b3
Fix Arduino SDK bin folder search on Linux
jeandet May 5, 2019
4f20e4f
Fixed function definition regex pattern
MrPointer Apr 27, 2019
14d1c7b
Fixed cache-related bug in `find_arduino_library`
MrPointer Jun 17, 2019
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
98 changes: 93 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,93 @@ crashlytics.properties
crashlytics-build.properties
fabric.properties

# Created by https://www.gitignore.io/api/clion
# Edit at https://www.gitignore.io/?templates=clion

### CLion ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

# JetBrains templates
**___jb_tmp___

### CLion Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
.idea/sonarlint

# End of https://www.gitignore.io/api/clion

### VisualStudioCode ###
.vscode/*
!.vscode/tasks.json
Expand All @@ -129,8 +216,9 @@ fabric.properties

### User-Defined
[Aa]ssets/*
/examples/blink-example/Blink.cpp
/examples/servo-knob-example/Knob.cpp
/examples/sketch/sketch1.cpp
/examples/sketch/sketch2.cpp
/docs/wiki
[Bb]uild/
examples/blink-example/Blink.cpp
examples/servo-knob-example/Knob.cpp
examples/sketch/sketch1.cpp
examples/sketch/sketch2.cpp
docs/wiki
6 changes: 4 additions & 2 deletions cmake/Platform/Arduino.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ include(Boards)

include(RecipeParser)
include(TargetFlagsManager)
include(SourcesManager)
include(SketchManager)

include(Sources)
include(Sketches)

include(DefaultsManager)
include(ArchitectureSupportQuery)
include(CMakeProperties)
Expand Down
12 changes: 7 additions & 5 deletions cmake/Platform/Libraries/LibrariesFinder.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
macro(_cleanup_find_arduino_library)
macro(_clear_find_library_state)

unset(library_path CACHE)

Expand All @@ -18,6 +18,8 @@ endmacro()
#=============================================================================#
function(find_arduino_library _target_name _library_name)

_clear_find_library_state()

set(argument_options "3RD_PARTY" "HEADER_ONLY" "QUIET")
cmake_parse_arguments(parsed_args "${argument_options}" "" "" ${ARGN})

Expand All @@ -28,7 +30,7 @@ function(find_arduino_library _target_name _library_name)
endif ()

find_file(library_path
NAMES ${_library_name}
NAMES "${_library_name}"
PATHS ${ARDUINO_CMAKE_PLATFORM_LIBRARIES_PATH} ${ARDUINO_SDK_LIBRARIES_PATH}
${ARDUINO_CMAKE_SKETCHBOOK_PATH} ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}
PATH_SUFFIXES libraries dependencies
Expand All @@ -43,7 +45,7 @@ function(find_arduino_library _target_name _library_name)

if (NOT library_headers)
if (parsed_args_QUIET)
_cleanup_find_arduino_library()
_clear_find_library_state()
return()
else ()
message(SEND_ERROR "Couldn't find any header files for the "
Expand All @@ -57,7 +59,7 @@ function(find_arduino_library _target_name _library_name)

if (NOT library_sources)
if (parsed_args_QUIET)
_cleanup_find_arduino_library()
_clear_find_library_state()
return()
else ()
message(SEND_ERROR "Couldn't find any source files for the "
Expand All @@ -78,6 +80,6 @@ function(find_arduino_library _target_name _library_name)
endif ()
endif ()

_cleanup_find_arduino_library()
_clear_find_library_state()

endfunction()
9 changes: 5 additions & 4 deletions cmake/Platform/Other/ArduinoSDKSeeker.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,16 @@ function(find_arduino_sdk_bin _return_var)
set(${_return_var} "${ARDUINO_SDK_PATH}/hardware/tools/avr/bin" PARENT_SCOPE)
else ()
# Some systems like the Arch Linux arduino package install binaries to /usr/bin
find_program(avr_gcc_location avr-gcc)
if ("${avr_gcc_location}" MATCHES "NOTFOUND")
# But gcc can be found first in ccache folder so let's search ar instead
find_program(avr_gcc_ar_location avr-gcc-ar)
if ("${avr_gcc_ar_location}" MATCHES "NOTFOUND")
string(CONCAT error_message
"Couldn't find Arduino bin path - Is it in a non-standard location?" "\n"
"If so, please set the ARDUINO_SDK_BIN_PATH CMake-Variable")
message(FATAL_ERROR ${error_message})
else ()
get_filename_component(avr_gcc_parent ${avr_gcc_location} DIRECTORY)
set(${_return_var} "${avr_gcc_parent}" PARENT_SCOPE)
get_filename_component(avr_gcc_ar_parent ${avr_gcc_ar_location} DIRECTORY)
set(${_return_var} "${avr_gcc_ar_parent}" PARENT_SCOPE)
endif ()
endif ()

Expand Down
47 changes: 0 additions & 47 deletions cmake/Platform/Sketches/SketchHeadersManager.cmake

This file was deleted.

23 changes: 23 additions & 0 deletions cmake/Platform/Sketches/SketchHeadersResolver.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#=============================================================================#
# Resolves all headers used by a given sketch file by searching its 'include lines', recursively.
# _target_name - Name of the sketch's target created earlier.
# _sketch_file - Path to the sketch file which its' headers should be resolved.
# _return_var - Name of variable in parent-scope holding the return value.
# Returns - List of all unique header files used by the sketch file, recursively.
#=============================================================================#
function(resolve_sketch_headers _target_name _sketch_file _return_var)

get_target_include_directories(${_target_name} target_include_dirs)

get_source_headers("${_sketch_file}" "${target_include_dirs}" sketch_headers RECURSIVE)
get_source_headers("${ARDUINO_CMAKE_PLATFORM_HEADER_PATH}" "${target_include_dirs}" platform_headers RECURSIVE)

list(APPEND sketch_headers ${platform_headers})

if (sketch_headers)
list(REMOVE_DUPLICATES sketch_headers)
endif ()

set(${_return_var} ${sketch_headers} PARENT_SCOPE)

endfunction()
24 changes: 24 additions & 0 deletions cmake/Platform/Sketches/SketchLibrariesResolver.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#=============================================================================#
# Resolves the libraries used by a sketch file. It's possible that not all libraries will be resolved,
# as the current algorithm relies on the name of the included headers to match a library name.
# _target_name - Name of the sketch's target created earlier.
# _sketch_file - Path to the sketch file which its' libraries should be resolved.
# _sketch_headers - List of headers files used by the sketch, directly or indirectly.
#=============================================================================#
function(resolve_sketch_libraries _target_name _sketch_file _sketch_headers)

foreach (header ${_sketch_headers})

# Header name without extension (such as '.h') can represent an Arduino/Platform library
get_name_without_file_extension("${header}" header_we)

# Pass the '3RD_PARTY' option to avoid name-conversion
find_arduino_library(${header_we}_sketch_lib ${header_we} 3RD_PARTY QUIET)

if (TARGET ${header_we}_sketch_lib)
link_arduino_library(${_target_name} ${header_we}_sketch_lib)
endif ()

endforeach ()

endfunction()
12 changes: 5 additions & 7 deletions cmake/Platform/Sketches/SketchManager.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
include(SketchSourceConverter)
include(SketchHeadersManager)

#=============================================================================#
# Returns a desired path for sources converted from sketches.
# It can't be resolved just by a cache variable since sketches may belong each to a different project,
Expand Down Expand Up @@ -31,12 +28,13 @@ function(add_sketch_to_target _target_name _sketch_file)
_get_converted_source_desired_path(${_sketch_file} sketch_converted_source_path)

# Only perform conversion if policy is set or if sketch hasn't been converted yet
if (CONVERT_SKETCHES_IF_CONVERTED_SOURCES_EXISTS OR
NOT EXISTS ${sketch_converted_source_path})
if (CONVERT_SKETCHES_IF_CONVERTED_SOURCES_EXISTS OR NOT EXISTS ${sketch_converted_source_path})

resolve_sketch_headers(${_target_name} ${_sketch_file})
resolve_sketch_headers(${_target_name} ${_sketch_file} sketch_headers)
resolve_sketch_libraries(${_target_name} ${_sketch_file} "${sketch_headers}")
resolve_sketch_prototypes(${_sketch_file} "${sketch_headers}" sketch_prototypes)

convert_sketch_to_source(${_sketch_file} ${sketch_converted_source_path})
convert_sketch_to_source(${_sketch_file} ${sketch_converted_source_path} "${sketch_prototypes}")

endif ()

Expand Down
32 changes: 32 additions & 0 deletions cmake/Platform/Sketches/SketchPrototypesResolver.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#=============================================================================#
# Resolves the given sketch file's prototypes, which are just function declarations,
# by matching all function definitions with their declaration. If a declaration can't be found,
# the definition is added to a list of prototypes to generate, which is then returned.
# _sketch_file - Path to the sketch file which its' libraries should be resolved.
# _sketch_headers - List of headers files used by the sketch, directly or indirectly.
# _return_var - Name of variable in parent-scope holding the return value.
# Returns - List of prototypes to generate, i.e. function definitions without a matching declaration.
#=============================================================================#
function(resolve_sketch_prototypes _sketch_file _sketch_headers _return_var)

get_source_function_definitions(${_sketch_file} sketch_func_defines)
if (NOT sketch_func_defines) # Source has no function definitions at all
return()
endif ()

# Add the current file to the list of headers to search in as well - It's the functions' containing file
list(APPEND _sketch_headers "${_sketch_file}")

foreach (func_def ${sketch_func_defines})

match_function_declaration("${func_def}" "${_sketch_headers}" match)

if (${match} MATCHES "NOTFOUND")
list(APPEND prototypes "${func_def}")
endif ()

endforeach ()

set(${_return_var} ${prototypes} PARENT_SCOPE)

endfunction()
Loading