93 lines
3.3 KiB
CMake
93 lines
3.3 KiB
CMake
cmake_minimum_required(VERSION 3.21)
|
|
###############################################################################
|
|
# we are building embedded, so no shared libs
|
|
set(BUILD_SHARED_LIBS OFF)
|
|
include(${CMAKE_TOOLCHAIN_FILE})
|
|
###############################################################################
|
|
# Adds picolibc
|
|
#set(CMAKE_SYSTEM_PROCESSOR riscv)
|
|
add_subdirectory(third-party/picolibc)
|
|
#add_subdirectory(picolibc/semihost)
|
|
target_link_libraries(c PUBLIC gcc)
|
|
###############################################################################
|
|
# Adds threadx
|
|
set(THREADX_CUSTOM_PORT ${CMAKE_CURRENT_LIST_DIR}/port/threadx)
|
|
add_subdirectory(third-party/threadx)
|
|
target_link_libraries(threadx PUBLIC c)
|
|
# Adds netxduo
|
|
set(NETXDUO_CUSTOM_PORT ${CMAKE_CURRENT_LIST_DIR}/port/threadx)
|
|
set(NXD_ENABLE_FILE_SERVERS OFF)
|
|
set(NX_USER_FILE ${CMAKE_CURRENT_LIST_DIR}/port/threadx/inc/nx_user.h)
|
|
add_subdirectory(third-party/netxduo)
|
|
target_link_libraries(netxduo PUBLIC c)
|
|
###############################################################################
|
|
project(threadx_demo C ASM)
|
|
option(NX_DEBUG "compile netxduo debug output in" OFF)
|
|
set(TARGET_MEM "ram" CACHE STRING "memory map to use" )
|
|
set(CMAKE_EXECUTABLE_SUFFIX_C ".elf")
|
|
|
|
function(setup_target TARGET)
|
|
set(options)
|
|
set(oneValueArgs) # none for now
|
|
set(multiValueArgs LIBRARIES SOURCES)
|
|
cmake_parse_arguments(ST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
if(ST_UNPARSED_ARGUMENTS)
|
|
message(FATAL_ERROR "setup_target(${target} ...): unknown args: ${ST_UNPARSED_ARGUMENTS}")
|
|
endif()
|
|
|
|
add_executable(${TARGET})
|
|
target_sources(${TARGET} PRIVATE
|
|
port/picolibc/port.c
|
|
port/moonlight/bootup.c
|
|
port/moonlight/board.c
|
|
port/moonlight/trap_non_vectored.c
|
|
port/moonlight/exception.c
|
|
port/moonlight/vector_table.c
|
|
port/moonlight/tx_timer_interrupt.c
|
|
)
|
|
if("netxduo" IN_LIST ST_LIBRARIES)
|
|
target_sources(${TARGET} PRIVATE port/moonlight/mnrs_network_driver.c)
|
|
endif()
|
|
|
|
if(ST_SOURCES)
|
|
target_sources(${TARGET} PRIVATE ${ST_SOURCES})
|
|
endif()
|
|
|
|
target_include_directories(${TARGET} PRIVATE port/moonlight src)
|
|
target_compile_options(${TARGET} PRIVATE
|
|
-ffreestanding
|
|
-fno-builtin
|
|
-fdata-sections
|
|
-ffunction-sections
|
|
)
|
|
if(NX_DEBUG)
|
|
target_compile_definitions(${TARGET} PRIVATE NX_DEBUG)
|
|
endif()
|
|
target_link_directories(${TARGET} PRIVATE src) # needed for linker script includes
|
|
target_link_options(${TARGET} PRIVATE
|
|
-nostartfiles
|
|
-nostdlib
|
|
-T ${CMAKE_SOURCE_DIR}/src/${TARGET_MEM}.lds
|
|
-Wl,--gc-sections
|
|
-Wl,-Map=${CMAKE_BINARY_DIR}/${TARGET}.map
|
|
)
|
|
if(ST_LIBRARIES)
|
|
target_link_libraries(${TARGET} PRIVATE ${ST_LIBRARIES})
|
|
endif()
|
|
target_link_libraries(${TARGET} PRIVATE threadx)
|
|
|
|
add_custom_command(TARGET ${TARGET} POST_BUILD
|
|
COMMAND ${OBJCOPY} -O ihex $<TARGET_FILE:${TARGET}> ${CMAKE_BINARY_DIR}/${TARGET}.hex
|
|
COMMAND ${OBJCOPY} -O binary $<TARGET_FILE:${TARGET}> ${CMAKE_BINARY_DIR}/${TARGET}.bin
|
|
COMMAND ${SIZE} $<TARGET_FILE:${TARGET}>
|
|
COMMAND ${OBJDUMP} -S $<TARGET_FILE:${TARGET}> > ${TARGET}.dis
|
|
COMMENT "Creating collateral for ${TARGET}"
|
|
)
|
|
endfunction()
|
|
|
|
setup_target(thread_demo SOURCES src/thread_demo/main.c)
|
|
setup_target(tcp_demo
|
|
LIBRARIES netxduo
|
|
SOURCES src/tcp_demo/main.c
|
|
)
|