mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-09 09:28:31 -04:00
Working on prototypes regex for cmake.
This commit is contained in:
parent
e6f02d07f8
commit
4d7016aadc
@ -86,6 +86,8 @@ macro(add_sketch SKETCH_NAME BOARD PORT)
|
|||||||
# files
|
# files
|
||||||
set(SKETCH_CPP ${CMAKE_CURRENT_BINARY_DIR}/${SKETCH_NAME}/${SKETCH_NAME}.cpp)
|
set(SKETCH_CPP ${CMAKE_CURRENT_BINARY_DIR}/${SKETCH_NAME}/${SKETCH_NAME}.cpp)
|
||||||
set(SKETCH_PDE ${CMAKE_CURRENT_SOURCE_DIR}/${SKETCH_NAME}/${SKETCH_NAME}.pde)
|
set(SKETCH_PDE ${CMAKE_CURRENT_SOURCE_DIR}/${SKETCH_NAME}/${SKETCH_NAME}.pde)
|
||||||
|
message(STATUS "SKETCH_PDE:\n${SKETCH_PDE}")
|
||||||
|
message(STATUS "SKETCH_CPP:\n${SKETCH_CPP}")
|
||||||
|
|
||||||
# settings
|
# settings
|
||||||
set(${SKETCH_NAME}_BOARD ${BOARD})
|
set(${SKETCH_NAME}_BOARD ${BOARD})
|
||||||
@ -95,34 +97,52 @@ macro(add_sketch SKETCH_NAME BOARD PORT)
|
|||||||
|
|
||||||
# find pde files
|
# find pde files
|
||||||
file(GLOB PDE_SOURCES ${SKETCH_NAME}/*.pde)
|
file(GLOB PDE_SOURCES ${SKETCH_NAME}/*.pde)
|
||||||
list(REMOVE_ITEM PDE_SOURCES ${SKETCH_PDE})
|
|
||||||
list(SORT PDE_SOURCES)
|
# find the head of the main pde
|
||||||
|
|
||||||
# write main pde
|
|
||||||
file(WRITE ${SKETCH_CPP} "// automatically generated by arduino-cmake\n")
|
file(WRITE ${SKETCH_CPP} "// automatically generated by arduino-cmake\n")
|
||||||
|
file(READ ${SKETCH_PDE} FILE)
|
||||||
|
|
||||||
|
string(FIND "${FILE}" "#include" POS1 REVERSE)
|
||||||
|
string(LENGTH "${FILE}" FILE_LENGTH)
|
||||||
|
math(EXPR LENGTH_STR1 "${FILE_LENGTH}-${POS1}")
|
||||||
|
string(SUBSTRING "${FILE}" ${POS1} ${LENGTH_STR1} STR1)
|
||||||
|
string(FIND "${STR1}" "\n" POS2)
|
||||||
|
math(EXPR POS3 "${POS1}+${POS2}")
|
||||||
|
string(SUBSTRING "${FILE}" 0 ${POS3} FILE_HEAD)
|
||||||
|
message(STATUS "FILE_HEAD:\n${FILE_HEAD}")
|
||||||
|
|
||||||
|
# find the body of the main pde
|
||||||
|
math(EXPR BODY_LENGTH "${FILE_LENGTH}-${POS3}-1")
|
||||||
|
string(SUBSTRING "${FILE}" "${POS3}+1" "${BODY_LENGTH}" FILE_BODY)
|
||||||
|
message(STATUS "BODY:\n${FILE_BODY}")
|
||||||
|
|
||||||
|
# write the file head
|
||||||
|
file(APPEND ${SKETCH_CPP} "${FILE_HEAD}")
|
||||||
|
file(APPEND ${SKETCH_CPP} "\n#include \"WProgram.h\"\n")
|
||||||
|
|
||||||
# write prototypes
|
# write prototypes
|
||||||
foreach(PDE ${PDE_SOURCES})
|
foreach(PDE ${PDE_SOURCES})
|
||||||
message(STATUS "pde: ${PDE}")
|
message(STATUS "pde: ${PDE}")
|
||||||
file(READ ${PDE} FILE)
|
file(READ ${PDE} FILE)
|
||||||
string(REGEX MATCHALL "[ ]*(static)?[ ]*(unsigned|signed)?[ ]*(void)+[ ]*[ _a-zA-Z0-9]*[(][^)]*[)]" PROTOTYPES ${FILE})
|
string(REGEX MATCHALL "([a-zA-Z]+[ ]+)*[ ]*[a-zA-Z0-9]+[ ]+[_a-zA-Z0-9]+[(][^)]*[)]" PROTOTYPES ${FILE})
|
||||||
foreach(PROTOTYPE ${PROTOTYPES})
|
foreach(PROTOTYPE ${PROTOTYPES})
|
||||||
message(STATUS "\tprototype: ${PROTOTYPE}")
|
message(STATUS "\tprototype: ${PROTOTYPE};")
|
||||||
file(APPEND ${SKETCH_CPP} "${PROTOTYPE};\n")
|
file(APPEND ${SKETCH_CPP} "${PROTOTYPE};\n")
|
||||||
endforeach()
|
endforeach()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
|
||||||
# write source
|
# write source
|
||||||
file(READ ${SKETCH_PDE} FILE)
|
file(APPEND ${SKETCH_CPP} "${FILE_BODY}")
|
||||||
file(APPEND ${SKETCH_CPP} ${FILE})
|
list(REMOVE_ITEM PDE_SOURCES ${SKETCH_PDE})
|
||||||
|
list(SORT PDE_SOURCES)
|
||||||
foreach (PDE ${PDE_SOURCES})
|
foreach (PDE ${PDE_SOURCES})
|
||||||
file(READ ${PDE} FILE)
|
file(READ ${PDE} FILE)
|
||||||
file(APPEND ${SKETCH_CPP} ${FILE})
|
file(APPEND ${SKETCH_CPP} "${FILE}")
|
||||||
endforeach()
|
endforeach()
|
||||||
file(APPEND ${SKETCH_CPP} "#include \"WProgram.h\"\n")
|
|
||||||
|
|
||||||
# generate firmware
|
# generate firmware
|
||||||
include_directories(${SKETCH_NAME})
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${SKETCH_NAME})
|
||||||
generate_arduino_firmware(${SKETCH_NAME})
|
generate_arduino_firmware(${SKETCH_NAME})
|
||||||
set_target_properties(${SKETCH_NAME} PROPERTIES LINKER_LANGUAGE CXX)
|
set_target_properties(${SKETCH_NAME} PROPERTIES LINKER_LANGUAGE CXX)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user