File: CMakeBuilder.cpp

package info (click to toggle)
codelite 10.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 71,364 kB
  • sloc: cpp: 415,397; ansic: 18,277; php: 9,547; lex: 4,181; yacc: 2,820; python: 2,294; sh: 383; makefile: 51; xml: 13
file content (131 lines) | stat: -rw-r--r-- 4,500 bytes parent folder | download
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "CMakeBuilder.h"
#include "globals.h"
#include "workspace.h"

#define CMAKE_BUILD_FOLDER_PREFIX "cmake-build-"
CMakeBuilder::CMakeBuilder()
    : Builder("CMake")
{
}

CMakeBuilder::~CMakeBuilder() {}

bool CMakeBuilder::Export(const wxString& project, const wxString& confToBuild, const wxString& arguments,
    bool isProjectOnly, bool force, wxString& errMsg)
{
    wxUnusedVar(project);
    wxUnusedVar(confToBuild);
    wxUnusedVar(arguments);
    wxUnusedVar(isProjectOnly);
    wxUnusedVar(force);
    wxUnusedVar(errMsg);
    return true;
}

wxString CMakeBuilder::GetCleanCommand(const wxString& project, const wxString& confToBuild, const wxString& arguments)
{
    // The build folder is set to the workspace-path/workspace-config
    wxString command;
    command << "cd " << GetWorkspaceBuildFolder(true) << " && " << GetBuildToolCommand(project, confToBuild)
            << " clean";
    return command;
}

wxString CMakeBuilder::GetBuildCommand(const wxString& project, const wxString& confToBuild, const wxString& arguments)
{
    // The build folder is set to the workspace-path/workspace-config
    wxString command;
    command << "cd " << GetWorkspaceBuildFolder(true) << " && " << GetBuildToolCommand(project, confToBuild);
    return command;
}

wxString CMakeBuilder::GetPOCleanCommand(
    const wxString& project, const wxString& confToBuild, const wxString& arguments)
{
    wxString command;
    command << "cd " << GetProjectBuildFolder(project, true) << " && " << GetBuildToolCommand(project, confToBuild)
            << " clean";
    return command;
}

wxString CMakeBuilder::GetPOBuildCommand(
    const wxString& project, const wxString& confToBuild, const wxString& arguments)
{
    wxString command;
    command << "cd " << GetProjectBuildFolder(project, true) << " && " << GetBuildToolCommand(project, confToBuild);
    return command;
}

wxString CMakeBuilder::GetPORebuildCommand(
    const wxString& project, const wxString& confToBuild, const wxString& arguments)
{
    wxString command;
    command << "cd " << GetProjectBuildFolder(project, true) << " && " << GetBuildToolCommand(project, confToBuild)
            << " clean all";
    return command;
}

wxString CMakeBuilder::GetSingleFileCmd(
    const wxString& project, const wxString& confToBuild, const wxString& arguments, const wxString& fileName)
{
    return wxEmptyString;
}

wxString CMakeBuilder::GetPreprocessFileCmd(const wxString& project, const wxString& confToBuild,
    const wxString& arguments, const wxString& fileName, wxString& errMsg)
{
    return wxEmptyString;
}

wxString CMakeBuilder::GetWorkspaceBuildFolder(bool wrapWithQuotes)
{
    wxFileName fn = clCxxWorkspaceST::Get()->GetFileName();
    wxString workspaceConfig = clCxxWorkspaceST::Get()->GetBuildMatrix()->GetSelectedConfigurationName();

    fn.AppendDir(CMAKE_BUILD_FOLDER_PREFIX + workspaceConfig);
    wxString folder = fn.GetPath();
    if(wrapWithQuotes) {
        ::WrapWithQuotes(folder);
    }
    return folder;
}

wxString CMakeBuilder::GetProjectBuildFolder(const wxString& project, bool wrapWithQuotes)
{
    ProjectPtr p = clCxxWorkspaceST::Get()->GetProject(project);
    wxASSERT(p);

    wxFileName fnProject = p->GetFileName();
    wxFileName fnWorkspace = clCxxWorkspaceST::Get()->GetFileName();
    fnProject.MakeRelativeTo(fnWorkspace.GetPath());

    wxString workspaceConfig = clCxxWorkspaceST::Get()->GetBuildMatrix()->GetSelectedConfigurationName();
    fnWorkspace.AppendDir(CMAKE_BUILD_FOLDER_PREFIX + workspaceConfig);

    wxString folder;
    folder = fnWorkspace.GetPath();
    folder << wxFileName::GetPathSeparator() << fnProject.GetPath();
    if(wrapWithQuotes) {
        ::WrapWithQuotes(folder);
    }
    return folder;
}

wxString CMakeBuilder::GetBuildToolCommand(const wxString& project, const wxString& confToBuild) const
{
    BuildConfigPtr bldConf = clCxxWorkspaceST::Get()->GetProjBuildConf(project, confToBuild);
    if(!bldConf) return wxEmptyString;

    // The 'make' command is part of the compiler settings
    CompilerPtr compiler = bldConf->GetCompiler();
    if(!compiler) return wxEmptyString;

    wxString buildTool = compiler->GetTool("MAKE");
    return buildTool + " -e ";
}
wxString CMakeBuilder::GetOutputFile() const
{
    wxChar sep = wxFileName::GetPathSeparator();
    return wxString() << "$(WorkspacePath)" << sep << CMAKE_BUILD_FOLDER_PREFIX << "$(WorkspaceConfiguration)" << sep
                      << "bin" << sep << "$(ProjectName)";
}