function [ret, keys, vals, groups] = getDefines(buildInfo, incGroups, excGroups, ...
    params)
% GETDEFINES - The getDefines function returns preprocessor macro
% definitions stored in the model's build information. When the function
% returns a definition, it automatically performs the following:
%
% - prepends a -D to the definition if the -D was not specified when the
%   definition was added to the build information
% - Changes a lowercase -d to -D
%
% Using optional includeGroups and excludeGroups arguments, you can
% selectively include or exclude groups of definitions the function is to
% return.
%
% If you choose to specify excludeGroups and omit includeGroups, specify a
% null string ('') for includeGroups.
%   
% Argument      description
% buildinfo     Build information handle returned by RTW.Buildinfo.
% 
%
% includeGroups (optional) A character array or cell array of character arrays
%               that specifies groups of macro definitions you want the
%               function to return.
% excludeGroups (optional) A character array or cell array of character arrays
%               that specifies groups of macro definitions you do not want
%               the function to return.
%
% Return values
% The function returns the preprocessor macro definitions stored in the
% model's build information. The function returns the macro definitions in
% three vectors:
%
% Vector        Description
% macrodef      Complete macro definitions with -D prefix
% identifier    Names of the macros
% value         Values assigned to the macros (anything specified to the right
%               of the first equals sign) ; the default is an empty string ('')
%
% example 1:
%    myModelBuildInfo = RTW.BuildInfo;
%    addDefines(myModelBuildInfo, {'PROTO=first' '-DDEBUG'... 
%               'test' '-dPRODUCTION'}, {'Debug' 'Debug' 'Debug'... 
%               'Release'});
%    [defs names values]=getDefines(myModelBuildInfo);
%
%    resulting values:
%    defs ==   {'-DPROTO=first'   '-DDEBUG'   '-Dtest'   '-DPRODUCTION'}
%    names ==  {'PROTO'; 'DEBUG'; 'test'; 'PRODUCTION'}
%    values == {'first'; ''; ''; ''}
%
% example 2:
%    myModelBuildInfo = RTW.BuildInfo;
%    addDefines(myModelBuildInfo, {'PROTO=first' '-DDEBUG'... 
%               'test' '-dPRODUCTION'}, {'Debug' 'Debug' 'Debug'... 
%               'Release'});
%    defs = getDefines(myModelBuildInfo, 'Release');
% 
%    resulting values
%    defs == {'-DPRODUCTION'}
%
% Please refer to the documentation for more information.
%

% Copyright 2005-2023 The MathWorks, Inc.

arguments
    buildInfo
    incGroups = string.empty;
    excGroups = string.empty;
    params.OnlyForSharedLibraryMerge = false;
    params.SourceFile string {mustBeScalarOrEmpty} = string.empty;
end

[ret, keys, vals, groups] = buildInfo.Options.getOptions('Defines', ...
    incGroups, excGroups, ...
    OnlyForSharedLibraryMerge=params.OnlyForSharedLibraryMerge, ...
    SourceFileHandle=getSourceFileHandles(buildInfo, params.SourceFile));
