function ret = tgtLibAddIncPath(fname, modelName)
%   TGTLIBADDINCPATH - Adds an include path to the build process

%   Copyright 2007-2009 The MathWorks, Inc.

ret = 0;
if (nargin < 2)
    modelName = bdroot;
end

if ~isempty(fname)
    if ~iscell(fname)
        filename{1} = fname;
    else
        filename = fname;
    end
    hPM = linkfoundation.pjtgenerator.getProjectManager(modelName);
    if ~isempty(hPM) && ~isempty(hPM.mProjectBuildInfo)
        ret = hPM.addToProject('IncPath', filename);
    elseif isequal(get_param(modelName, 'SimulationMode'), 'rapid-accelerator')
        loc_addBuildInfoIncPath(filename,modelName);
    end
end

function ret =  loc_addBuildInfoIncPath(fname, modelName)
ret = 0;

if ~isempty(fname)
    if ~iscell(fname)
        filename{1} = fname;
    else
        filename = fname;
    end
    
    modelCodegenMgr = coder.internal.ModelCodegenMgr.getInstance(modelName);
    
    buildInfo = modelCodegenMgr.BuildInfo;
    
    buildInfo.addIncludePaths(filename, 'include');
end

