include(CMakeForceCompiler)

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

# THE VERSION NUMBER
SET (Tutorial_VERSION_MAJOR 1)
SET (Tutorial_VERSION_MINOR 0)

project(my_project)

# ENABLE ASM
enable_language(ASM)

set(CMAKE_STATIC_LIBRARY_PREFIX)
set(CMAKE_STATIC_LIBRARY_SUFFIX)

set(CMAKE_EXECUTABLE_LIBRARY_PREFIX)
set(CMAKE_EXECUTABLE_LIBRARY_SUFFIX)

set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -DDEBUG")
set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -D__STARTUP_CLEAR_BSS")
set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -D__STARTUP_INITIALIZE_NONCACHEDATA")
set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -g")
set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -mcpu=cortex-m3")
set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -Wall")
# set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -mfloat-abi=hard")
# set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -mfpu=fpv4-sp-d16")
set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -mthumb")
set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -fno-common")
set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -ffunction-sections")
set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -fdata-sections")
set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -ffreestanding")
set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -fno-builtin")
set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -mapcs")
set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -std=gnu99")

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -mcpu=cortex-m3")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall")
# set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -mfloat-abi=hard")
# set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -mfpu=fpv4-sp-d16")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -mthumb")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -MMD")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -MP")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-common")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ffunction-sections")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fdata-sections")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ffreestanding")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-builtin")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -mapcs")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -std=gnu99")

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mcpu=cortex-m3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mfloat-abi=hard")
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mfpu=fpv4-sp-d16")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mthumb")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -MMD")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -MP")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-common")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ffunction-sections")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fdata-sections")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ffreestanding")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-builtin")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mapcs")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-rtti")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-exceptions")

set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -mcpu=cortex-m3")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -Wall")
# set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -mfloat-abi=hard")
# set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -mfpu=fpv4-sp-d16")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} --specs=nano.specs")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} --specs=nosys.specs")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fno-common")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -ffunction-sections")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fdata-sections")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -ffreestanding")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fno-builtin")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -mthumb")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -mapcs")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -Xlinker")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} --gc-sections")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -Xlinker")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -static")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -Xlinker")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -z")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -Xlinker")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} muldefs")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -Xlinker")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -Map=output.map")

# ignore warnings
set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -Wno-unused-function")
set(CMAKE_C_FLAGS_DEBUG   "${CMAKE_C_FLAGS_DEBUG}   -Wno-unused-function")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-unused-function")

set(PrjDirPath ${CMAKE_CURRENT_SOURCE_DIR})

# USER_CONF_START
include_directories(
    ${PrjDirPath}/..
    ${PrjDirPath}/../../../../components/mbedtls/include
    ${PrjDirPath}/../../../../device/drivers
    ${PrjDirPath}/../../../../device/CMSIS/Include
    ${PrjDirPath}/../../../../device
)

add_executable(${CMAKE_PROJECT_NAME}.elf
    "${PrjDirPath}/../../../../device/mm32f3273g.h"
    "${PrjDirPath}/../../../../device/system_mm32f3273g.h"
    "${PrjDirPath}/../../../../device/mm32f3273g_features.h"
    "${PrjDirPath}/../../../../device/system_mm32f3273g.c"
    "${PrjDirPath}/../../../../device/hal_device_registers.h"
    "${PrjDirPath}/../../../../device/armgcc/startup_mm32f3273g.S"
    "${PrjDirPath}/../../../../device/drivers/hal_rtc.c"
    "${PrjDirPath}/../../../../device/drivers/hal_wwdg.c"
    "${PrjDirPath}/../../../../device/drivers/hal_uart.h"
    "${PrjDirPath}/../../../../device/drivers/hal_sdio.h"
    "${PrjDirPath}/../../../../device/drivers/hal_pwr.h"
    "${PrjDirPath}/../../../../device/drivers/hal_spi.c"
    "${PrjDirPath}/../../../../device/drivers/hal_i2c.h"
    "${PrjDirPath}/../../../../device/drivers/hal_power.h"
    "${PrjDirPath}/../../../../device/drivers/hal_dma_request.h"
    "${PrjDirPath}/../../../../device/drivers/hal_exti.c"
    "${PrjDirPath}/../../../../device/drivers/hal_rtc.h"
    "${PrjDirPath}/../../../../device/drivers/hal_exti.h"
    "${PrjDirPath}/../../../../device/drivers/hal_fsmc.c"
    "${PrjDirPath}/../../../../device/drivers/hal_usb_bdt.h"
    "${PrjDirPath}/../../../../device/drivers/hal_tim.h"
    "${PrjDirPath}/../../../../device/drivers/hal_power.c"
    "${PrjDirPath}/../../../../device/drivers/hal_pwr.c"
    "${PrjDirPath}/../../../../device/drivers/hal_common.h"
    "${PrjDirPath}/../../../../device/drivers/hal_rcc.h"
    "${PrjDirPath}/../../../../device/drivers/hal_gpio.h"
    "${PrjDirPath}/../../../../device/drivers/hal_syscfg.c"
    "${PrjDirPath}/../../../../device/drivers/hal_i2c.c"
    "${PrjDirPath}/../../../../device/drivers/hal_tim.c"
    "${PrjDirPath}/../../../../device/drivers/hal_flash.c"
    "${PrjDirPath}/../../../../device/drivers/hal_usb.h"
    "${PrjDirPath}/../../../../device/drivers/hal_comp.c"
    "${PrjDirPath}/../../../../device/drivers/hal_fsmc.h"
    "${PrjDirPath}/../../../../device/drivers/hal_iwdg.c"
    "${PrjDirPath}/../../../../device/drivers/hal_spi.h"
    "${PrjDirPath}/../../../../device/drivers/hal_i2s.h"
    "${PrjDirPath}/../../../../device/drivers/hal_dac.h"
    "${PrjDirPath}/../../../../device/drivers/hal_i2s.c"
    "${PrjDirPath}/../../../../device/drivers/hal_uart.c"
    "${PrjDirPath}/../../../../device/drivers/hal_wwdg.h"
    "${PrjDirPath}/../../../../device/drivers/hal_rcc.c"
    "${PrjDirPath}/../../../../device/drivers/hal_sdio.c"
    "${PrjDirPath}/../../../../device/drivers/hal_dma.c"
    "${PrjDirPath}/../../../../device/drivers/hal_dma.h"
    "${PrjDirPath}/../../../../device/drivers/hal_syscfg.h"
    "${PrjDirPath}/../../../../device/drivers/hal_usb.c"
    "${PrjDirPath}/../../../../device/drivers/hal_dac.c"
    "${PrjDirPath}/../../../../device/drivers/hal_flash.h"
    "${PrjDirPath}/../../../../device/drivers/hal_adc.h"
    "${PrjDirPath}/../../../../device/drivers/hal_adc.c"
    "${PrjDirPath}/../../../../device/drivers/hal_comp.h"
    "${PrjDirPath}/../../../../device/drivers/hal_iwdg.h"
    "${PrjDirPath}/../../../../device/drivers/hal_gpio.c"
    "${PrjDirPath}/../board_init.h"
    "${PrjDirPath}/../clock_init.h"
    "${PrjDirPath}/../pin_init.c"
    "${PrjDirPath}/../board_init.c"
    "${PrjDirPath}/../config-mini-tls1_1.h"
    "${PrjDirPath}/../readme.md"
    "${PrjDirPath}/../pin_init.h"
    "${PrjDirPath}/../clock_init.c"
    "${PrjDirPath}/../main.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/aes.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/aesni.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/arc4.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/aria.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/asn1parse.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/asn1write.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/base64.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/bignum.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/blowfish.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/camellia.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ccm.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/certs.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/chacha20.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/chachapoly.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/cipher.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/cipher_wrap.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/cmac.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ctr_drbg.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/debug.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/des.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/dhm.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ecdh.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ecdsa.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ecjpake.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ecp.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ecp_curves.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/entropy.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/entropy_poll.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/error.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/gcm.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/havege.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/hkdf.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/hmac_drbg.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/md.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/md2.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/md4.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/md5.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/memory_buffer_alloc.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/net_sockets.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/nist_kw.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/oid.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/padlock.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/pem.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/pk.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/pk_wrap.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/pkcs5.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/pkcs11.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/pkcs12.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/pkparse.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/pkwrite.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/platform.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/platform_util.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/poly1305.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/psa_crypto.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/psa_crypto_se.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/psa_crypto_slot_management.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/psa_crypto_storage.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/psa_its_file.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ripemd160.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/rsa.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/rsa_internal.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/sha1.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/sha256.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/sha512.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ssl_cache.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ssl_ciphersuites.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ssl_cli.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ssl_cookie.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ssl_msg.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ssl_srv.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ssl_ticket.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/ssl_tls.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/threading.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/timing.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/version.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/version_features.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/x509.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/x509_create.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/x509_crl.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/x509_crt.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/x509_csr.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/x509write_crt.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/x509write_csr.c"
    "${PrjDirPath}/../../../../components/mbedtls/library/xtea.c"
)

target_compile_definitions(${CMAKE_PROJECT_NAME}.elf
    PRIVATE MBEDTLS_CONFIG_FILE=<config-mini-tls1_1.h>
    PRIVATE BRD_PLUS_F3270
)

set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -T${PrjDirPath}/../../../../device/armgcc/linker/mm32f3273g_flash.ld -static")

# USER_CONF_END

target_link_libraries(${CMAKE_PROJECT_NAME}.elf
    -Wl,--start-group
    debug m
    debug c
    debug gcc
    debug nosys
    optimized m
    optimized c
    optimized gcc
    optimized nosys
    -Wl,--end-group
)
