def setup_can_build(cfg):
    '''enable CAN build. By doing this here we can auto-enable CAN in
    the build based on the presence of CAN pins in hwdef.dat'''
    env = cfg.env
    env.AP_LIBRARIES += [
        'AP_UAVCAN',
        'modules/uavcan/libuavcan/src/**/*.cpp',
        'modules/uavcan/libuavcan_drivers/stm32/driver/src/*.cpp'
        ]

    env.CFLAGS += ['-DUAVCAN_STM32_CHIBIOS=1',
                   '-DUAVCAN_STM32_NUM_IFACES=2']

    env.CXXFLAGS += [
        '-Wno-error=cast-align',
        '-DUAVCAN_STM32_CHIBIOS=1',
        '-DUAVCAN_STM32_NUM_IFACES=2'
        ]

    env.DEFINES += [
        'UAVCAN_CPP_VERSION=UAVCAN_CPP03',
        'UAVCAN_NO_ASSERTIONS=1',
        'UAVCAN_NULLPTR=nullptr'
        ]

    env.INCLUDES += [
        cfg.srcnode.find_dir('modules/uavcan/libuavcan/include').abspath(),
        cfg.srcnode.find_dir('modules/uavcan/libuavcan_drivers/stm32/driver/include').abspath()
        ]
    cfg.get_board().with_uavcan = True