diff --git a/CMakeLists.txt b/CMakeLists.txt index f052f2d15619aaa86acc46d54b318cd96a834991..27560fec23342f6951df5370f5d6cb30d6ad613a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,7 @@ include(LinkTarget) # List here your source files (.s, .c and .cpp) add_executable(main main.cpp) miosix_link_target(main) +miosix_add_program_target(main) # List here additional include directories # target_include_directories(main PRIVATE here_your_includes) diff --git a/miosix/_examples/blinking_led/CMakeLists.txt b/miosix/_examples/blinking_led/CMakeLists.txt index 33ac7057c7f90f5e126d3fbe661d850b8de05897..156d72a57167682a49bbed9cc229cc28edc54291 100644 --- a/miosix/_examples/blinking_led/CMakeLists.txt +++ b/miosix/_examples/blinking_led/CMakeLists.txt @@ -37,3 +37,4 @@ include(LinkTarget) add_executable(blinking_led simple.cpp) miosix_link_target(blinking_led) +miosix_add_program_target(blinking_led) diff --git a/miosix/_examples/processes/CMakeLists.txt b/miosix/_examples/processes/CMakeLists.txt index e2711da1fafaf61e870dd7f120e4aaeaa9119f34..df98d1563fad24173f20a7dedebead5d5592f99b 100644 --- a/miosix/_examples/processes/CMakeLists.txt +++ b/miosix/_examples/processes/CMakeLists.txt @@ -55,3 +55,4 @@ miosix_add_romfs_image( KERNEL main PROCESSES process1 process2 ) +miosix_add_program_target(image DEPENDS image) diff --git a/miosix/_tools/processes/CMakeLists.txt b/miosix/_tools/processes/CMakeLists.txt index 314d0a1d5b9ad1882bd1e0e7d6524ad3c15348ab..c0f924a3d6e69268f1b2961919f94947e3f4d3f7 100644 --- a/miosix/_tools/processes/CMakeLists.txt +++ b/miosix/_tools/processes/CMakeLists.txt @@ -54,3 +54,4 @@ miosix_add_romfs_image( KERNEL main PROCESSES hello ) +miosix_add_program_target(image DEPENDS image) diff --git a/miosix/_tools/testsuite/CMakeLists.txt b/miosix/_tools/testsuite/CMakeLists.txt index b42cda4e6fae4c6c169d0454b1b0a9b91ea4ebe0..660da8dff9397039eaa2ee20dbc70742a9bb2bd5 100644 --- a/miosix/_tools/testsuite/CMakeLists.txt +++ b/miosix/_tools/testsuite/CMakeLists.txt @@ -43,6 +43,7 @@ include(AddRomfsImage) # Kernel level program add_executable(testsuite testsuite.cpp) miosix_link_target(testsuite) +miosix_add_program_target(testsuite) # Processes # miosix_add_process(test_process test_process/main.cpp) @@ -56,3 +57,4 @@ miosix_link_target(testsuite) # KERNEL testsuite # PROCESSES test_process # test_execve test_global_dtor_ctor # ) +# miosix_add_program_target(image DEPENDS image) diff --git a/miosix/cmake/AddProgramTarget.cmake b/miosix/cmake/AddProgramTarget.cmake index b02fea466ba4ead1555ac1d8d64f72522c6fa5d0..5bb20db67ff626e9d712e7a44fb26ac5fba089f4 100644 --- a/miosix/cmake/AddProgramTarget.cmake +++ b/miosix/cmake/AddProgramTarget.cmake @@ -31,7 +31,15 @@ function(miosix_add_program_target TARGET) cmake_parse_arguments(PROGRAM "" "" "DEPENDS" ${ARGN}) if(NOT PROGRAM_DEPENDS) - set(PROGRAM_DEPENDS ${TARGET}_bin ${TARGET}_hex) + add_custom_command( + OUTPUT ${TARGET}.bin + COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${TARGET}> ${TARGET}.bin + DEPENDS ${TARGET} + COMMENT "Creating ${TARGET}.bin" + VERBATIM + ) + add_custom_target(${TARGET}_bin ALL DEPENDS ${TARGET}.bin) + set(PROGRAM_DEPENDS ${TARGET}_bin) endif() get_target_property(PROGRAM_CMDLINE miosix PROGRAM_CMDLINE) diff --git a/miosix/cmake/AddRomfsImage.cmake b/miosix/cmake/AddRomfsImage.cmake index ea83b6097734b072c6917279e8e1ca5dc4330a17..396cef547c2c65d14824c4117cd212928df0e642 100644 --- a/miosix/cmake/AddRomfsImage.cmake +++ b/miosix/cmake/AddRomfsImage.cmake @@ -62,6 +62,15 @@ function(miosix_add_romfs_image) PROCESSES ${ROMFS_PROCESSES} ) + # Create the image of the kernel + add_custom_command( + OUTPUT ${ROMFS_KERNEL}.bin + DEPENDS ${ROMFS_KERNEL} + COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${ROMFS_KERNEL}> ${ROMFS_KERNEL}.bin + COMMENT "Creating ${ROMFS_KERNEL}.bin" + VERBATIM + ) + # Create the romfs image with the given processes add_custom_command( OUTPUT ${ROMFS_IMAGE_NAME}-romfs.bin @@ -80,7 +89,4 @@ function(miosix_add_romfs_image) # Create the custom romfs target add_custom_target(${ROMFS_IMAGE_NAME} ALL DEPENDS ${PROJECT_BINARY_DIR}/${ROMFS_IMAGE_NAME}.bin) - - # And a target to flash the image - miosix_add_program_target(${ROMFS_IMAGE_NAME} DEPENDS ${ROMFS_IMAGE_NAME}) endfunction() diff --git a/miosix/cmake/LinkTarget.cmake b/miosix/cmake/LinkTarget.cmake index a9ffad8ecbb09e4e4b836ff88b843b720426e9de..fdbdbcaceb5096a2884661c4c21ec9a26ce611b1 100644 --- a/miosix/cmake/LinkTarget.cmake +++ b/miosix/cmake/LinkTarget.cmake @@ -32,8 +32,6 @@ include(AddProgramTarget) # What it does: # - Links the Miosix libraries to the target # - Tells the linker to generate the map file -# - Registers custom targets to create the hex and bin files (${TARGET}_bin and ${TARGET}_hex) -# - Registers a custom target to flash the program to the board (${TARGET}_program) function(miosix_link_target TARGET) if (NOT TARGET miosix) message(FATAL_ERROR "The board you selected is not supported") @@ -42,29 +40,10 @@ function(miosix_link_target TARGET) # Linker script and linking options are eredited from miosix libraries # Link libraries - target_link_libraries(${TARGET} PRIVATE + target_link_libraries(${TARGET} PUBLIC -Wl,--start-group miosix stdc++ c m gcc atomic -Wl,--end-group ) # Tell the linker to produce the map file target_link_options(${TARGET} PRIVATE -Wl,-Map,$<TARGET_FILE_DIR:${TARGET}>/$<TARGET_FILE_BASE_NAME:${TARGET}>.map) - - # Add a post build command to create the hex file to flash on the board - add_custom_command( - OUTPUT ${TARGET}.hex - COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:${TARGET}> ${TARGET}.hex - COMMENT "Creating ${TARGET}.hex" - VERBATIM - ) - add_custom_target(${TARGET}_hex ALL DEPENDS ${TARGET}.hex) - add_custom_command( - OUTPUT ${TARGET}.bin - COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${TARGET}> ${TARGET}.bin - COMMENT "Creating ${TARGET}.bin" - VERBATIM - ) - add_custom_target(${TARGET}_bin ALL DEPENDS ${TARGET}.bin) - - # Generate custom build command to flash the target - miosix_add_program_target(${TARGET}) endfunction()