Skip to content

Commit

Permalink
Reorganized cmake, mostly
Browse files Browse the repository at this point in the history
  • Loading branch information
bsutherland333 committed Dec 5, 2023
1 parent 509f038 commit 4691e6f
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
.vscode/
*.o
*.html
/boards/*/build/
/build/
/test/build/
/site/
*.idea*
Expand Down
86 changes: 86 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()

84 changes: 2 additions & 82 deletions boards/varmint/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -107,20 +41,6 @@ add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-x$<SEMICOLON>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 ###

Expand Down

0 comments on commit 4691e6f

Please sign in to comment.