File: CompilerLocatorMSYS2Clang.cpp

package info (click to toggle)
codelite 17.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 136,204 kB
  • sloc: cpp: 491,547; ansic: 280,393; php: 10,259; sh: 8,930; lisp: 7,664; vhdl: 6,518; python: 6,020; lex: 4,920; yacc: 3,123; perl: 2,385; javascript: 1,715; cs: 1,193; xml: 1,110; makefile: 804; cobol: 741; sql: 709; ruby: 620; f90: 566; ada: 534; asm: 464; fortran: 350; objc: 289; tcl: 258; java: 157; erlang: 61; pascal: 51; ml: 49; awk: 44; haskell: 36
file content (113 lines) | stat: -rw-r--r-- 3,484 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "CompilerLocatorMSYS2Clang.hpp"

#include "GCCMetadata.hpp"
#include "Platform.hpp"
#include "compiler.h"

#include <wx/filename.h>

// --------------------------------------------------
// --------------------------------------------------

CompilerLocatorMSYS2ClangUsr::CompilerLocatorMSYS2ClangUsr()
{
    m_repository = "";
    m_msys2.SetChroot("\\usr");
}
CompilerLocatorMSYS2ClangUsr::~CompilerLocatorMSYS2ClangUsr() {}

CompilerLocatorMSYS2ClangMingw64::CompilerLocatorMSYS2ClangMingw64()
{
    m_repository = "mingw64";
    m_msys2.SetChroot("\\mingw64");
}

CompilerLocatorMSYS2ClangMingw64::~CompilerLocatorMSYS2ClangMingw64() {}

CompilerLocatorMSYS2ClangClang64::CompilerLocatorMSYS2ClangClang64()
{
    m_repository = "clang64";
    m_msys2.SetChroot("\\clang64");
}
CompilerLocatorMSYS2ClangClang64::~CompilerLocatorMSYS2ClangClang64() {}

// --------------------------------------------------
// --------------------------------------------------

CompilerLocatorMSYS2Clang::CompilerLocatorMSYS2Clang() {}

CompilerLocatorMSYS2Clang::~CompilerLocatorMSYS2Clang() {}

bool CompilerLocatorMSYS2Clang::Locate()
{
    m_compilers.clear();

    // try some defaults
    wxString clang_exe;
    if(!m_msys2.Which("clang", &clang_exe)) {
        return false;
    }

    auto compiler = Locate(wxFileName(clang_exe).GetPath());
    if(compiler) {
        m_compilers.push_back(compiler);
    }
    return !m_compilers.empty();
}

CompilerPtr CompilerLocatorMSYS2Clang::Locate(const wxString& folder)
{
    // check for g++
    wxFileName clang = GetFileName(folder, "clang");
    wxFileName clangxx = GetFileName(folder, "clang++");
    wxFileName ar = GetFileName(folder, "ar");
    wxFileName as = GetFileName(folder, "as");
    wxFileName make = GetFileName(folder, "mingw32-make");
    wxFileName windres = GetFileName(folder, "windres");
    wxFileName mkdir = GetFileName(folder, "mkdir");
    wxFileName gdb = GetFileName(folder, "gdb");

    // make sure that both clang & g++ exist
    if(!(clang.FileExists() && clangxx.FileExists())) {
        return nullptr;
    }

    // define the toolchain name
    wxString basename = m_repository;
    if(!basename.empty()) {
        basename << "/";
    }
    basename << "clang";
    GCCMetadata cmd(basename);

    cmd.Load(clang.GetFullPath(), folder);

    // create new compiler
    CompilerPtr compiler(new Compiler(nullptr));
    compiler->SetName(cmd.GetName());
    compiler->SetCompilerFamily(COMPILER_FAMILY_CLANG);
    compiler->SetInstallationPath(folder);

    // add the tools
    compiler->SetTool("CXX", clangxx.GetFullPath());
    compiler->SetTool("CC", clang.GetFullPath());
    compiler->SetTool("AR", ar.GetFullPath() + " -r");
    compiler->SetTool("LinkerName", clangxx.GetFullPath());
    compiler->SetTool("SharedObjectLinkerName", clangxx.GetFullPath() + " -shared -fPIC");
    compiler->SetTool("AS", as.GetFullPath());

    size_t cpu_count = wxThread::GetCPUCount();
    compiler->SetTool("MAKE", wxString() << make.GetFullPath() << " -j" << cpu_count);
    compiler->SetTool("ResourceCompiler", windres.GetFullPath());
    compiler->SetTool("Debugger", gdb.GetFullPath());
    return compiler;
}

void CompilerLocatorMSYS2Clang::AddTool(const wxString& tool_name, const wxString& value) {}

wxFileName CompilerLocatorMSYS2Clang::GetFileName(const wxString& bin_dir, const wxString& fullname) const
{
    wxFileName tool(bin_dir, fullname);
    tool.SetExt("exe");
    return tool;
}