function clangSetupFcn
% This function is used by clang tools MATLABSetup (in clang_tools.m) 
% to check if the Xcode version is correct. 

% Copyright 2014-2020 The MathWorks, Inc.

    cmd = [ 'perl ', fullfile(matlabroot, 'rtw', 'c', 'tools', 'macsdkver.pl') ];
    [ status, ~ ] = system(cmd);
    if (status~=0)
        error(message('RTW:targetRegistry:notSupportedMacOSxVer'));
    end
    
    % Verify the Xcode license is accepted
    [status, xcodeAcceptedVer] = system('defaults read /Library/Preferences/com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense');            
    xcodeAcceptedVerNum = str2double(strrep(xcodeAcceptedVer, '.', ''));
    
    if (status ~= 0 || isnan(xcodeAcceptedVerNum))
        error(message('Simulink:slbuild:XcodeLicenseNotAccepted', xcodeAcceptedVer));
    end
end
