mirror of
https://github.com/eclipse-threadx/threadx.git
synced 2026-10-06 06:59:08 +08:00
The project guidelines ask for CMake and Ninja, but only 15 of the 59 gnu port directories had a CMakeLists.txt. None of the 27 AArch64 ports had one, so the architecture whose examples were repaired over the last few changes still could not be built the way the project says to build it, and nothing in CI could compile it. Add a CMakeLists.txt to the 44 that lacked one. Three of them are templates in ports_arch, because 34 of the 44 are generated: the ARMv7-A and AArch64 source lists are uniform within each family, so one template per family serves every core in it and update.sh distributes it. The other 10 ports have no generator and get their own file. Add the toolchain files those ports select, following the shape of cmake/cortex_a9.cmake. AArch64 needs a base file of its own rather than a variant of arm-none-eabi.cmake: it has no -marm or -mthumb to choose between and no -mfloat-abi, and aarch64-none-elf-gcc rejects -mlong-calls outright, so that flag cannot be carried across. The tools are named without a path, unlike cmake/cortex_r52.cmake which pins one, because pinning 30 files to a single machine's directory layout is the problem the previous change removed from the launch configurations. Three toolchain files cover ports that already had a CMakeLists.txt but no way to select it: the Armv8-M mainline gnu ports, cortex_m33, cortex_m55 and cortex_m85. Without cmake/<arch>.cmake the documented invocation cannot reach them. The top level needed one fix. It derives the SMP port directory as <arch>_smp, but ports_smp/linux and ports_smp/win64 predate that convention and carry no suffix, so those two could never be configured. Fall back to the bare name when the suffixed directory is absent. The check only fires when the suffixed directory does not exist, so no port that already resolved changes behaviour, and ports_smp/win64's existing CMakeLists.txt becomes reachable too. Verified by configuring and building every one: 53 of 53 static libraries build with cmake -G Ninja, using Arm GNU Toolchain 14.3.Rel1 for both arm-none-eabi and aarch64-none-elf. That covers the 44 new ports plus the 9 that already worked, and includes ports_smp/linux, which failed before the fallback. scripts/check_ports.sh passes, so the three templates and their 34 generated copies agree. Six gnu ports are still outside the CMake build, all for want of a compiler rather than a CMakeLists.txt: rxv1, rxv2 and rxv3 need the Renesas RX GNU toolchain and mips32_interaptiv_smp needs a MIPS one, neither of which is available here, so writing toolchain files for them would mean shipping untested guesses. risc-v32 and risc-v64 already build through their own differently named toolchain files. Assisted-by: Claude Code (Opus 5) <noreply@anthropic.com>
123 lines
4.6 KiB
CMake
123 lines
4.6 KiB
CMake
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
|
|
|
# Declare the project with C only first so that CMake loads the toolchain file,
|
|
# which sets THREADX_ARCH and THREADX_TOOLCHAIN as normal variables. Checking
|
|
# those variables before project() would always fail because the toolchain is
|
|
# not sourced until the first project() call.
|
|
project(threadx LANGUAGES C)
|
|
|
|
if(NOT DEFINED THREADX_ARCH)
|
|
message(FATAL_ERROR "Error: THREADX_ARCH not defined")
|
|
endif()
|
|
if(NOT DEFINED THREADX_TOOLCHAIN)
|
|
message(FATAL_ERROR "Error: THREADX_TOOLCHAIN not defined")
|
|
endif()
|
|
|
|
# The Windows simulation ports do not use assembly. All other ports require
|
|
# it. enable_language() is called here rather than in project() above so that
|
|
# the ASM toolchain is only activated when we know the target actually needs it.
|
|
# Note: CMAKE_TRY_COMPILE_TARGET_TYPE is already set to STATIC_LIBRARY by
|
|
# every toolchain file in cmake/, so it does not need to be repeated here.
|
|
if(NOT ((THREADX_ARCH STREQUAL "win32") OR (THREADX_ARCH STREQUAL "win64")))
|
|
enable_language(ASM)
|
|
endif()
|
|
|
|
option(THREADX_SMP "Build ThreadX SMP version" OFF)
|
|
|
|
# Enable testing at the top level so that tests registered by ports and
|
|
# example builds further down the tree are discoverable with ctest from the
|
|
# build root. Without this, add_test() in a subdirectory still generates a
|
|
# CTestTestfile.cmake there, but the root does not reference it and
|
|
# "ctest --test-dir <build>" reports no tests at all.
|
|
enable_testing()
|
|
|
|
if(THREADX_SMP)
|
|
set(TX_PORT_DIR "ports_smp")
|
|
set(TX_COMMON_DIR "common_smp")
|
|
set(TX_ARCH_DIR "${THREADX_ARCH}_smp")
|
|
# Most SMP ports are named <arch>_smp, but ports_smp/linux and
|
|
# ports_smp/win64 predate that convention and carry no suffix. Fall back to
|
|
# the bare name for them. The check only fires when the suffixed directory
|
|
# is absent, so no port that already resolves changes.
|
|
if(NOT IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/${TX_PORT_DIR}/${TX_ARCH_DIR}")
|
|
set(TX_ARCH_DIR "${THREADX_ARCH}")
|
|
endif()
|
|
message(STATUS "Building ThreadX SMP version")
|
|
else()
|
|
set(TX_PORT_DIR "ports")
|
|
set(TX_COMMON_DIR "common")
|
|
set(TX_ARCH_DIR "${THREADX_ARCH}")
|
|
message(STATUS "Building standard ThreadX version")
|
|
endif()
|
|
|
|
message(STATUS "THREADX_ARCH: ${THREADX_ARCH}")
|
|
message(STATUS "THREADX_TOOLCHAIN: ${THREADX_TOOLCHAIN}")
|
|
|
|
# Define our target library and an alias for consumers
|
|
add_library(${PROJECT_NAME})
|
|
add_library("azrtos::${PROJECT_NAME}" ALIAS ${PROJECT_NAME})
|
|
|
|
# A place for generated/copied include files (no need to change)
|
|
set(CUSTOM_INC_DIR ${CMAKE_CURRENT_BINARY_DIR}/custom_inc)
|
|
|
|
# Pick up the port specific variables and apply them
|
|
if(DEFINED THREADX_CUSTOM_PORT)
|
|
add_subdirectory(${THREADX_CUSTOM_PORT} threadx_port)
|
|
else()
|
|
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${TX_PORT_DIR}/${TX_ARCH_DIR}/${THREADX_TOOLCHAIN})
|
|
endif()
|
|
|
|
# Pick up the common stuff
|
|
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${TX_COMMON_DIR})
|
|
|
|
# Define the FreeRTOS adaptation layer
|
|
add_library(freertos-threadx EXCLUDE_FROM_ALL)
|
|
target_include_directories(freertos-threadx
|
|
PUBLIC
|
|
${CMAKE_CURRENT_LIST_DIR}/utility/rtos_compatibility_layers/FreeRTOS
|
|
)
|
|
target_sources(freertos-threadx
|
|
PRIVATE
|
|
${CMAKE_CURRENT_LIST_DIR}/utility/rtos_compatibility_layers/FreeRTOS/tx_freertos.c
|
|
)
|
|
target_link_libraries(freertos-threadx PUBLIC threadx)
|
|
|
|
# If the user provided an override, copy it to the custom directory
|
|
if (NOT TX_USER_FILE)
|
|
message(STATUS "Using default tx_user.h file")
|
|
set(TX_USER_FILE ${CMAKE_CURRENT_LIST_DIR}/${TX_COMMON_DIR}/inc/tx_user_sample.h)
|
|
else()
|
|
message(STATUS "Using custom tx_user.h file from ${TX_USER_FILE}")
|
|
endif()
|
|
configure_file(${TX_USER_FILE} ${CUSTOM_INC_DIR}/tx_user.h COPYONLY)
|
|
target_include_directories(${PROJECT_NAME}
|
|
PUBLIC
|
|
${CUSTOM_INC_DIR}
|
|
)
|
|
target_compile_definitions(${PROJECT_NAME} PUBLIC "TX_INCLUDE_USER_DEFINE_FILE" )
|
|
if(THREADX_SMP)
|
|
target_compile_definitions(${PROJECT_NAME} PUBLIC "TX_MPCORE" )
|
|
endif()
|
|
|
|
# Optional: build for S-mode (Supervisor mode) instead of M-mode (Machine mode).
|
|
# Required when running after OpenSBI, e.g. booted from U-Boot.
|
|
option(TX_RISCV_SMODE "Use S-mode CSRs instead of M-mode for RISC-V targets" OFF)
|
|
if(TX_RISCV_SMODE)
|
|
message(STATUS "RISC-V S-mode enabled (TX_RISCV_SMODE)")
|
|
target_compile_definitions(${PROJECT_NAME} PUBLIC "TX_RISCV_SMODE")
|
|
endif()
|
|
|
|
# Enable a build target that produces a ZIP file of all sources
|
|
set(CPACK_SOURCE_GENERATOR "ZIP")
|
|
set(CPACK_SOURCE_IGNORE_FILES
|
|
\\.git/
|
|
\\.github/
|
|
_build/
|
|
\\.git
|
|
\\.gitattributes
|
|
\\.gitignore
|
|
".*~$"
|
|
)
|
|
set(CPACK_VERBATIM_VARIABLES YES)
|
|
include(CPack)
|