def get_build_config(build_worktree, args):
    """ Get a CMakeBuildConfig object from an argparse.Namespace object """
    build_config = build_worktree.build_config
    if hasattr(args, 'config'):
        if args.config:
            build_config.set_active_config(args.config)
    if hasattr(args, 'build_type'):
        build_config.build_type = args.build_type
    if hasattr(args, 'cmake_generator'):
        build_config.cmake_generator = args.cmake_generator
    if hasattr(args, 'verbose_make'):
        build_config.verbose_make = args.verbose_make
    if hasattr(args, 'cmake_flags') and args.cmake_flags:
        user_flags = list()
        for flag_string in args.cmake_flags:
            if '=' not in flag_string:
                raise Exception('Expecting a flag looking like -Dkey=value')
            key, value = flag_string.split('=', 1)
            user_flags.append((key, value))
        build_config.user_flags = user_flags
    if hasattr(args, 'num_jobs'):
        build_config.num_jobs = args.num_jobs
    if hasattr(args, 'build_prefix'):
        if args.build_prefix:
            build_config.build_prefix = args.build_prefix
    return build_config
