Skip to content

Commit 7f5d45e

Browse files
authored
Merge pull request #2283 from ddowling/multiple-sketch-support
* Support calling build_sketch() multiple times in the CMakeList.txt file build multiple targets. Add an include_guard() on build_sketch.cmake to prevent errors if this file is included multiple time. * Fix dependency generation error when the sketch ino file is not in the project base directory. * Fix sketch_preprocess_sources to make consistent use of the ${CMAKE_CURRENT_BINARY_DIR} on all generated files.
2 parents c12103b + 076681a commit 7f5d45e

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

cmake/build_sketch.cmake

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
cmake_minimum_required(VERSION 3.21)
22

3+
# Only want the variant and library targets to be defined once
4+
include_guard(GLOBAL)
5+
36
include(sketch_preprocess_sources)
47
include(convert_file)
58

69
include(set_base_arduino_config)
710

11+
add_subdirectory(${BUILD_VARIANT_PATH} ./variant)
12+
add_subdirectory(${BUILD_CORE_PATH} ./cores/arduino)
13+
add_subdirectory(${BUILD_LIB_PATH} ./libraries)
14+
815
function(build_sketch)
9-
add_subdirectory(${BUILD_VARIANT_PATH} ./variant)
10-
add_subdirectory(${BUILD_CORE_PATH} ./cores/arduino)
11-
add_subdirectory(${BUILD_LIB_PATH} ./libraries)
1216

1317

1418
cmake_parse_arguments(PARSE_ARGV 0 SKBD "" "TARGET" "SOURCES;DEPENDS")

cmake/sketch_preprocess_sources.cmake

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,31 @@ function(sketch_preprocess_sources)
55
set(SRCLIST "")
66
foreach(SRCFILE IN LISTS SPC_SOURCES)
77
if (${SRCFILE} MATCHES "\.ino$")
8+
# Convert <file>.ino to ${CMAKE_CURRENT_BINARY_DIR}/<file>.ino.{cpp,h}
89
cmake_path(GET SRCFILE FILENAME SRC_BASE_NAME)
10+
set(SRC_BINARY_BASE_NAME ${CMAKE_CURRENT_BINARY_DIR}/${SRC_BASE_NAME})
911

1012
configure_file(
1113
${SRCFILE}
12-
${CMAKE_CURRENT_BINARY_DIR}/${SRC_BASE_NAME}.cpp
14+
${SRC_BINARY_BASE_NAME}.cpp
1315
COPYONLY
1416
)
1517

16-
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${SRC_BASE_NAME}.h
17-
COMMAND ${ARDUINOCTAGS_EXECUTABLE} -u --language-force=c++ -f ${CMAKE_CURRENT_BINARY_DIR}/${SRC_BASE_NAME}.ctags --c++-kinds=svpf --fields=KSTtzns --line-directives ${CMAKE_CURRENT_BINARY_DIR}/${SRC_BASE_NAME}.cpp
18-
COMMAND ${Python3_EXECUTABLE} ${SCRIPTS_FOLDER}/generate_header.py -i ${CMAKE_CURRENT_BINARY_DIR}/${SRC_BASE_NAME}.ctags -o ${CMAKE_CURRENT_BINARY_DIR}/${SRC_BASE_NAME}.h
18+
add_custom_command(OUTPUT ${SRC_BINARY_BASE_NAME}.h
19+
COMMAND ${ARDUINOCTAGS_EXECUTABLE} -u --language-force=c++ -f ${SRC_BINARY_BASE_NAME}.ctags --c++-kinds=svpf --fields=KSTtzns --line-directives ${SRC_BINARY_BASE_NAME}.cpp
20+
COMMAND ${Python3_EXECUTABLE} ${SCRIPTS_FOLDER}/generate_header.py -i ${SRC_BINARY_BASE_NAME}.ctags -o ${SRC_BINARY_BASE_NAME}.h
1921

20-
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${SRC_BASE_NAME}.cpp
21-
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${SRC_BASE_NAME}.ctags
22+
DEPENDS ${SRC_BINARY_BASE_NAME}.cpp
23+
BYPRODUCTS ${SRC_BINARY_BASE_NAME}.ctags
2224
VERBATIM
2325
)
2426

25-
set_source_files_properties(${SRCFILE}.cpp
27+
set_source_files_properties(${SRC_BINARY_BASE_NAME}.cpp
2628
PROPERTIES
27-
COMPILE_OPTIONS "-include;Arduino.h;-include;${SRCFILE}.h"
28-
OBJECT_DEPENDS "${SRCFILE}.h"
29+
COMPILE_OPTIONS "-include;Arduino.h;-include;${SRC_BINARY_BASE_NAME}.h"
30+
OBJECT_DEPENDS ${SRC_BINARY_BASE_NAME}.h
2931
)
30-
list(APPEND SRCLIST ${SRCFILE}.cpp)
32+
list(APPEND SRCLIST ${SRC_BINARY_BASE_NAME}.cpp)
3133
else()
3234
list(APPEND SRCLIST ${SRCFILE})
3335
endif()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy