function setBuildArtifactProperties(h,artifact,writer,executor)
%

%   Copyright 2014-2020 The MathWorks, Inc.

if isempty( artifact )
    h.BuildArtifact = 'gmake makefile';
else
    h.BuildArtifact = artifact;
end
switch lower( h.BuildArtifact )
    case { 'gmake', 'gmake makefile' }
        h.BuildArtifact = 'gmake makefile';
        h.BuildArtifactType = coder.make.enum.BuildArtifact.GMAKE_MAKEFILE;
        h.BuildArtifactWriter = 'coder.make.GmakeWriter';
        h.BuildArtifactExecutor = 'coder.make.MakefileExecutor';
    case { 'nmake', 'nmake makefile' }
        h.BuildArtifact = 'nmake makefile';
        h.BuildArtifactType = coder.make.enum.BuildArtifact.NMAKE_MAKEFILE;
        h.BuildArtifactWriter = 'coder.make.NmakeWriter';
        h.BuildArtifactExecutor = 'coder.make.MakefileExecutor';
    case 'custom makefile'
        h.BuildArtifactType = coder.make.enum.BuildArtifact.CUSTOM_MAKEFILE;
    case 'msvc project'
        error(message('coder_compile:toolchain:UnsupportedBuildArtifact'));
        %Future
        %h.BuildArtifactType = coder.make.enum.BuildArtifact.MSVC_PROJECT;
        %h.BuildArtifactWriter = 'coder.make.MSVCWriter';
        %h.BuildArtifactExecutor = 'coder.make.MSVCExecutor';
    case 'custom ide project'
        % error(message('coder_compile:toolchain:UnsupportedBuildArtifact'));
        h.BuildArtifactType = coder.make.enum.BuildArtifact.CUSTOM_IDE_PROJECT;
        if isempty(writer)
            writer = 'coder.make.IDEProjectWriter';
        end
        if isempty(executor)
            executor = 'coder.make.IDEProjectExecutor';
        end
    otherwise
        error( message( 'coder_compile:toolchain:NotASupportedOption', artifact, 'build artifact' ) );
end
if h.isCustomBuildArtifact()
    % Custom artifact:
    narginchk( 4, 4 );
    h.BuildArtifactWriter = writer;
    h.BuildArtifactExecutor = executor;
else
    % Factory artifact:
    % Warn if user is passing a writer or executor for a factory
    % artifact. Tell user it will not be used.
    if nargin>2 && ~isempty( writer ) && ~strcmpi( writer, h.BuildArtifactWriter )
        warning( message( 'coder_compile:toolchain:FixedWriterExecutor', 'BuildArtifactWriter', h.BuildArtifact ) );
    end
    if nargin>3 && ~isempty( executor ) && ~strcmpi( executor, h.BuildArtifactExecutor )
        warning( message( 'coder_compile:toolchain:FixedWriterExecutor', 'BuildArtifactExecutor', h.BuildArtifact ) );
    end
end
end
