2011-10-31 12:32:48 -03:00
|
|
|
cmake_minimum_required(VERSION 2.8.5)
|
2011-09-30 17:55:27 -03:00
|
|
|
|
2011-11-25 22:35:20 -04:00
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
|
2011-09-30 17:55:27 -03:00
|
|
|
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchains/Arduino.cmake)
|
|
|
|
|
|
|
|
# modify flags from default toolchain flags
|
2011-09-30 19:52:41 -03:00
|
|
|
set(APM_OPT_FLAGS "-Wformat -Wall -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wformat=2")
|
2011-09-30 17:55:27 -03:00
|
|
|
|
|
|
|
set(ARDUINO_C_FLAGS "${APM_OPT_FLAGS} -mcall-prologues -ffunction-sections -fdata-sections")
|
2011-09-30 19:52:41 -03:00
|
|
|
set(ARDUINO_CXX_FLAGS "${APM_OPT_FLAGS} -mcall-prologues -ffunction-sections -fdata-sections -fno-exceptions -Wno-reorder")
|
|
|
|
set(ARDUINO_LINKER_FLAGS "-lc -lm ${APM_OPT_FLAGS} -Wl,--gc-sections")
|
2011-09-30 17:55:27 -03:00
|
|
|
|
|
|
|
project(ArduPilotMega C CXX)
|
|
|
|
|
|
|
|
# set default cmake build type to RelWithDebInfo (None Debug Release RelWithDebInfo MinSizeRel)
|
|
|
|
if( NOT DEFINED CMAKE_BUILD_TYPE )
|
|
|
|
set( CMAKE_BUILD_TYPE "RelWithDebInfo" )
|
|
|
|
endif()
|
|
|
|
|
2011-09-30 21:24:02 -03:00
|
|
|
# set these for release
|
|
|
|
set(APPLICATION_VERSION_MAJOR "1")
|
|
|
|
set(APPLICATION_VERSION_MINOR "2")
|
|
|
|
set(APPLICATION_VERSION_PATCH "0")
|
|
|
|
|
|
|
|
# dependencies
|
|
|
|
find_package(Arduino 22 REQUIRED)
|
|
|
|
|
|
|
|
# cmake settigns
|
|
|
|
set(APPLICATION_NAME ${PROJECT_NAME})
|
|
|
|
set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
|
|
|
|
|
|
|
|
# macros
|
|
|
|
include(MacroEnsureOutOfSourceBuild)
|
2011-11-28 13:29:05 -04:00
|
|
|
#include(UseDoxygen)
|
2011-09-30 21:24:02 -03:00
|
|
|
|
|
|
|
# disallow in-source build
|
|
|
|
macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out of source build.
|
|
|
|
Please create a separate build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there.")
|
|
|
|
|
|
|
|
# options
|
|
|
|
if (NOT DEFINED BOARD)
|
2011-12-07 20:19:30 -04:00
|
|
|
message(STATUS "please define the board type (for example: cmake -DBOARD=mega, assuming mega2560")
|
|
|
|
set(BOARD "mega2560")
|
2011-09-30 21:24:02 -03:00
|
|
|
endif()
|
|
|
|
|
2011-10-30 02:36:45 -03:00
|
|
|
if (NOT DEFINED PORT)
|
|
|
|
message(STATUS "please define the upload port (for example: cmake
|
|
|
|
-DPORT=/dev/ttyUSB0, assuming /dev/ttyUSB0")
|
|
|
|
set(PORT "/dev/ttyUSB0")
|
|
|
|
endif()
|
|
|
|
|
2011-09-30 21:24:02 -03:00
|
|
|
# cpack settings
|
|
|
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A universal autopilot system for the ArduPilotMega board.")
|
|
|
|
set(CPACK_PACKAGE_VENDOR "DIYDRONES")
|
|
|
|
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "james.goppert@gmail.com")
|
|
|
|
set(CPACK_PACKAGE_CONTACT "james.goppert@gmail.com")
|
|
|
|
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.txt")
|
|
|
|
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING.txt")
|
|
|
|
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.txt")
|
|
|
|
set(CPACK_PACKAGE_VERSION_MAJOR "${APPLICATION_VERSION_MAJOR}")
|
|
|
|
set(CPACK_PACKAGE_VERSION_MINOR "${APPLICATION_VERSION_MINOR}")
|
|
|
|
set(CPACK_PACKAGE_VERSION_PATCH "${APPLICATION_VERSION_PATCH}")
|
|
|
|
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}")
|
|
|
|
set(CPACK_SET_DESTDIR TRUE)
|
|
|
|
set(CPACK_SOURCE_IGNORE_FILES ${CPACK_SOURCE_IGNORE_FILES}
|
|
|
|
/.git/;/build/;~$;.*\\\\.bin$;.*\\\\.swp$)
|
|
|
|
set(CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
|
|
|
set(CPACK_SOURCE_GENERATOR "ZIP")
|
|
|
|
set(CPACK_GENERATOR "ZIP")
|
|
|
|
set(CPACK_PACKAGE_NAME "${APPLICATION_NAME}_${BOARD}")
|
|
|
|
include(CPack)
|
2011-09-30 17:55:27 -03:00
|
|
|
|
|
|
|
find_package(Arduino 22 REQUIRED)
|
|
|
|
|
|
|
|
# determine board being used
|
|
|
|
if (NOT DEFINED BOARD)
|
|
|
|
message(STATUS "board not defined, assuming mega, use cmake -DBOARD=mega2560 , etc. to specify")
|
|
|
|
set(BOARD "mega")
|
|
|
|
endif()
|
|
|
|
message(STATUS "Board configured as: ${BOARD}")
|
|
|
|
|
2011-10-30 03:21:32 -03:00
|
|
|
# add a sketch
|
|
|
|
macro(add_sketch SKETCH_NAME BOARD PORT)
|
2011-10-30 15:47:30 -03:00
|
|
|
|
2011-10-30 03:21:32 -03:00
|
|
|
message(STATUS "Generating sketch ${SKETCH_NAME}")
|
2011-10-30 15:47:30 -03:00
|
|
|
|
|
|
|
# files
|
2011-10-30 03:21:32 -03:00
|
|
|
set(SKETCH_CPP ${CMAKE_CURRENT_BINARY_DIR}/${SKETCH_NAME}/${SKETCH_NAME}.cpp)
|
2011-10-30 15:47:30 -03:00
|
|
|
set(SKETCH_PDE ${CMAKE_CURRENT_SOURCE_DIR}/${SKETCH_NAME}/${SKETCH_NAME}.pde)
|
2011-11-19 02:08:17 -04:00
|
|
|
#message(STATUS "SKETCH_PDE:\n${SKETCH_PDE}")
|
|
|
|
#message(STATUS "SKETCH_CPP:\n${SKETCH_CPP}")
|
2011-10-30 15:47:30 -03:00
|
|
|
|
|
|
|
# settings
|
2011-10-30 03:21:32 -03:00
|
|
|
set(${SKETCH_NAME}_BOARD ${BOARD})
|
|
|
|
set(${SKETCH_NAME}_PORT ${PORT})
|
|
|
|
set(${SKETCH_NAME}_SRCS ${SKETCH_CPP})
|
|
|
|
set(${SKETCH_NAME}_LIBS m c)
|
2011-10-30 15:47:30 -03:00
|
|
|
|
|
|
|
# find pde files
|
2011-10-30 03:21:32 -03:00
|
|
|
file(GLOB PDE_SOURCES ${SKETCH_NAME}/*.pde)
|
2011-10-30 18:34:54 -03:00
|
|
|
|
|
|
|
# find the head of the main pde
|
2011-10-30 15:47:30 -03:00
|
|
|
file(WRITE ${SKETCH_CPP} "// automatically generated by arduino-cmake\n")
|
2011-10-30 18:34:54 -03:00
|
|
|
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)
|
2011-11-19 02:08:17 -04:00
|
|
|
#message(STATUS "FILE_HEAD:\n${FILE_HEAD}")
|
2011-10-30 18:34:54 -03:00
|
|
|
|
|
|
|
# find the body of the main pde
|
|
|
|
math(EXPR BODY_LENGTH "${FILE_LENGTH}-${POS3}-1")
|
|
|
|
string(SUBSTRING "${FILE}" "${POS3}+1" "${BODY_LENGTH}" FILE_BODY)
|
2011-11-19 02:08:17 -04:00
|
|
|
#message(STATUS "BODY:\n${FILE_BODY}")
|
2011-10-30 18:34:54 -03:00
|
|
|
|
|
|
|
# write the file head
|
|
|
|
file(APPEND ${SKETCH_CPP} "${FILE_HEAD}")
|
|
|
|
file(APPEND ${SKETCH_CPP} "\n#include \"WProgram.h\"\n")
|
2011-10-30 15:47:30 -03:00
|
|
|
|
|
|
|
# write prototypes
|
2011-10-30 03:21:32 -03:00
|
|
|
foreach(PDE ${PDE_SOURCES})
|
2011-11-19 02:08:17 -04:00
|
|
|
#message(STATUS "pde: ${PDE}")
|
2011-10-30 15:47:30 -03:00
|
|
|
file(READ ${PDE} FILE)
|
2011-10-31 14:18:48 -03:00
|
|
|
string(REGEX MATCHALL "[\n]([a-zA-Z]+[ ])*[_a-zA-Z0-9]+([ ]*[\n][\t]*|[ ])[_a-zA-Z0-9]+[ ]?[\n]?[\t]*[ ]*[(]([\t]*[ ]*[*]?[ ]?[a-zA-Z0-9_][,]?[ ]*[\n]?)*[)]" PROTOTYPES ${FILE})
|
2011-10-30 15:47:30 -03:00
|
|
|
foreach(PROTOTYPE ${PROTOTYPES})
|
2011-11-19 02:08:17 -04:00
|
|
|
#message(STATUS "\tprototype: ${PROTOTYPE};")
|
2011-10-31 14:18:48 -03:00
|
|
|
file(APPEND ${SKETCH_CPP} "${PROTOTYPE};")
|
2011-10-30 15:47:30 -03:00
|
|
|
endforeach()
|
|
|
|
endforeach()
|
2011-10-30 18:34:54 -03:00
|
|
|
|
2011-10-30 15:47:30 -03:00
|
|
|
|
|
|
|
# write source
|
2011-10-31 14:18:48 -03:00
|
|
|
file(APPEND ${SKETCH_CPP} "\n${FILE_BODY}")
|
2011-10-30 18:34:54 -03:00
|
|
|
list(REMOVE_ITEM PDE_SOURCES ${SKETCH_PDE})
|
|
|
|
list(SORT PDE_SOURCES)
|
2011-10-30 15:47:30 -03:00
|
|
|
foreach (PDE ${PDE_SOURCES})
|
2011-10-30 03:21:32 -03:00
|
|
|
file(READ ${PDE} FILE)
|
2011-10-30 18:34:54 -03:00
|
|
|
file(APPEND ${SKETCH_CPP} "${FILE}")
|
2011-10-30 03:21:32 -03:00
|
|
|
endforeach()
|
2011-10-30 15:47:30 -03:00
|
|
|
|
|
|
|
# generate firmware
|
2011-10-30 18:34:54 -03:00
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${SKETCH_NAME})
|
2011-10-30 03:21:32 -03:00
|
|
|
generate_arduino_firmware(${SKETCH_NAME})
|
|
|
|
set_target_properties(${SKETCH_NAME} PROPERTIES LINKER_LANGUAGE CXX)
|
2011-10-30 15:47:30 -03:00
|
|
|
|
|
|
|
# install settings
|
2011-09-30 21:24:02 -03:00
|
|
|
install(FILES
|
2011-10-30 03:21:32 -03:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${SKETCH_NAME}.hex
|
2011-09-30 21:24:02 -03:00
|
|
|
DESTINATION bin
|
2011-09-30 18:32:51 -03:00
|
|
|
)
|
2011-09-30 21:24:02 -03:00
|
|
|
endmacro()
|
2011-09-30 18:32:51 -03:00
|
|
|
|
2011-09-30 21:24:02 -03:00
|
|
|
# projects
|
2011-10-30 03:21:32 -03:00
|
|
|
add_sketch(apo ${BOARD} ${PORT})
|
|
|
|
add_sketch(ArduRover ${BOARD} ${PORT})
|
|
|
|
add_sketch(ArduBoat ${BOARD} ${PORT})
|
2011-11-28 01:53:30 -04:00
|
|
|
#add_sketch(ArduPlane ${BOARD} ${PORT})
|
2011-10-30 03:21:32 -03:00
|
|
|
#add_sketch(ArduCopter ${BOARD} ${PORT})
|