def _write_crossbuild_file(file):
    root_path = cmdutil.to_cmake_path(toolchain.sysroot)
    with open(file, 'w') as f:
        f.write('# generated by buildtool\n\n')
        f.write('SET(CMAKE_SYSTEM_NAME %s)\n\n' % toolchain.target_os_cmake)
        f.write('SET(CMAKE_C_COMPILER   %s)\n' % toolchain.tool_name('gcc'))
        f.write('SET(CMAKE_CXX_COMPILER %s)\n' % toolchain.tool_name('g++'))
        f.write('SET(CMAKE_RC_COMPILER  %s)\n\n' % toolchain.tool_name('windres'))
        f.write('SET(CMAKE_FIND_ROOT_PATH %s)\n' % root_path)
        f.write('SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\n')
        f.write('SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)\n')
        f.write('SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)\n')
def _build_cmake_args():
    if cmdutil.on_windows:
        generator = '"MinGW Makefiles"'
    else:
        generator = '"Unix Makefiles"'

    install_prefix = cmdutil.to_cmake_path(_info.install_dir)
    result = ['..', '-G', generator, '-DCMAKE_INSTALL_PREFIX=' + install_prefix]
    
    if toolchain.crossbuild:
        _write_crossbuild_file(path.join(_info.build_dir, 'crossbuild.cmake'))
        result.append('-DCMAKE_TOOLCHAIN_FILE=../crossbuild.cmake')

    return result