Browse Source

[BUILD] Add more compile options for stm32

WARNIGNS_AS_ERRORS, DEBUG_HARDFAULTS and SEMIHOSTING can now be
turned on/off
master
Alberto García Hierro 4 years ago
parent
commit
fd42e03f04
  1. 3
      CMakeLists.txt
  2. 28
      cmake/stm32.cmake

3
CMakeLists.txt

@ -47,6 +47,9 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(FIRMWARE_VERSION ${PROJECT_VERSION})
option(WARNINGS_AS_ERRORS "Make all warnings into errors")
message("-- toolchain: ${TOOLCHAIN}, WARNINGS_AS_ERRORS: ${WARNINGS_AS_ERRORS}")
include(settings)
include(openocd)
include(svd)

28
cmake/stm32.cmake

@ -5,6 +5,11 @@ include(stm32f7)
include(CMakeParseArguments)
option(DEBUG_HARDFAULTS "Enable debugging of hard faults via custom handler")
option(SEMIHOSTING "Enable semihosting")
message("-- DEBUG_HARDFAULTS: ${DEBUG_HARDFAULTS}, SEMIHOSTING: ${SEMIHOSTING}")
set(CMSIS_DIR "${MAIN_LIB_DIR}/main/CMSIS")
set(CMSIS_INCLUDE_DIR "${CMSIS_DIR}/Core/Include")
set(CMSIS_DSP_DIR "${MAIN_LIB_DIR}/main/CMSIS/DSP")
@ -70,12 +75,14 @@ set(STM32_INCLUDE_DIRS
set(STM32_DEFINITIONS
)
set(STM32_DEFAULT_HSE_MHZ 8)
set(STM32_LINKER_DIR "${MAIN_SRC_DIR}/target/link")
set(STM32_COMPILE_OPTIONS
-ffunction-sections
-fdata-sections
-fno-common
)
set(STM32_LIBS lnosys)
#if(SEMIHOSTING)
# set(SEMIHOSTING_DEFINITIONS "SEMIHOSTING")
# set(SEMIHOSTING_LDFLAGS
@ -170,16 +177,20 @@ function(target_stm32 name startup ldscript)
endif()
# Main .elf target
add_executable(${name} ${COMMON_SRC} ${CMSIS_DSP_SRC})
add_executable(${name})
target_sources(${name} PRIVATE "${STM32_STARTUP_DIR}/${startup}" ${COMMON_SRC} ${CMSIS_DSP_SRC})
file(GLOB target_c_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
file(GLOB target_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
target_sources(${name} PRIVATE ${target_c_sources} ${target_h_sources})
target_sources(${name} PRIVATE "${STM32_STARTUP_DIR}/${startup}")
target_link_options(${name} PRIVATE "-T${STM32_LINKER_DIR}/${ldscript}")
target_link_options(${name} PRIVATE "-Wl,-Map,$<TARGET_FILE:${name}>.map")
target_include_directories(${name} PRIVATE . ${STM32_INCLUDE_DIRS})
target_compile_options(${name} PRIVATE ${STM32_COMPILE_OPTIONS})
if(WARNINGS_AS_ERRORS)
target_compile_options(${name} PRIVATE -Werror)
endif()
target_link_libraries(${name} PRIVATE ${STM32_LINK_LIBRARIES})
target_link_options(${name} PRIVATE ${STM32_LINK_OPTIONS})
target_link_options(${name} PRIVATE "-T${STM32_LINKER_DIR}/${ldscript}")
target_link_options(${name} PRIVATE "-Wl,-Map,$<TARGET_FILE:${name}>.map")
set(target_definitions ${STM32_DEFINITIONS})
math(EXPR hse_value "${hse_mhz} * 1000000")
@ -187,6 +198,9 @@ function(target_stm32 name startup ldscript)
if(PARSED_ARGS_DEFINITIONS)
list(APPEND target_definitions ${PARSED_ARGS_DEFINITIONS})
endif()
if(DEBUG_HARDFAULTS)
list(APPEND target_definitions DEBUG_HARDFAULTS)
endif()
target_compile_definitions(${name} PRIVATE ${target_definitions})
get_stm32_target_features(features "${CMAKE_CURRENT_SOURCE_DIR}" ${name})

Loading…
Cancel
Save