set(OS "@platform_os@")
set(CPU "@use_cpu@")
set(PLATFORM "@target_platform@")
set(APP_RENDER_SYSTEM @app_rendersystem@)

set(CMAKE_FIND_ROOT_PATH @CMAKE_FIND_ROOT_PATH@)

# set CORE_SYSTEM_NAME and CMAKE_SYSTEM_NAME (sets CMAKE_CROSSCOMPILING)
if(OS STREQUAL linux)
  set(CMAKE_SYSTEM_NAME Linux)
  set(CORE_SYSTEM_NAME linux)
  if(PLATFORM STREQUAL raspberry-pi)
    set(CORE_PLATFORM_NAME rbpi)
    set(ENABLE_LDGOLD OFF CACHE BOOL "Disabling Gnu Gold Linker" FORCE)
    if(NOT APP_RENDER_SYSTEM)
      set(APP_RENDER_SYSTEM gles)
    endif()
  elseif(NOT "@target_platform@" STREQUAL "")
    set(CORE_PLATFORM_NAME @target_platform@)
  endif()
  if(NOT APP_RENDER_SYSTEM)
    set(APP_RENDER_SYSTEM gl)
  endif()
elseif(OS STREQUAL android)
  set(CMAKE_SYSTEM_NAME Android)
  set(CORE_SYSTEM_NAME android)
  if(NOT APP_RENDER_SYSTEM)
    set(APP_RENDER_SYSTEM gles)
  endif()
elseif(OS STREQUAL osx)
  set(CMAKE_SYSTEM_NAME Darwin)
  set(CORE_SYSTEM_NAME osx)
  if(NOT APP_RENDER_SYSTEM)
    set(APP_RENDER_SYSTEM gl)
  endif()
elseif(OS STREQUAL ios)
  set(CMAKE_SYSTEM_NAME Darwin)
  set(CORE_SYSTEM_NAME ios)
  if(NOT APP_RENDER_SYSTEM)
    set(APP_RENDER_SYSTEM gles)
  endif()
endif()

if(CORE_SYSTEM_NAME STREQUAL ios OR CORE_SYSTEM_NAME STREQUAL osx)
  set(CMAKE_OSX_SYSROOT @use_sdk_path@)
  list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT} ${CMAKE_OSX_SYSROOT}/usr /usr/X11R6)
  set(CMAKE_LIBRARY_PATH @CMAKE_FIND_ROOT_PATH@/lib:@use_sdk_path@/lib:/usr/X11R6/lib)
  set(CMAKE_INCLUDE_PATH @CMAKE_FIND_ROOT_PATH@/include:@use_sdk_path@/include:/usr/X11R6/include)
endif()
set(CMAKE_SYSTEM_VERSION 1)

# specify the cross compiler
set(CMAKE_C_COMPILER @CC@)
set(CMAKE_CXX_COMPILER @CXX@)
set(CMAKE_AR @AR@ CACHE FILEPATH "Archiver")
set(CMAKE_LINKER @LD@ CACHE FILEPATH "Linker")
set(CMAKE_OBJDUMP @OBJDUMP@ CACHE FILEPATH "Objdump")
set(CMAKE_RANLIB @RANLIB@ CACHE FILEPATH "Ranlib")

if(@use_ccache@ STREQUAL "yes")
  set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "@CCACHE@")
endif()

# where is the target environment
if(NOT "@use_toolchain@" STREQUAL "")
  list(APPEND CMAKE_FIND_ROOT_PATH @use_toolchain@/sysroot/usr)
endif()

# add RBPI's firmware directories
if(CORE_PLATFORM_NAME STREQUAL rbpi)
  list(APPEND CMAKE_FIND_ROOT_PATH @use_firmware@/opt/vc)
  list(APPEND CMAKE_LIBRARY_PATH @CMAKE_FIND_ROOT_PATH@/lib:@use_firmware@/opt/vc/lib)
  list(APPEND CMAKE_INCLUDE_PATH @CMAKE_FIND_ROOT_PATH@/include:@use_firmware@/opt/vc/include)
endif()

# add Android directories and tools
if(CORE_SYSTEM_NAME STREQUAL android)
  set(NDKROOT @use_ndk_path@)
  set(SDKROOT @use_sdk_path@)
  set(TOOLCHAIN @use_toolchain@)
  set(HOST @use_host@)
  string(REPLACE ":" ";" SDK_BUILDTOOLS_PATH "@build_tools_path@")
endif()

set(CMAKE_C_FLAGS "@platform_cflags@ @platform_includes@")
set(CMAKE_CXX_FLAGS "@platform_cxxflags@ @platform_includes@")
set(CMAKE_C_FLAGS_RELEASE "@platform_cflags_release@ @platform_includes@")
set(CMAKE_CXX_FLAGS_RELEASE "@platform_cxxflags_release@ @platform_includes@")
set(CMAKE_C_FLAGS_DEBUG "@platform_cflags_debug@ @platform_includes@")
set(CMAKE_CXX_FLAGS_DEBUG "@platform_cxxflags_debug@ @platform_includes@")
set(CMAKE_CPP_FLAGS "@platform_cflags@ @platform_includes@")
set(CMAKE_LD_FLAGS "@platform_ldflags@")
set(ENV{CFLAGS} ${CMAKE_C_FLAGS})
set(ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS})
set(ENV{CPPFLAGS} ${CMAKE_CPP_FLAGS})
set(ENV{LDFLAGS} ${CMAKE_LD_FLAGS})
# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_FRAMEWORK LAST)

# Binary Addons
if(NOT CORE_SYSTEM_NAME STREQUAL linux)
  set(ADDONS_PREFER_STATIC_LIBS ON)
endif()

set(KODI_DEPENDSBUILD 1)

