cmake_minimum_required(VERSION 3.0.0)

# Setting the ARCH if not provided
if (NOT DEFINED ARCH)
    execute_process(COMMAND uname -m OUTPUT_VARIABLE arch_from_cmd)
    string(STRIP ${arch_from_cmd} arch_from_cmd)
    set(ARCH ${arch_from_cmd})
endif()

# Setting the CMAKE_C_COMPILER if not provided
if (${ARCH} STREQUAL "aarch64")
    if (NOT DEFINED CMAKE_C_COMPILER)
        set(CMAKE_C_COMPILER "/usr/bin/aarch64-linux-gnu-gcc")
    endif()
else()
    if (NOT DEFINED CMAKE_C_COMPILER)
        set(CMAKE_C_COMPILER "/usr/bin/gcc")
    endif()
endif()

set(HAILORT_ROOT $ENV{HAILORT_ROOT})

set (HAILORT_LIB ${HAILORT_ROOT}/lib/${ARCH}/libhailort.so.0.5.0)
# set(HAILORT_LIB "${HAILORT_ROOT}/../lib/linux.x86_64.release/libhailort.so.0.5.0")
set(HAILORT_INCLUDE_DIR ${HAILORT_ROOT}/include)
message(STATUS ${HAILORT_LIB})
message(STATUS ${HAILORT_INCLUDE_DIR})
set(COMPILE_OPTIONS_CPP -Werror -O3 -DNDEBUG -std=c++11)
set(COMPILE_OPTIONS -O3 -DNDEBUG)
include_directories(${HAILORT_INCLUDE_DIR} "./")

find_package(Threads)

foreach(target example shortcut example_1rx_thread)
    add_executable(${target} "${target}.c")
    target_compile_options(${target} PRIVATE ${COMPILE_OPTIONS})
    target_link_libraries(${target} ${CMAKE_THREAD_LIBS_INIT})
    target_link_libraries(${target} ${HAILORT_LIB})
endforeach(target)


#find_package( OpenCV REQUIRED )
#include_directories( ${OpenCV_INCLUDE_DIRS} )
# add_executable(md_example example_device.cpp main.cpp)
# target_compile_options(md_example PRIVATE ${COMPILE_OPTIONS_CPP})
# target_link_libraries(md_example ${CMAKE_THREAD_LIBS_INIT})
# target_link_libraries(md_example ${HAILORT_LIB})
#target_link_libraries(md_example ${OpenCV_LIBS})