From 4691e6fc959eab79ba47d646d4f9080193167d24 Mon Sep 17 00:00:00 2001 From: Brandon Sutherland Date: Tue, 5 Dec 2023 12:47:29 -0700 Subject: [PATCH] Reorganized cmake, mostly --- .gitignore | 2 +- CMakeLists.txt | 86 +++++++++++++++++++++++++++++++++++ boards/varmint/CMakeLists.txt | 84 +--------------------------------- 3 files changed, 89 insertions(+), 83 deletions(-) create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore index 2c221aa2..0b123f76 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ .vscode/ *.o *.html -/boards/*/build/ +/build/ /test/build/ /site/ *.idea* diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..aae8e0a3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,86 @@ +### project settings ### + +set(CMAKE_SYSTEM_NAME Generic) +cmake_minimum_required(VERSION 3.8) +project(rosflight_firmware C CXX ASM) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_C_STANDARD 11) + +# specify cross-compilers and tools +set(CMAKE_C_COMPILER arm-none-eabi-gcc) +set(CMAKE_CXX_COMPILER arm-none-eabi-g++) +set(CMAKE_ASM_COMPILER arm-none-eabi-gcc) +set(CMAKE_AR arm-none-eabi-ar) +set(CMAKE_OBJCOPY arm-none-eabi-objcopy) +set(CMAKE_OBJDUMP arm-none-eabi-objdump) +set(SIZE arm-none-eabi-size) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release") +endif() + +#add_compile_options(-Wall) + + +### git ### + +# clone mavlink submodule if it is missing +set(FIRMWARE_SUBMODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/comms/mavlink/v1.0") +if(NOT EXISTS "${FIRMWARE_SUBMODULE_DIR}/.git") + message(STATUS "Firmware submodule not found at ${FIRMWARE_SUBMODULE_DIR}") + execute_process( + COMMAND git submodule update --init --recursive + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) +endif() + +# get version info +execute_process(COMMAND git rev-parse --short=8 HEAD + OUTPUT_VARIABLE GIT_VERSION_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) +execute_process(COMMAND git describe --tags --abbrev=8 --always --dirty --long + OUTPUT_VARIABLE GIT_VERSION_STRING + OUTPUT_STRIP_TRAILING_WHITESPACE + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) +if("${GIT_VERSION_STRING}" STREQUAL "") + set(GIT_VERSION_STRING "undefined") +endif() +if("${GIT_VERSION_HASH}" STREQUAL "") + set(GIT_VERSION_HASH "0") +endif() + + +### source files ### + +include_directories( + include + include/interface + + lib + + comms/mavlink + comms/mavlink/v1.0 + comms/mavlink/v1.0/common + comms/mavlink/v1.0/rosflight +) + +file(GLOB_RECURSE SOURCES + "src/*.cpp" + + "lib/turbomath/turbomath.cpp" + + "comms/mavlink/mavlink.cpp" +) + + +### select boards to compile ### + +option(BUILD_VARMINT "Build the varmint board target" ON) + +if(BUILD_VARMINT) + message(STATUS "Selecting varmint board target") + add_subdirectory(boards/varmint) +endif() + diff --git a/boards/varmint/CMakeLists.txt b/boards/varmint/CMakeLists.txt index 473ccb44..45e4e140 100644 --- a/boards/varmint/CMakeLists.txt +++ b/boards/varmint/CMakeLists.txt @@ -1,33 +1,9 @@ -### project settings ### - -set(CMAKE_SYSTEM_NAME Generic) -cmake_minimum_required(VERSION 3.8) - -# specify cross-compilers and tools -set(CMAKE_C_COMPILER arm-none-eabi-gcc) -set(CMAKE_CXX_COMPILER arm-none-eabi-g++) -set(CMAKE_ASM_COMPILER arm-none-eabi-gcc) -set(CMAKE_AR arm-none-eabi-ar) -set(CMAKE_OBJCOPY arm-none-eabi-objcopy) -set(CMAKE_OBJDUMP arm-none-eabi-objdump) -set(SIZE arm-none-eabi-size) -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) - -project(varmint C CXX ASM) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_C_STANDARD 11) - - -### include & source files ### - -set(ROSFLIGHT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/../..) +### source files ### include_directories( - # Varmint include include/board - # STM32 lib/usb_device/App lib/usb_device/Target lib/drivers/STM32H7xx_HAL_Driver/Inc @@ -36,61 +12,19 @@ include_directories( lib/drivers/CMSIS/Include lib/middleware/ST/STM32_USB_Device_Library/Core/Inc lib/middleware/ST/STM32_USB_Device_Library/Class/CDC/Inc - - # ROSflight - ${ROSFLIGHT_SOURCE_DIR}/include - ${ROSFLIGHT_SOURCE_DIR}/include/interface - ${ROSFLIGHT_SOURCE_DIR}/lib - - # MAVLink - ${ROSFLIGHT_SOURCE_DIR}/comms/mavlink - ${ROSFLIGHT_SOURCE_DIR}/comms/mavlink/v1.0 - ${ROSFLIGHT_SOURCE_DIR}/comms/mavlink/v1.0/common - ${ROSFLIGHT_SOURCE_DIR}/comms/mavlink/v1.0/rosflight ) file(GLOB_RECURSE SOURCES - # Varmint "src/*.*" - - # STM32 "lib/usb_device/*.c" "lib/drivers/*.c" "lib/middleware/*.c" - - # ROSflight - "${ROSFLIGHT_SOURCE_DIR}/src/*.cpp" - "${ROSFLIGHT_SOURCE_DIR}/lib/turbomath/turbomath.cpp" - - # MAVLink - "${ROSFLIGHT_SOURCE_DIR}/comms/mavlink/mavlink.cpp" ) -set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32H753VIHX_FLASH.ld) +set(LINKER_SCRIPT STM32H753VIHX_FLASH.ld) add_link_options(-T ${LINKER_SCRIPT}) -### git information ### - -execute_process(COMMAND git rev-parse --short=8 HEAD - OUTPUT_VARIABLE GIT_VERSION_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE - WORKING_DIRECTORY ${ROSFLIGHT_SOURCE_DIR}) - -execute_process(COMMAND git describe --tags --abbrev=8 --always --dirty --long - OUTPUT_VARIABLE GIT_VERSION_STRING - OUTPUT_STRIP_TRAILING_WHITESPACE - WORKING_DIRECTORY ${ROSFLIGHT_SOURCE_DIR}) - -if("${GIT_VERSION_STRING}" STREQUAL "") - set(GIT_VERSION_STRING "undefined") -endif() - -if("${GIT_VERSION_HASH}" STREQUAL "") - set(GIT_VERSION_HASH "0") -endif() - - ### preprocessor, compiler, linker options ### add_definitions(-DDEBUG -DUSE_HAL_DRIVER -DSTM32H753xx) @@ -107,20 +41,6 @@ add_compile_options($<$:-x$assembler-with-cpp>) add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map) add_link_options(-mcpu=cortex-m7 -mthumb -mthumb-interwork) -if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release") - message(STATUS "Maximum optimization for speed") - add_compile_options(-Ofast) -elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") - message(STATUS "Maximum optimization for speed, debug info included") - add_compile_options(-Ofast -g) -elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel") - message(STATUS "Maximum optimization for size") - add_compile_options(-Os) -else () - message(STATUS "Minimal optimization, debug info included") - add_compile_options(-Og -g) -endif () - ### build target ###