Browse Source

[BUILD] Use -Os for F3, -O2 for F4/F7 with cmake

master
Alberto García Hierro 4 years ago
parent
commit
fb9f61a583
  1. 4
      CMakeLists.txt
  2. 10
      cmake/arm-none-eabi.cmake
  3. 5
      cmake/stm32f3.cmake
  4. 4
      cmake/stm32f4.cmake
  5. 4
      cmake/stm32f7.cmake

4
CMakeLists.txt

@ -9,6 +9,10 @@ endif()
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${TOOLCHAIN}.cmake")
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(IS_RELEASE_BUILD ON)
endif()
project(INAV VERSION 2.5.0)
ENABLE_LANGUAGE(ASM)

10
cmake/arm-none-eabi.cmake

@ -33,7 +33,7 @@ set(CMAKE_CXX_COMPILER "${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-g++${TOOL_EXECUTA
set(CMAKE_OBJCOPY "${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-objcopy${TOOL_EXECUTABLE_SUFFIX}" CACHE INTERNAL "objcopy tool")
set(CMAKE_OBJDUMP "${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-objdump${TOOL_EXECUTABLE_SUFFIX}" CACHE INTERNAL "objdump tool")
set(CMAKE_SIZE "${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-size${TOOL_EXECUTABLE_SUFFIX}" CACHE INTERNAL "size tool")
set(CMAKE_DEBUGER "${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-gdb${TOOL_EXECUTABLE_SUFFIX}" CACHE INTERNAL "debuger")
set(CMAKE_DEBUGGER "${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-gdb${TOOL_EXECUTABLE_SUFFIX}" CACHE INTERNAL "debugger")
set(CMAKE_CPPFILT "${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-c++filt${TOOL_EXECUTABLE_SUFFIX}" CACHE INTERNAL "c++filt")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
@ -43,11 +43,15 @@ set(CMAKE_EXECUTABLE_SUFFIX ".elf")
if(NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo)
endif()
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Build Type" FORCE)
if(CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Build Type" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES})
set(arm_none_eabi_debug "-Og -g")
set(arm_none_eabi_release "-Os -DNDEBUG -flto -fuse-linker-plugin")
# We set -Os or -O2 depending on the MCU family
set(arm_none_eabi_release "-DNDEBUG -flto -fuse-linker-plugin")
set(arm_none_eabi_relwithdebinfo "-ggdb3 ${arm_none_eabi_release}")
SET(CMAKE_C_FLAGS_DEBUG ${arm_none_eabi_debug} CACHE INTERNAL "c compiler flags debug")

5
cmake/stm32f3.cmake

@ -61,6 +61,11 @@ set(STM32F303_DEFINITIONS
function(target_stm32f3xx name startup ldscript)
# F3 targets don't support MSC
target_stm32(${name} ${startup} ${ldscript} DISABLE_MSC ${ARGN})
# F3 targets don't use -O2 to save size
if (IS_RELEASE_BUILD)
target_compile_options(${name} PRIVATE "-Os")
target_link_options(${name} PRIVATE "-Os")
endif()
target_sources(${name} PRIVATE ${STM32_STDPERIPH_SRC} ${STM32F3_STDPERIPH_SRC} ${STM32F3_SRC})
target_compile_options(${name} PRIVATE ${CORTEX_M4F_COMMON_OPTIONS} ${CORTEX_M4F_COMPILE_OPTIONS})
target_include_directories(${name} PRIVATE ${STM32F3_INCLUDE_DIRS})

4
cmake/stm32f4.cmake

@ -77,6 +77,10 @@ set(STM32F4_DEFINITIONS
function(target_stm32f4xx name startup ldscript)
target_stm32(${name} ${startup} ${ldscript} ${ARGN})
if (IS_RELEASE_BUILD)
target_compile_options(${name} PRIVATE "-O2")
target_link_options(${name} PRIVATE "-O2")
endif()
target_sources(${name} PRIVATE ${STM32_STDPERIPH_SRC} ${STM32F4_SRC})
target_compile_options(${name} PRIVATE ${CORTEX_M4F_COMMON_OPTIONS} ${CORTEX_M4F_COMPILE_OPTIONS})
target_include_directories(${name} PRIVATE ${STM32F4_INCLUDE_DIRS})

4
cmake/stm32f7.cmake

@ -84,6 +84,10 @@ set(STM32F7_DEFINITIONS
function(target_stm32f7xx name startup ldscript)
target_stm32(${name} ${startup} ${ldscript} ${ARGN})
if (IS_RELEASE_BUILD)
target_compile_options(${name} PRIVATE "-O2")
target_link_options(${name} PRIVATE "-O2")
endif()
target_sources(${name} PRIVATE ${STM32F7_HAL_SRC} ${STM32F7_SRC})
target_compile_options(${name} PRIVATE ${CORTEX_M7_COMMON_OPTIONS} ${CORTEX_M7_COMPILE_OPTIONS})
target_include_directories(${name} PRIVATE ${STM32F7_INCLUDE_DIRS})

Loading…
Cancel
Save