Created
October 31, 2017 20:38
-
-
Save nullsauce/3d146b322231aaf00546fcdd84faaee3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.2) | |
project(test_image) | |
set(TARGET_PREFIX "arm-none-eabi-") | |
set(CPU "cortex-m3") | |
set(CMAKE_C_FLAGS "\ | |
-c \ | |
-g \ | |
-O3 \ | |
-std=c99 \ | |
-ffreestanding \ | |
-mcpu=${CPU} \ | |
-mthumb \ | |
-mfloat-abi=soft \ | |
-nostdlib \ | |
") | |
set(LD_FLAGS "\ | |
-nostdlib \ | |
-nodefaultlibs \ | |
-nostartfiles \ | |
-T ${CMAKE_SOURCE_DIR}/linker.txt \ | |
") | |
set(SOURCES | |
main.c | |
io.c | |
string.c | |
) | |
set(ASM_SOURCES | |
boot.s | |
) | |
set_property(SOURCE ${ASM_SOURCES} PROPERTY LANGUAGE C) | |
set(CMAKE_C_COMPILER "${TARGET_PREFIX}gcc") | |
set(CMAKE_LINKER "${TARGET_PREFIX}ld") | |
set(CMAKE_ASM_COMPILER "${TARGET_PREFIX}as") | |
set(CMAKE_C_LINK_FLAGS "${LD_FLAGS}") | |
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET>") | |
set(CROSS_OBJCOPY "${TARGET_PREFIX}objcopy") | |
set(CROSS_OBJDUMP "${TARGET_PREFIX}objdump") | |
include_directories(../sdk/include) | |
add_executable(program_elf ${SOURCES} ${ASM_SOURCES}) | |
set_target_properties(program_elf PROPERTIES PREFIX "") | |
add_custom_target(program_bin ALL | |
COMMAND ${CROSS_OBJCOPY} -O binary $<TARGET_FILE:program_elf> program.bin | |
DEPENDS program_elf | |
VERBATIM | |
) | |
set_target_properties(program_bin PROPERTIES OUTFILE "program.bin") | |
add_custom_target(program_h ALL | |
COMMAND xxd -i $<TARGET_PROPERTY:program_bin,OUTFILE> > program.h | |
DEPENDS program_elf | |
VERBATIM | |
) | |
set_target_properties(program_h PROPERTIES OUTFILE "program.h") | |
add_custom_target(program_disam ALL | |
COMMAND ${CROSS_OBJDUMP} -b binary -Mforce-thumb -marm -D --prefix-addresses $<TARGET_PROPERTY:program_bin,OUTFILE> > program.txt | |
COMMAND ${CROSS_OBJDUMP} -d -S $<TARGET_FILE:program_elf> > program.full.txt | |
DEPENDS program_bin | |
VERBATIM | |
) | |
set_target_properties(program_disam PROPERTIES OUTFILE "program.txt") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment