# Copyright 2026 NXP
#
# SPDX-License-Identifier: BSD-3-Clause

# CROSS COMPILER SETTING
set(CMAKE_SYSTEM_NAME Generic)
cmake_minimum_required(VERSION 3.10.0)

if (NOT DEFINED SdkRootDirPath)
    SET(SdkRootDirPath ${CMAKE_CURRENT_LIST_DIR})
endif()

include(${CMAKE_CURRENT_LIST_DIR}/config.cmake)
include(${SdkRootDirPath}/cmake/toolchain/toolchain.cmake)

# THE VERSION NUMBER
SET (MCUXPRESSO_CMAKE_FORMAT_MAJOR_VERSION 2)
SET (MCUXPRESSO_CMAKE_FORMAT_MINOR_VERSION 0)

include(ide_overrides.cmake OPTIONAL)

if(CMAKE_SCRIPT_MODE_FILE)
  message("${MCUXPRESSO_CMAKE_FORMAT_MAJOR_VERSION}")
  return()
endif()


set(CMAKE_EXECUTABLE_LIBRARY_PREFIX)
set(CMAKE_EXECUTABLE_LIBRARY_SUFFIX)

# CURRENT DIRECTORY
set(ProjDirPath ${CMAKE_CURRENT_SOURCE_DIR})

project(MCXA2TS_FlexSPI)

enable_language(ASM)

set(MCUX_BUILD_TYPES debug)

set(MCUX_SDK_PROJECT_NAME ${BUILD_CONFIG_NAME}.elf)

include(${ProjDirPath}/flags.cmake)

add_executable(${MCUX_SDK_PROJECT_NAME}
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/system_MCXA577.c"
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/drivers/romapi/flash/fsl_flash.c"
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/drivers/fsl_clock.c"
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/drivers/fsl_reset.c"
"${ProjDirPath}/examples/_boards/frdmmcxa577/board.c"
"${ProjDirPath}/examples/_boards/frdmmcxa577/clock_config.c"
"${ProjDirPath}/examples/_boards/frdmmcxa577/common/pin_mux/pin_mux.c"
"${ProjDirPath}/examples/_boards/frdmmcxa577/driver_examples/romapi/flexspi_nor/hardware_init.c"
"${ProjDirPath}/drivers/common/fsl_common.c"
"${ProjDirPath}/drivers/common/fsl_common_arm.c"
"${ProjDirPath}/drivers/gpio/fsl_gpio.c"
"${ProjDirPath}/drivers/inputmux/fsl_inputmux.c"
"${ProjDirPath}/drivers/lpuart/fsl_lpuart.c"
"${ProjDirPath}/drivers/mcx_spc/fsl_spc.c"
"${ProjDirPath}/components/assert/fsl_assert.c"
"${ProjDirPath}/components/debug_console_lite/fsl_debug_console.c"
"${ProjDirPath}/components/misc_utilities/fsl_syscall_stub.c"
"${ProjDirPath}/components/misc_utilities/fsl_sbrk.c"
"${ProjDirPath}/components/misc_utilities/fsl_memcpy.S"
"${ProjDirPath}/components/misc_utilities/fsl_memset.S"
"${ProjDirPath}/components/str/fsl_str.c"
"${ProjDirPath}/components/uart/fsl_adapter_lpuart.c"
"${ProjDirPath}/mcux_config.h"
"${ProjDirPath}/mcuxsdk_version.h"
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/fsl_device_registers.h"
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/MCXA577.h"
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/MCXA577_features.h"
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/MCXA577_COMMON.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_AHBSC.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_FLEXSPI.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_FMU.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_GDET.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_GPIO.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_INPUTMUX.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_ITRC.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_LPUART.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_MRCC.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_PORT.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_RTC.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_SCG.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_SPC.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_SYSCON.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_USBHS.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_USBPHY.h"
"${ProjDirPath}/devices/MCX/MCXA/periph4/PERI_VBAT.h"
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/system_MCXA577.h"
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/drivers/romapi/flash/fsl_flash.h"
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/drivers/romapi/flash/fsl_flexspi_nor_flash.h"
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/drivers/romapi/flash/fsl_lpspi_flash.h"
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/drivers/romapi/fsl_romapi_tree.h"
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/drivers/fsl_clock.h"
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/drivers/fsl_inputmux_connections.h"
"${ProjDirPath}/devices/MCX/MCXA/MCXA577/drivers/fsl_reset.h"
"${ProjDirPath}/arch/arm/CMSIS/Core/Include/cmsis_compiler.h"
"${ProjDirPath}/arch/arm/CMSIS/Core/Include/cmsis_version.h"
"${ProjDirPath}/arch/arm/CMSIS/Core/Include/cmsis_gcc.h"
"${ProjDirPath}/arch/arm/CMSIS/Core/Include/m-profile/cmsis_gcc_m.h"
"${ProjDirPath}/arch/arm/CMSIS/Core/Include/core_cm33.h"
"${ProjDirPath}/arch/arm/CMSIS/Core/Include/m-profile/armv8m_mpu.h"
"${ProjDirPath}/arch/arm/CMSIS/Core/Include/tz_context.h"
"${ProjDirPath}/examples/_boards/frdmmcxa577/board.h"
"${ProjDirPath}/examples/_boards/frdmmcxa577/clock_config.h"
"${ProjDirPath}/examples/_boards/frdmmcxa577/common/pin_mux/pin_mux.h"
"${ProjDirPath}/examples/_boards/frdmmcxa577/driver_examples/romapi/flexspi_nor/app.h"
"${ProjDirPath}/drivers/common/fsl_common.h"
"${ProjDirPath}/drivers/common/fsl_common_arm.h"
"${ProjDirPath}/drivers/gpio/fsl_gpio.h"
"${ProjDirPath}/drivers/inputmux/fsl_inputmux.h"
"${ProjDirPath}/drivers/lpuart/fsl_lpuart.h"
"${ProjDirPath}/drivers/mcx_spc/fsl_spc.h"
"${ProjDirPath}/drivers/port/fsl_port.h"
"${ProjDirPath}/components/assert/fsl_assert.h"
"${ProjDirPath}/components/debug_console_lite/fsl_debug_console.h"
"${ProjDirPath}/components/str/fsl_str.h"
"${ProjDirPath}/components/uart/fsl_adapter_uart.h"
)

target_include_directories(${MCUX_SDK_PROJECT_NAME} PRIVATE
    "${ProjDirPath}/devices/MCX/MCXA/MCXA577"
    "${ProjDirPath}/devices/MCX/MCXA/periph4"
    "${ProjDirPath}/devices/MCX/MCXA/MCXA577/drivers/romapi/flash"
    "${ProjDirPath}/devices/MCX/MCXA/MCXA577/drivers/romapi"
    "${ProjDirPath}/devices/MCX/MCXA/MCXA577/drivers"
    "${ProjDirPath}/arch/arm/CMSIS/Core/Include"
    "${ProjDirPath}/arch/arm/CMSIS/Core/Include/m-profile"
    "${ProjDirPath}/examples/_boards/frdmmcxa577"
    "${ProjDirPath}/examples/_boards/frdmmcxa577/common/pin_mux"
    "${ProjDirPath}/examples/_boards/frdmmcxa577/driver_examples/romapi/flexspi_nor"
    "${ProjDirPath}/drivers/common"
    "${ProjDirPath}/drivers/gpio"
    "${ProjDirPath}/drivers/inputmux"
    "${ProjDirPath}/drivers/lpuart"
    "${ProjDirPath}/drivers/mcx_spc"
    "${ProjDirPath}/drivers/port"
    "${ProjDirPath}/components/assert"
    "${ProjDirPath}/components/debug_console_lite"
    "${ProjDirPath}/components/str"
    "${ProjDirPath}/components/uart"
)

if (CMAKE_BUILD_TYPE STREQUAL debug)
    IF(NOT DEFINED TARGET_LINK_SYSTEM_LIBRARIES)
        SET(TARGET_LINK_SYSTEM_LIBRARIES "-lm -lc -lgcc -lnosys")
    ENDIF()

    TARGET_LINK_LIBRARIES(${MCUX_SDK_PROJECT_NAME} PRIVATE -Wl,--start-group)

    target_link_libraries(${MCUX_SDK_PROJECT_NAME} PRIVATE ${TARGET_LINK_SYSTEM_LIBRARIES})

    TARGET_LINK_LIBRARIES(${MCUX_SDK_PROJECT_NAME} PRIVATE -Wl,--end-group)
endif()

ADD_CUSTOM_COMMAND(TARGET ${MCUX_SDK_PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_OBJCOPY}
-Obinary ${CMAKE_CURRENT_BINARY_DIR}/${MCUX_SDK_PROJECT_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${BUILD_CONFIG_NAME}.bin)

set_target_properties(${MCUX_SDK_PROJECT_NAME} PROPERTIES ADDITIONAL_CLEAN_FILES "output.map;${CMAKE_CURRENT_BINARY_DIR}/${BUILD_CONFIG_NAME}.bin")

include(${CMAKE_CURRENT_LIST_DIR}/flash-driver.cmake)
