91 lines
3.3 KiB
CMake
91 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)
|
|
set(__THREAD_LOCAL_STORAGE OFF)
|
|
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 threadx_smp
|
|
add_subdirectory(port/threadx_smp)
|
|
target_link_libraries(threadx_smp 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)
|
|
if(NX_DEBUG)
|
|
target_compile_definitions(netxduo PRIVATE NX_DEBUG NX_DEBUG_PACKET NX_ENABLE_PACKET_DEBUG_INFO)
|
|
endif()
|
|
if(TX_TRACE)
|
|
target_compile_definitions(netxduo PUBLIC TX_ENABLE_EVENT_TRACE)
|
|
endif()
|
|
###############################################################################
|
|
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")
|
|
|
|
add_subdirectory(port/moonlight)
|
|
|
|
function(setup_target TARGET)
|
|
set(options)
|
|
set(oneValueArgs PLATFORM_TARGET)
|
|
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})
|
|
set_target_properties(${TARGET} PROPERTIES
|
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
)
|
|
if(ST_PLATFORM_TARGET)
|
|
target_add_moonlight_platform(${TARGET} PLATFORM_TARGET ${ST_PLATFORM_TARGET})
|
|
else()
|
|
target_add_moonlight_platform(${TARGET})
|
|
endif()
|
|
|
|
if("netxduo" IN_LIST ST_LIBRARIES)
|
|
target_add_moonlight_network_driver(${TARGET})
|
|
endif()
|
|
|
|
if(ST_SOURCES)
|
|
target_sources(${TARGET} PRIVATE ${ST_SOURCES})
|
|
endif()
|
|
|
|
if(ST_LIBRARIES)
|
|
target_link_libraries(${TARGET} PRIVATE ${ST_LIBRARIES})
|
|
endif()
|
|
|
|
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)
|
|
|
|
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}> > ${CMAKE_BINARY_DIR}/${TARGET}.dis
|
|
COMMENT "Creating collateral for ${TARGET}"
|
|
)
|
|
endfunction()
|
|
|
|
setup_target(thread_demo LIBRARIES threadx SOURCES src/thread_demo/main.c)
|
|
setup_target(tcp_demo LIBRARIES threadx netxduo SOURCES src/tcp_demo/main.c)
|
|
setup_target(smp_demo PLATFORM_TARGET moonlight_platform_common_smp LIBRARIES threadx_smp SOURCES src/thread_demo/main.c)
|