function setBuildConfigurationOption(h,cfg,name,value)

%   Copyright 2014-2020 The MathWorks, Inc.

narginchk( 4, 4 );
name = convertStringsToChars(name);
value = convertStringsToChars(value);

if strcmpi( cfg, 'all' )
    cfgKeys = h.getBuildConfigurationNames();
else
    cfgKeys = { cfg };
end
% g951761: Backward compatibility
name = h.updateIfUsingAlias( name );
% Set the specified build tool(s) for all configurations
for i = 1:numel( cfgKeys )
    cfg = cfgKeys{ i };
    if ischar( name )
        map = h.getBuildConfiguration( cfg );
        h.checkBuildConfigOptionForGetSet( map, name, value );
        obj = map.getOption( name );
        obj.setValue( value );
    elseif iscell( name ) && iscellstr( value )
        map = h.getBuildConfiguration( cfg );
        for j = 1:numel( name )
            h.checkBuildConfigOptionForGetSet( map, name{ j }, value{ j } );
            obj = map.getOption( name{ j } );
            obj.setValue( value{ j } );
        end
    else
        error( message( 'coder_compile:toolchain:IncorrectBuildConfigOptionFormat' ) )
    end
end
end
