Plasma Engine  2.0
Loading...
Searching...
No Matches
CppProject.h
1#pragma once
2
3#include <EditorFramework/CodeGen/CppSettings.h>
4#include <EditorFramework/EditorFrameworkDLL.h>
5#include <EditorFramework/Preferences/Preferences.h>
6#include <Foundation/Communication/Event.h>
7#include <Foundation/Types/VariantType.h>
8#include <Foundation/Types/Status.h>
9
10// Only saved in editor preferences, does not have to work cross-platform
11struct PL_EDITORFRAMEWORK_DLL plIDE
12{
13 using StorageType = plUInt8;
14
15 enum Enum
16 {
17 Clion,
18 VisualStudioCode,
19#if PL_ENABLED(PL_PLATFORM_WINDOWS)
20 Rider,
21 _10x,
22 VisualStudio,
23 SolutionDefault,
24#endif
25 CustomOpenFolder,
26
27#if PL_ENABLED(PL_PLATFORM_WINDOWS)
28 Default = VisualStudio
29#else
30 Default = VisualStudioCode
31#endif
32 };
33};
34
35PL_DECLARE_REFLECTABLE_TYPE(PL_EDITORFRAMEWORK_DLL, plIDE);
36
37// Only saved in editor preferences, does not have to work cross-platform
38struct PL_EDITORFRAMEWORK_DLL plCompiler
39{
40 using StorageType = plUInt8;
41
42 enum Enum
43 {
44 Clang,
45#if PL_ENABLED(PL_PLATFORM_LINUX)
46 Gcc,
47#elif PL_ENABLED(PL_PLATFORM_WINDOWS)
48 Vs2022,
49#endif
50
51#if PL_ENABLED(PL_PLATFORM_WINDOWS)
52 Default = Vs2022
53#else
54 Default = Gcc
55#endif
56 };
57};
58
59PL_DECLARE_REFLECTABLE_TYPE(PL_EDITORFRAMEWORK_DLL, plCompiler);
60
61struct PL_EDITORFRAMEWORK_DLL plCompilerPreferences
62{
63 plEnum<plCompiler> m_Compiler;
64 bool m_bCustomCompiler;
65 plString m_sCppCompiler;
66 plString m_sCCompiler;
67 plString m_sRcCompiler;
68};
69
70PL_DECLARE_REFLECTABLE_TYPE(PL_EDITORFRAMEWORK_DLL, plCompilerPreferences);
71
72struct PL_EDITORFRAMEWORK_DLL plCppProject : public plPreferences
73{
74 PL_ADD_DYNAMIC_REFLECTION(plCppProject, plPreferences);
75
77 {
78 plString m_sNiceName;
79 plEnum<plCompiler> m_Compiler;
80 plString m_sCCompiler;
81 plString m_sCppCompiler;
82 bool m_bIsCustom;
83 };
84
85 enum class ModifyResult
86 {
87 FAILURE,
88 NOT_MODIFIED,
89 MODIFIED
90 };
91
92
95
96 static plString GetTargetSourceDir(plStringView sProjectDirectory = {});
97
98 static plString GetGeneratorFolderName(const plCppSettings& cfg);
99
100 static plString GetCMakeGeneratorName(const plCppSettings& cfg);
101
102 static plString GetPluginSourceDir(const plCppSettings& cfg, plStringView sProjectDirectory = {});
103
104 static plString GetBuildDir(const plCppSettings& cfg);
105
106 static plString GetSolutionPath(const plCppSettings& cfg);
107
108 static plStatus OpenSolution(const plCppSettings& cfg);
109
110 static plStringView CompilerToString(plCompiler::Enum compiler);
111
112 static plCompiler::Enum GetSdkCompiler();
113
114 static plString GetSdkCompilerMajorVersion();
115
116 static plStatus TestCompiler();
117
118 static const char* GetCMakePath();
119
120 static plResult CheckCMakeCache(const plCppSettings& cfg);
121
122 static ModifyResult CheckCMakeUserPresets(const plCppSettings& cfg, bool bWriteResult);
123
124 static bool ExistsSolution(const plCppSettings& cfg);
125
126 static bool ExistsProjectCMakeListsTxt();
127
128 static plResult PopulateWithDefaultSources(const plCppSettings& cfg);
129
130 static plResult CleanBuildDir(const plCppSettings& cfg);
131
132 static plResult RunCMake(const plCppSettings& cfg);
133
134 static plResult RunCMakeIfNecessary(const plCppSettings& cfg);
135
136 static plResult CompileSolution(const plCppSettings& cfg);
137
138 static plResult BuildCodeIfNecessary(const plCppSettings& cfg);
139
140 static plVariantDictionary CreateEmptyCMakeUserPresetsJson(const plCppSettings& cfg);
141
142 static ModifyResult ModifyCMakeUserPresetsJson(const plCppSettings& cfg, plVariantDictionary& inout_json);
143
144 static void UpdatePluginConfig(const plCppSettings& cfg);
145
146 static plResult EnsureCppPluginReady();
147
148 static bool IsBuildRequired();
149
152
153 static void LoadPreferences();
154
155 static plArrayPtr<const MachineSpecificCompilerPaths> GetMachineSpecificCompilers() { return s_MachineSpecificCompilers.GetArrayPtr(); }
156
157 // Change the current preferences to point to a SDK compatible compiler
158 static plResult ForceSdkCompatibleCompiler();
159
160private:
161 plEnum<plIDE> m_Ide;
162 plCompilerPreferences m_CompilerPreferences;
163 plString m_CustomIDEPath;
164
165
166 static plDynamicArray<MachineSpecificCompilerPaths> s_MachineSpecificCompilers;
167};
168
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Definition CppSettings.h:7
Definition DynamicArray.h:81
Definition Event.h:177
Base class for all preferences.
Definition Preferences.h:17
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Definition CppProject.h:39
Definition CppProject.h:62
Definition CppProject.h:73
static plEvent< const plCppSettings & > s_ChangeEvents
Fired when a notable change has been made.
Definition CppProject.h:151
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Definition CppProject.h:12
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
An plResult with an additional message for the reason of failure.
Definition Status.h:12