mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-10 09:58:28 -04:00
CMake sketch processing almost complete
Need to get prototypes included after last include. Use string find?
This commit is contained in:
parent
d18bb1cc7e
commit
e6f02d07f8
@ -80,26 +80,53 @@ message(STATUS "Board configured as: ${BOARD}")
|
||||
|
||||
# add a sketch
|
||||
macro(add_sketch SKETCH_NAME BOARD PORT)
|
||||
|
||||
message(STATUS "Generating sketch ${SKETCH_NAME}")
|
||||
|
||||
# files
|
||||
set(SKETCH_CPP ${CMAKE_CURRENT_BINARY_DIR}/${SKETCH_NAME}/${SKETCH_NAME}.cpp)
|
||||
set(SKETCH_PDE ${SKETCH_NAME}/${SKETCH_NAME}.pde)
|
||||
set(SKETCH_PDE ${CMAKE_CURRENT_SOURCE_DIR}/${SKETCH_NAME}/${SKETCH_NAME}.pde)
|
||||
|
||||
# settings
|
||||
set(${SKETCH_NAME}_BOARD ${BOARD})
|
||||
set(${SKETCH_NAME}_PORT ${PORT})
|
||||
set(${SKETCH_NAME}_SRCS ${SKETCH_CPP})
|
||||
set(${SKETCH_NAME}_LIBS m c)
|
||||
|
||||
# find pde files
|
||||
file(GLOB PDE_SOURCES ${SKETCH_NAME}/*.pde)
|
||||
file(READ ${SKETCH_PDE} FILE)
|
||||
file(WRITE ${SKETCH_CPP} ${FILE})
|
||||
file(APPEND ${SKETCH_CPP} "#include \"WProgram.h\"")
|
||||
list(REMOVE_ITEM PDE_SOURCES ${SKETCH_PDE})
|
||||
list(SORT PDE_SOURCES)
|
||||
|
||||
# write main pde
|
||||
file(WRITE ${SKETCH_CPP} "// automatically generated by arduino-cmake\n")
|
||||
|
||||
# write prototypes
|
||||
foreach(PDE ${PDE_SOURCES})
|
||||
message(STATUS "pde: ${PDE}")
|
||||
file(READ ${PDE} FILE)
|
||||
string(REGEX MATCHALL "[ ]*(static)?[ ]*(unsigned|signed)?[ ]*(void)+[ ]*[ _a-zA-Z0-9]*[(][^)]*[)]" PROTOTYPES ${FILE})
|
||||
foreach(PROTOTYPE ${PROTOTYPES})
|
||||
message(STATUS "\tprototype: ${PROTOTYPE}")
|
||||
file(APPEND ${SKETCH_CPP} "${PROTOTYPE};\n")
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
# write source
|
||||
file(READ ${SKETCH_PDE} FILE)
|
||||
file(APPEND ${SKETCH_CPP} ${FILE})
|
||||
foreach (PDE ${PDE_SOURCES})
|
||||
file(READ ${PDE} FILE)
|
||||
file(APPEND ${SKETCH_CPP} ${FILE})
|
||||
endforeach()
|
||||
file(APPEND ${SKETCH_CPP} "#include \"WProgram.h\"\n")
|
||||
|
||||
# generate firmware
|
||||
include_directories(${SKETCH_NAME})
|
||||
generate_arduino_firmware(${SKETCH_NAME})
|
||||
set_target_properties(${SKETCH_NAME} PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
# install settings
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${SKETCH_NAME}.hex
|
||||
DESTINATION bin
|
||||
|
Loading…
Reference in New Issue
Block a user