# Main cmake file for project based on x86

set(CPU_FLAGS
    -march=x86-64
)

add_compile_options(
    ${CPU_FLAGS}
    -ffunction-sections
    -fdata-sections
    $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
    $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
    $<$<COMPILE_LANGUAGE:CXX>:-fno-threadsafe-statics>
    $<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-atexit>
)

include_directories(.)

#add_subdirectory(drv)
add_subdirectory(hal/x86)
add_subdirectory(third_party/FreeRTOS)
add_subdirectory(ul/freertos_wrappers)

# libnmea is a drv/gps/nmea dependency
#set(NMEA_BUILD_SHARED_LIB OFF CACHE BOOL "")
#set(NMEA_BUILD_EXAMPLES OFF CACHE BOOL "")
#set(NMEA_UNIT_TESTS OFF CACHE BOOL "")
#add_subdirectory(third_party/libnmea)

#add_subdirectory(third_party/FatFs)
#add_subdirectory(third_party/printf)
#add_subdirectory(ul/fatfs_diskio)
#add_subdirectory(ul/syslog)

add_executable(${CMAKE_PROJECT_NAME} main.cpp)

target_link_options(${CMAKE_PROJECT_NAME} PRIVATE
    ${CPU_FLAGS}
    -Wl,--gc-sections
    -Wl,-Map=${CMAKE_PROJECT_NAME}.map,--cref
)

target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
    #drv
    hal
    #fatfs_diskio
    #syslog
)

add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
    COMMAND size $<TARGET_FILE:${CMAKE_PROJECT_NAME}>
)
