63 lines
1.4 KiB
C++
63 lines
1.4 KiB
C++
#include "c.h"
|
|
#include "filesystem.h"
|
|
#include "helper.h"
|
|
#include "tier1/utlvector.h"
|
|
#include "libgen.h"
|
|
|
|
struct ClangFile_t
|
|
{
|
|
CUtlString m_szName;
|
|
CUtlVector<CUtlString> m_szArguments;
|
|
};
|
|
|
|
CUtlVector<ClangFile_t> g_clangFiles;
|
|
|
|
CLDProject CCProject::Compile()
|
|
{
|
|
CLDProject proj = {};
|
|
proj.m_szName = m_szName;
|
|
unsigned int hash = GenerateProjectHash();
|
|
for (auto &file: files)
|
|
{
|
|
CUtlString szOutputFile = CUtlString("%s/cc/%u_%s/%s/%s.o",FPC_TEMPORAL_DIRNAME, hash, m_szName.GetString(), IFileSystem2::OwnDirectory(), file.GetString());
|
|
CUtlString szOutputDir = szOutputFile;
|
|
szOutputDir = dirname(szOutputDir);
|
|
IFileSystem2::MakeDirectory(szOutputDir);
|
|
|
|
CUtlVector<CUtlString> args = {
|
|
"-g",
|
|
"-c",
|
|
"-o",
|
|
szOutputFile,
|
|
file,
|
|
};
|
|
if (bFPIC)
|
|
args.AppendTail("-fPIC");
|
|
if (bFPIE)
|
|
args.AppendTail("-fPIE");
|
|
for (auto ¯o: macros)
|
|
{
|
|
args.AppendTail("-D");
|
|
args.AppendTail(CUtlString("%s=%s", (char*)macro.szName, (char*)macro.szValue));
|
|
}
|
|
for (auto &include: includeDirectories)
|
|
{
|
|
args.AppendTail("-I");
|
|
args.AppendTail(include);
|
|
}
|
|
for (auto &include: includeFiles)
|
|
{
|
|
args.AppendTail("-include");
|
|
args.AppendTail(include);
|
|
}
|
|
IRunner::Run("clang", args);
|
|
proj.objects.AppendTail((CObject){szOutputFile});
|
|
|
|
ClangFile_t cfile = {};
|
|
cfile.m_szName = m_szName;
|
|
cfile.m_szArguments = args;
|
|
g_clangFiles.AppendTail(cfile);
|
|
}
|
|
return proj;
|
|
}
|