added compile_commands.json

This commit is contained in:
2025-06-03 00:19:45 +03:00
parent 3beb7aad3b
commit 83b18faab8
9 changed files with 98 additions and 14 deletions

View File

@@ -3,6 +3,7 @@
#include "helper.h"
#include "tier1/utlvector.h"
#include "libgen.h"
#include <cstdio>
struct ClangFile_t
{
@@ -54,9 +55,33 @@ CLDProject CCProject::Compile()
proj.objects.AppendTail((CObject){szOutputFile});
ClangFile_t cfile = {};
cfile.m_szName = m_szName;
cfile.m_szName = file;
cfile.m_szArguments = args;
g_clangFiles.AppendTail(cfile);
}
return proj;
}
void CCProject::GenerateCompileCommands()
{
FILE* f = V_fopen("compile_commands.json", "w");
V_fprintf(f, "[\n");
uint32_t i = 0;
for (auto &file: g_clangFiles)
{
V_fprintf(f, "\t{\n");
V_fprintf(f, "\t\t\"arguments\": [\n");
V_fprintf(f, "\t\t\t\"clang\",\n");
for (auto &arg: file.m_szArguments)
V_fprintf(f, "\t\t\t\"%s\",\n",arg.GetString());
V_fseek(f, -2, SEEK_CUR);
V_fprintf(f, "\n\t\t],\n");
V_fprintf(f, "\t\t\"file\": \"%s\",\n", file.m_szName.GetString());
V_fprintf(f, "\t\t\"directory\": \"%s\"\n", IFileSystem2::OwnDirectory());
V_fprintf(f, "\t},\n");
};
V_fseek(f, -2, SEEK_CUR);
V_fprintf(f, "\n]\n");
V_fclose(f);
};