set(CMAKE_SYSTEM_NAME Linux)
set(TENSOROPT_SYSROOT_DIR $ENV{TENSOROPT_SYSROOT_DIR})
set(TENSOROPT_TOOLCHAIN_DIR $ENV{TENSOROPT_TOOLCHAIN_DIR})
set(TENSOROPT_TARGET_TRIPLE $ENV{TENSOROPT_TARGET_TRIPLE})

if(NOT TENSOROPT_SYSROOT_DIR OR
  NOT TENSOROPT_TOOLCHAIN_DIR OR
  NOT TENSOROPT_TARGET_TRIPLE
)
  message(FATAL_ERROR
    "Please set all of TENSOROPT_TARGET_TRIPLE, TENSOROPT_SYSROOT_DIR and "
    "TENSOROPT_TOOLCHAIN_DIR in the environment when crosscompiling.")
endif()

set(CMAKE_SYSROOT ${TENSOROPT_SYSROOT_DIR})
set(CMAKE_C_COMPILER ${TENSOROPT_TOOLCHAIN_DIR}/bin/${TENSOROPT_TARGET_TRIPLE}-gcc)
set(CMAKE_CXX_COMPILER ${TENSOROPT_TOOLCHAIN_DIR}/bin/${TENSOROPT_TARGET_TRIPLE}-g++)
list(APPEND CMAKE_PREFIX_PATH ${TENSOROPT_TOOLCHAIN_DIR}/${TENSOROPT_TARGET_TRIPLE})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)

