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

Commit 40965fe

Browse files
committed
Modified sketch target API to be more similar to CMake's targets API.
It's reflected mostly by the `target_sketches` function which adds sketches as converted source files to an already created target, just as CMake's `target_sources` does. The 'Example' modules that depend on the sketch API has been updated to use new API. Also removed the `SketchTarget` module which allowed to create a target consisting of a single sketch files as this is not necessary anymore. The 'sketch' example has been updated accordingly.
1 parent 729fe95 commit 40965fe

File tree

7 files changed

+23
-44
lines changed

7 files changed

+23
-44
lines changed

cmake/Platform/Arduino.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@ include(ArduinoCMakeLibraryTarget)
2626
include(ArduinoLibraryTarget)
2727
include(PlatformLibraryTarget)
2828
include(ArduinoExampleTarget)
29-
include(SketchTarget)
3029

3130
initialize_build_system()

cmake/Platform/Sketches/SketchHeadersManager.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ endfunction()
4646
# Resolves the header files included in a sketch by linking their appropriate library if necessary
4747
# or by validating they're included by the sketch target.
4848
# _target_name - Name of the target to add the sketch file to.
49-
# _sketch_file - Path to a sketch file to add to the target.
5049
# _board_id - ID of the board to bind to the target (Each target can have a single board).
50+
# _sketch_file - Path to a sketch file to add to the target.
5151
#=============================================================================#
52-
function(resolve_sketch_headers _target_name _sketch_file _board_id)
52+
function(resolve_sketch_headers _target_name _board_id _sketch_file)
5353

5454
_get_sketch_headers("${_sketch_file}" sketch_headers)
5555
foreach (header ${sketch_headers})

cmake/Platform/Sketches/SketchManager.cmake

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,28 @@ endfunction()
2222
# Each sketch is converted to a valid '.cpp' source file under the project's source directory.
2323
# The function also finds and links any libraries the sketch uses to the target.
2424
# _target_name - Name of the target to add the sketch file to.
25-
# _sketch_file - Path to a sketch file to add to the target.
2625
# _board_id - ID of the board to bind to the target (Each target can have a single board).
26+
# _sketch_file - Path to a sketch file to add to the target.
2727
#=============================================================================#
28-
function(add_sketch_to_target _target_name _sketch_file _board_id)
28+
function(add_sketch_to_target _target_name _board_id _sketch_file)
2929

30-
resolve_sketch_headers(${_target_name} "${_sketch_file}")
30+
resolve_sketch_headers(${_target_name} ${_board_id} "${_sketch_file}")
3131
_get_converted_source_desired_path("${_sketch_file}" sketch_converted_source_path)
3232
convert_sketch_to_source("${_sketch_file}" "${sketch_converted_source_path}")
3333
target_sources(${_target_name} PRIVATE "${sketch_converted_source_path}")
3434

3535
endfunction()
3636

3737
#=============================================================================#
38-
# Converts all the given sketch file into valid 'cpp' source files and returns their paths.
39-
# _sketch_files - List of paths to original sketch files.
40-
# _return_var - Name of variable in parent-scope holding the return value.
41-
# Returns - List of paths representing post-conversion sources.
38+
# Adds a list of sketch files as converted sources to the given target.
39+
# _target_name - Name of the target to add the sketch file to.
40+
# _board_id - ID of the board to bind to the target (Each target can have a single board).
41+
# _sketch_files - List of paths to sketch files to add to the target.
4242
#=============================================================================#
43-
function(get_sources_from_sketches _sketch_files _return_var)
44-
45-
set(sources)
46-
foreach (sketch ${_sketch_files})
47-
get_filename_component(sketch_file_name "${sketch}" NAME_WE)
48-
set(target_source_path "${CMAKE_CURRENT_SOURCE_DIR}/${sketch_file_name}.cpp")
49-
# Only convert sketch if it hasn't been converted yet
50-
if (NOT EXISTS "${target_source_path}")
51-
convert_sketch_to_source("${sketch}" "${target_source_path}")
52-
endif ()
53-
list(APPEND sources "${target_source_path}")
54-
endforeach ()
43+
function(target_sketches _target_name _board_id _sketch_files)
5544

56-
set(${_return_var} ${sources} PARENT_SCOPE)
45+
foreach (sketch_file ${_sketch_files})
46+
add_sketch_to_target(${_target_name} ${_board_id} "${sketch_file}")
47+
endforeach ()
5748

5849
endfunction()

cmake/Platform/Sketches/SketchSourceConverter.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ endfunction()
5454
# During the conversion process the platform's main header file is inserted to the source file
5555
# since it's critical for it to include it - Something that doesn't happen in "Standard" sketches.
5656
# _sketch_file - Full path to the original sketch file (Read from).
57-
# _target_file - Full path to the converted target source file (Written to).
57+
# _converted_source_path - Full path to the converted target source file (Written to).
5858
#=============================================================================#
59-
function(convert_sketch_to_source _sketch_file _target_file)
59+
function(convert_sketch_to_source _sketch_file _converted_source_path)
6060

6161
file(STRINGS "${_sketch_file}" sketch_loc)
6262
list(LENGTH sketch_loc num_of_loc)
@@ -91,6 +91,6 @@ function(convert_sketch_to_source _sketch_file _target_file)
9191
endif ()
9292
endforeach ()
9393

94-
_write_source_file("${refined_sketch}" "${target_source_path}")
94+
_write_source_file("${refined_sketch}" "${_converted_source_path}")
9595

9696
endfunction()

cmake/Platform/Targets/ArduinoExampleTarget.cmake

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ function(add_arduino_example _target_name _board_id _example_name)
1313

1414
find_arduino_example_sources("${ARDUINO_SDK_EXAMPLES_PATH}"
1515
${_example_name} example_sketches ${ARGN})
16-
get_sources_from_sketches("${example_sketches}" example_sources)
17-
add_arduino_executable(${_target_name} ${_board_id} ${example_sources})
16+
# First create the target (Without sources), then add sketches as converted sources
17+
add_arduino_executable(${_target_name} ${_board_id} "")
18+
target_sketches(${_target_name} ${_board_id} "${example_sketches}")
1819

1920
endfunction()
2021

@@ -40,8 +41,8 @@ function(add_arduino_library_example _target_name _library_target_name _library_
4041

4142
find_arduino_library_example_sources("${ARDUINO_SDK_LIBRARIES_PATH}/${_library_name}"
4243
${_example_name} example_sketches ${ARGN})
43-
get_sources_from_sketches("${example_sketches}" example_sources)
44-
add_arduino_executable(${_target_name} ${_board_id} ${example_sources})
44+
add_arduino_executable(${_target_name} ${_board_id} "")
45+
target_sketches(${_target_name} ${_board_id} "${example_sketches}")
4546
link_arduino_library(${_target_name} ${_library_target_name} ${_board_id})
4647

4748
endfunction()

cmake/Platform/Targets/SketchTarget.cmake

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/sketch/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ cmake_minimum_required(VERSION 3.8)
33
project(Sketch LANGUAGES C CXX ASM)
44
get_board_id(board_id nano atmega328)
55

6-
add_sketch_target(Sketch ${board_id} sketch.ino)
6+
add_arduino_executable(Sketch ${board_id} "")
7+
target_sketches(Sketch ${board_id} sketch.ino)

0 commit comments

Comments
 (0)