I am cross-compiling for an ARM Cortex-M using CMake for the configuration of the project.
I've been so far successful in setting up the project and the executable is being generated. However, to flash the board I need an ".hex". file.
I've followed the Nordic nRF5SDK examples for gcc to get some clues about the compiling and linking stages and pass them to the CMake routines.
However, I cannot generate any ".out" file to proper extract the ".hex" file. I've played with the compiling flags and linker flags but without success.
I've setted up the init flags in the toolchain file as well as the compilers, the hex is being generated with a custom command:
(...)
add_executable(main main.c)
target_link_libraries(main sdk_lib)
add_custom_command(
TARGET
main
POST_BUILD
COMMAND
${ARM_OBJCOPY} -O ihex ${CMAKE_CURRENT_BINARY_DIR}/main${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_SOURCE_DIR}/main.hex
)
(...)
The issue is that I am using the binary file for extracting the hex, instead of a proper ".out" file.
How can I generate it without using another custom command parallel to the main build?
P.S.: Here is the current state of the project https://github.com/NunoRVicente/cmake-arm-toolchain