set(toolchain_dir /opt/roots/bbb)
set(toolchain_bin_dir ${toolchain_dir}/usr/bin)
set(toolchain_inc_dir ${toolchain_dir}/usr/include)
set(toolchain_lib_dir ${toolchain_dir}/usr/lib)
set(cross_prefix /usr/local/bin/arm-linux-gnueabihf-)
set(ENV{PKG_CONFIG_LIBDIR} ${toolchain_dir}/usr/lib/pkgconfig)
set(ENV{PKG_CONFIG_PATH} ${toolchain_lib_dir}/pkgconfig:${toolchain_dir}/usr/local/lib/pkgconfig)
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${toolchain_dir})
set(PKG_CONFIG_EXECUTABLE /usr/local/bin/pkg-config)

set(inc_flags "-I${toolchain_dir}/usr/include")

set(CMAKE_SYSTEM_NAME Linux CACHE INTERNAL "system name")
set(CMAKE_SYSTEM_PROCESSOR armv7l CACHE INTERNAL "processor")
set(CMAKE_LIBRARY_ARCHITECTURE arm-linux-gnueabihf CACHE INTERNAL "abi")
set(CMAKE_AR ${cross_prefix}gcc-ar CACHE FILEPATH "archiver")
set(CMAKE_RANLIB ${cross_prefix}gcc-ranlib CACHE FILEPATH "ranlib")
set(CMAKE_C_COMPILER ${cross_prefix}gcc)
set(CMAKE_CXX_COMPILER ${cross_prefix}g++)
set(CMAKE_ASM_COMPILER ${cross_prefix}gcc)
set(CMAKE_C_FLAGS "-march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon ${inc_flags}" CACHE INTERNAL "c compiler flags")
set(CMAKE_ASM_FLAGS "-march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon ${inc_flags}" CACHE INTERNAL "c compiler flags")
set(CMAKE_CXX_FLAGS "-march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon ${inc_flags}" CACHE INTERNAL "cxx compiler flags")
set(CMAKE_LINKER ${cross_prefix}ld)

set(link_flags "-L${toolchain_lib_dir} -Wl,-rpath-link,${toolchain_lib_dir},-rpath-link,${toolchain_dir}/lib/arm-linux-gnueabihf,-rpath-link,${toolchain_lib_dir}/pulseaudio,-rpath-link,${toolchain_dir}/lib -B${toolchain_lib_dir} -ldl -lc --sysroot=${toolchain_dir}")

set(CMAKE_EXE_LINKER_FLAGS ${link_flags} CACHE INTERNAL "exe link flags")
set(CMAKE_MODULE_LINKER_FLAGS ${link_flags} CACHE INTERNAL "module link flags")
set(CMAKE_SHARED_LINKER_FLAGS ${link_flags} CACHE INTERNAL "shared link flags")
set(CMAKE_FIND_ROOT_PATH "${toolchain_dir}/usr;${toolchain_lib_dir}" CACHE INTERNAL "cross root directory")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER CACHE INTERNAL "")
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY CACHE INTERNAL "")
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY CACHE INTERNAL "")
