2015-11-20 1 views
2

J'utilise CLion 1.2 pour créer un projet C intégré pour une cible STM32. La compilation croisée utilisant les outils GNU ARM fonctionne bien, cependant, je voudrais lancer arm-none-eabi-size après que le fichier exécutable ait été construit, et que la sortie de cette commande soit imprimée dans la fenêtre de sortie de compilation.Commande de sortie CMake post-construction avec impression

J'ai regardé la macro add_custom_command de manière approfondie, mais je n'ai pas l'intention de générer un fichier de sortie, ce que la macro semble faire.

est inférieure à la CMakeLists.txt que j'utilise dans le projet:

cmake_minimum_required(VERSION 3.3) 
include(CMakeForceCompiler) 
project(rtos_clion) 
# ------------------------------------------------------------------- 

set(CMAKE_SYSTEM_PROCESSOR cortex-m0) 
SET(CMAKE_SYSTEM_NAME Generic) 

# Target Environment 
SET(CMAKE_FIND_ROOT_PATH "C:/Program Files (x86)/GNU Tools ARM Embedded/4.9 2015q2") 

# Cross compiler 
CMAKE_FORCE_C_COMPILER(arm-none-eabi-gcc GNU) 
CMAKE_FORCE_CXX_COMPILER(arm-none-eabi-g++ GNU) 

# Executable type 
set(CMAKE_EXECUTABLE_SUFFIX ".elf") 

# Compiler flags 
set(ARM_FLAGS "-mcpu=cortex-m0 -mthumb -Os") 

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARM_FLAGS} -std=gnu++11 -fabi-version=0 -fno-exceptions -fno-rtti -fno-use-cxa-atexit -fno-threadsafe-statics -ffunction-sections -g") 
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11 ${ARM_FLAGS} -ffunction-sections -fmessage-length=0 -fsigned-char -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g") 
set(CMAKE_EXE_LINKER_FLAGS "${ARM_FLAGS} -g -Wl,--library-path=\"${PROJECT_SOURCE_DIR}\" -T mem.ld -T libs.ld -T sections.ld -Xlinker --gc-sections -Wl,-Map=${PROJECT_NAME}.map --specs=nano.specs") 

set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <LINK_FLAGS> -o <TARGET> <OBJECTS>") 
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <LINK_FLAGS> -o <TARGET> <OBJECTS>") 
# ------------------------------------------------------------------- 

# Global definitions 
add_definitions(-DDEBUG -DUSE_FULL_ASSERT -DSTM32F051x8 -DHSE_VALUE=8000000) 

include_directories(
    # My include directories 
) 

set(SOURCE_FILES 
    # My source files 
) 

add_executable(${PROJECT_NAME} ${SOURCE_FILES}) 

# search for programs in the build host directories 
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 

C'est ce que arm-none-eabi-size imprime lorsqu'il est exécuté dans une console:

$arm-none-eabi-size --format=berkeley "rtos_clion.elf" 

text data  bss  dec  hex filename 
32840  308 7796 40944 9ff0 rtos_clion.elf 

Comment aurais-je cette course et ont cette sortie affichée dans la fenêtre de construction?

Merci!

Répondre

5

Il suffit d'utiliser TARGET flux de add_custom_command:

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 
    COMMAND arm-none-eabi-size --format=berkeley "rtos_clion.elf") 

La commande sera exécutée après exécutable a été (re) construit.

+0

C'était beaucoup plus facile que je pensais. Merci! – WoodyWoodsta

0

Même le fichier .elf peut être pris d'une variable:

set_target_properties(${TARGET} PROPERTIES SUFFIX ".elf") 
add_custom_command(TARGET ${MAIN_TARGET} POST_BUILD 
     COMMAND arm-none-eabi-size --format=berkeley --totals "$<TARGET_FILE:${TARGET}>" 
     COMMENT "Invoking: Cross ARM GNU Print Size")