Skip to content

Commit b847e6e

Browse files
committed
Feature: Add support for
c.CCpp.Preprocessor.PreprocessorDefinitions = defines + L";%(PreprocessorDefinitions)"; c.Linker.Input.AdditionalDependencies = L"ws2_32.lib;Shlwapi.lib;%(AdditionalDependencies)"; Prototype: add project generation for GN tool.
1 parent 46b98bb commit b847e6e

3 files changed

Lines changed: 259 additions & 33 deletions

File tree

SolutionProjectModel/ProjectFileTypes.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,15 @@ class SPM_DLLEXPORT LinkerDebuggingConf : public ReflectClassT<LinkerDebuggingCo
310310
);
311311
};
312312

313+
class SPM_DLLEXPORT LinkerInputConf : public ReflectClassT<LinkerInputConf>
314+
{
315+
public:
316+
REFLECTABLE(LinkerInputConf,
317+
(std::wstring)AdditionalDependencies
318+
);
319+
};
320+
321+
313322
//
314323
// Character set - unicode MBCS.
315324
//
@@ -396,6 +405,14 @@ class SPM_DLLEXPORT CCppOptimizationConf : public ReflectClassT<CCppOptimization
396405
);
397406
};
398407

408+
class SPM_DLLEXPORT CCppPreprocessorConf : public ReflectClassT<CCppPreprocessorConf>
409+
{
410+
public:
411+
REFLECTABLE(CCppPreprocessorConf,
412+
(std::wstring)PreprocessorDefinitions
413+
);
414+
};
415+
399416
class SPM_DLLEXPORT CCppLanguageConf : public ReflectClassT<CCppLanguageConf>
400417
{
401418
public:
@@ -411,6 +428,7 @@ class SPM_DLLEXPORT CCppConf: public ReflectClassT<CCppConf>
411428
REFLECTABLE(CCppConf,
412429
(CCppGeneralConf)General,
413430
(CCppOptimizationConf)Optimization,
431+
(CCppPreprocessorConf)Preprocessor,
414432
(CCppLanguageConf)Language
415433
);
416434
};
@@ -457,7 +475,8 @@ class SPM_DLLEXPORT LinkerConf: public ReflectClassT<LinkerConf>
457475
public:
458476
REFLECTABLE(LinkerConf,
459477
(LinkerSystemConf)System,
460-
(LinkerDebuggingConf)Debugging
478+
(LinkerDebuggingConf)Debugging,
479+
(LinkerInputConf)Input
461480
);
462481
};
463482

SolutionProjectModel/TypeTraits.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,43 @@ class TypeTraitsT<CStringA> : public TypeTraits
171171
}
172172
};
173173

174+
template <>
175+
class TypeTraitsT<std::wstring> : public TypeTraits
176+
{
177+
public:
178+
virtual const char* name() { return "std::wstring"; }
179+
180+
virtual CStringW ToString(void* pField)
181+
{
182+
return ((std::wstring*)pField)->c_str();
183+
}
184+
185+
virtual void FromString(void* pField, const wchar_t* value)
186+
{
187+
*((std::wstring*)pField) = value;
188+
}
189+
};
190+
191+
192+
template <>
193+
class TypeTraitsT<std::string> : public TypeTraits
194+
{
195+
public:
196+
virtual const char* name() { return "std::string"; }
197+
198+
virtual CStringW ToString(void* pField)
199+
{
200+
return ((std::string*)pField)->c_str();
201+
}
202+
203+
virtual void FromString(void* pField, const wchar_t* value)
204+
{
205+
auto& s = *((std::string*)pField);
206+
s = CW2A(value);
207+
}
208+
};
209+
210+
174211

175212
template <>
176213
class TypeTraitsT<int> : public TypeTraits

SolutionProjectModel/testCppApp.cpp

Lines changed: 202 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,223 @@ using namespace filesystem;
77

88
void __declspec(dllexport) main(void)
99
{
10-
//Project p(L"sharedItems");
11-
//p.New(projecttype_CppSharedItemsProject);
10+
//Project proj(L"sharedItems");
11+
//proj.New(projecttype_CppSharedItemsProject);
1212

13-
//p.SetSaveDirectory(L".");
14-
//p.Save();
13+
//proj.SetSaveDirectory(L".");
14+
//proj.Save();
1515

16-
Project p(L"ninja");
16+
Project proj(L"gn");
1717

18-
p.SetSaveDirectory(LR"(C:\PrototypingQuick\CrashPad\crashpad3\ninja\src)");
19-
//p.SetVsVersion(2019);
20-
p.AddPlatform(L"x64");
21-
22-
for (auto& pit : directory_iterator(p.GetSaveDirectory()))
18+
proj.SetSaveDirectory(LR"(D:\Prototyping\crashpad\gn)");
19+
//proj.SetVsVersion(2019);
20+
proj.AddPlatform(L"x64");
21+
22+
string files[] =
2323
{
24-
auto& filePath = pit.path();
24+
"base/callback_internal.cc",
25+
"base/command_line.cc",
26+
"base/environment.cc",
27+
"base/files/file.cc",
28+
"base/files/file_enumerator.cc",
29+
"base/files/file_path.cc",
30+
"base/files/file_path_constants.cc",
31+
"base/files/file_util.cc",
32+
"base/files/scoped_file.cc",
33+
"base/files/scoped_temp_dir.cc",
34+
"base/json/json_parser.cc",
35+
"base/json/json_reader.cc",
36+
"base/json/json_writer.cc",
37+
"base/json/string_escape.cc",
38+
"base/logging.cc",
39+
"base/md5.cc",
40+
"base/memory/ref_counted.cc",
41+
"base/memory/weak_ptr.cc",
42+
"base/sha1.cc",
43+
"base/strings/string_number_conversions.cc",
44+
"base/strings/string_piece.cc",
45+
"base/strings/string_split.cc",
46+
"base/strings/string_util.cc",
47+
"base/strings/string_util_constants.cc",
48+
"base/strings/stringprintf.cc",
49+
"base/strings/utf_string_conversion_utils.cc",
50+
"base/strings/utf_string_conversions.cc",
51+
"base/third_party/icu/icu_utf.cc",
52+
"base/timer/elapsed_timer.cc",
53+
"base/value_iterators.cc",
54+
"base/values.cc",
55+
56+
"tools/gn/action_target_generator.cc",
57+
"tools/gn/action_values.cc",
58+
"tools/gn/analyzer.cc",
59+
"tools/gn/args.cc",
60+
"tools/gn/binary_target_generator.cc",
61+
"tools/gn/builder.cc",
62+
"tools/gn/builder_record.cc",
63+
"tools/gn/build_settings.cc",
64+
"tools/gn/bundle_data.cc",
65+
"tools/gn/bundle_data_target_generator.cc",
66+
"tools/gn/bundle_file_rule.cc",
67+
"tools/gn/c_include_iterator.cc",
68+
"tools/gn/c_substitution_type.cc",
69+
"tools/gn/c_tool.cc",
70+
"tools/gn/command_analyze.cc",
71+
"tools/gn/command_args.cc",
72+
"tools/gn/command_check.cc",
73+
"tools/gn/command_clean.cc",
74+
"tools/gn/command_desc.cc",
75+
"tools/gn/command_format.cc",
76+
"tools/gn/command_gen.cc",
77+
"tools/gn/command_help.cc",
78+
"tools/gn/command_meta.cc",
79+
"tools/gn/command_ls.cc",
80+
"tools/gn/command_path.cc",
81+
"tools/gn/command_refs.cc",
82+
"tools/gn/commands.cc",
83+
"tools/gn/compile_commands_writer.cc",
84+
"tools/gn/config.cc",
85+
"tools/gn/config_values.cc",
86+
"tools/gn/config_values_extractors.cc",
87+
"tools/gn/config_values_generator.cc",
88+
"tools/gn/copy_target_generator.cc",
89+
"tools/gn/create_bundle_target_generator.cc",
90+
"tools/gn/deps_iterator.cc",
91+
"tools/gn/desc_builder.cc",
92+
"tools/gn/eclipse_writer.cc",
93+
"tools/gn/err.cc",
94+
"tools/gn/escape.cc",
95+
"tools/gn/exec_process.cc",
96+
"tools/gn/filesystem_utils.cc",
97+
"tools/gn/function_exec_script.cc",
98+
"tools/gn/function_foreach.cc",
99+
"tools/gn/function_forward_variables_from.cc",
100+
"tools/gn/function_get_label_info.cc",
101+
"tools/gn/function_get_path_info.cc",
102+
"tools/gn/function_get_target_outputs.cc",
103+
"tools/gn/function_process_file_template.cc",
104+
"tools/gn/function_read_file.cc",
105+
"tools/gn/function_rebase_path.cc",
106+
"tools/gn/functions.cc",
107+
"tools/gn/function_set_defaults.cc",
108+
"tools/gn/function_set_default_toolchain.cc",
109+
"tools/gn/functions_target.cc",
110+
"tools/gn/function_template.cc",
111+
"tools/gn/function_toolchain.cc",
112+
"tools/gn/function_write_file.cc",
113+
"tools/gn/general_tool.cc",
114+
"tools/gn/generated_file_target_generator.cc",
115+
"tools/gn/group_target_generator.cc",
116+
"tools/gn/header_checker.cc",
117+
"tools/gn/import_manager.cc",
118+
"tools/gn/inherited_libraries.cc",
119+
"tools/gn/input_conversion.cc",
120+
"tools/gn/input_file.cc",
121+
"tools/gn/input_file_manager.cc",
122+
"tools/gn/item.cc",
123+
"tools/gn/json_project_writer.cc",
124+
"tools/gn/label.cc",
125+
"tools/gn/label_pattern.cc",
126+
"tools/gn/lib_file.cc",
127+
"tools/gn/loader.cc",
128+
"tools/gn/location.cc",
129+
"tools/gn/metadata.cc",
130+
"tools/gn/metadata_walk.cc",
131+
"tools/gn/ninja_action_target_writer.cc",
132+
"tools/gn/ninja_binary_target_writer.cc",
133+
"tools/gn/ninja_build_writer.cc",
134+
"tools/gn/ninja_bundle_data_target_writer.cc",
135+
"tools/gn/ninja_c_binary_target_writer.cc",
136+
"tools/gn/ninja_copy_target_writer.cc",
137+
"tools/gn/ninja_create_bundle_target_writer.cc",
138+
"tools/gn/ninja_generated_file_target_writer.cc",
139+
"tools/gn/ninja_group_target_writer.cc",
140+
"tools/gn/ninja_target_command_util.cc",
141+
"tools/gn/ninja_target_writer.cc",
142+
"tools/gn/ninja_toolchain_writer.cc",
143+
"tools/gn/ninja_utils.cc",
144+
"tools/gn/ninja_writer.cc",
145+
"tools/gn/operators.cc",
146+
"tools/gn/output_conversion.cc",
147+
"tools/gn/output_file.cc",
148+
"tools/gn/parse_node_value_adapter.cc",
149+
"tools/gn/parser.cc",
150+
"tools/gn/parse_tree.cc",
151+
"tools/gn/path_output.cc",
152+
"tools/gn/pattern.cc",
153+
"tools/gn/pool.cc",
154+
"tools/gn/qt_creator_writer.cc",
155+
"tools/gn/runtime_deps.cc",
156+
"tools/gn/scheduler.cc",
157+
"tools/gn/scope.cc",
158+
"tools/gn/scope_per_file_provider.cc",
159+
"tools/gn/settings.cc",
160+
"tools/gn/setup.cc",
161+
"tools/gn/source_dir.cc",
162+
"tools/gn/source_file.cc",
163+
"tools/gn/standard_out.cc",
164+
"tools/gn/string_utils.cc",
165+
"tools/gn/substitution_list.cc",
166+
"tools/gn/substitution_pattern.cc",
167+
"tools/gn/substitution_type.cc",
168+
"tools/gn/substitution_writer.cc",
169+
"tools/gn/switches.cc",
170+
"tools/gn/target.cc",
171+
"tools/gn/target_generator.cc",
172+
"tools/gn/template.cc",
173+
"tools/gn/token.cc",
174+
"tools/gn/tokenizer.cc",
175+
"tools/gn/tool.cc",
176+
"tools/gn/toolchain.cc",
177+
"tools/gn/trace.cc",
178+
"tools/gn/value.cc",
179+
"tools/gn/value_extractors.cc",
180+
"tools/gn/variables.cc",
181+
"tools/gn/visibility.cc",
182+
"tools/gn/visual_studio_utils.cc",
183+
"tools/gn/visual_studio_writer.cc",
184+
"tools/gn/xcode_object.cc",
185+
"tools/gn/xcode_writer.cc",
186+
"tools/gn/xml_element_writer.cc",
187+
"util/exe_path.cc",
188+
"util/msg_loop.cc",
189+
"util/semaphore.cc",
190+
"util/sys_info.cc",
191+
"util/ticks.cc",
192+
"util/worker_pool.cc",
193+
25194

26-
if (is_directory(filePath))
27-
continue;
195+
"base/files/file_enumerator_win.cc",
196+
"base/files/file_util_win.cc",
197+
"base/files/file_win.cc",
198+
"base/win/registry.cc",
199+
"base/win/scoped_handle.cc",
200+
"base/win/scoped_process_information.cc",
28201

29-
auto fname = lowercase(filePath.stem().u8string());
30-
auto ext = lowercase(filePath.extension().u8string());
31-
transform(ext.begin(), ext.end(), ext.begin(), tolower);
202+
"tools/gn/gn_main.cc"
203+
};
32204

33-
if (fname == "browse" || fname == "subprocess-posix" || fname == "test" /*|| fname == "msvc_helper_main-win32"*/)
34-
continue;
205+
for (auto strPath : files)
206+
proj.AddFile(path(strPath).c_str());
35207

36-
if(fname.find("test") != -1 || fname.find(".in") != -1 || fname.find("bench") != -1)
37-
continue;
38-
39-
if (ext == ".h" || ext == ".cc" || ext == ".c")
40-
p.AddFile(filePath.c_str());
41-
}
208+
wstring defines = L"NDEBUG;NOMINMAX;UNICODE;WIN32_LEAN_AND_MEAN;WINVER=0x0A00;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_DEPRECATE;_UNICODE;_WIN32_WINNT=0x0A00";
42209

43-
p.VisitConfigurations(
44-
[](VCConfiguration& c)
210+
proj.VisitConfigurations(
211+
[&](VCConfiguration& c)
45212
{
46213
c.General.IntDir = LR"(obj\$(ProjectName)_$(Configuration)_$(Platform)\)";
47214
c.General.OutDir = LR"(bin\$(Configuration)_$(Platform)\)";
48215
c.General.UseDebugLibraries = true;
49216
c.General.LinkIncremental = true;
50217
c.CCpp.Optimization.Optimization = optimization_Disabled;
218+
c.CCpp.General.AdditionalIncludeDirectories = L".;out";
219+
c.CCpp.Preprocessor.PreprocessorDefinitions = defines + L";%(PreprocessorDefinitions)";
51220
c.Linker.System.SubSystem = subsystem_Console;
221+
c.Linker.Input.AdditionalDependencies = L"ws2_32.lib;Shlwapi.lib;%(AdditionalDependencies)";
52222
c.Linker.Debugging.GenerateDebugInformation = debuginfo_true;
53223
}
54224
);
55225

56-
//auto f = p.File(L"..\\SolutionProjectModel.dll", true);
226+
//auto f = proj.File(L"..\\SolutionProjectModel.dll", true);
57227
//f->General.ItemType = CustomBuild;
58228
//f->VisitTool(
59229
// [](PlatformConfigurationProperties* props)
@@ -68,12 +238,12 @@ void __declspec(dllexport) main(void)
68238
// }
69239
//, &CustomBuildToolProperties::GetType());
70240

71-
p.Save();
241+
proj.Save();
72242

73-
//Project p(L"emptyProject");
74-
//p.SetSaveDirectory(L".");
75-
//p.AddPlatform(L"x64");
76-
//p.Save();
243+
//Project proj(L"emptyProject");
244+
//proj.SetSaveDirectory(L".");
245+
//proj.AddPlatform(L"x64");
246+
//proj.Save();
77247

78248
}
79249

0 commit comments

Comments
 (0)