Skip to content

Commit 6502669

Browse files
committed
Feature: Add initial support for projecttype_CppSharedItemsProject project generation
1 parent f6823b7 commit 6502669

4 files changed

Lines changed: 115 additions & 54 deletions

File tree

SolutionProjectModel/Project.cpp

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,23 @@ wstring Project::GetSaveDirectory()
7171
wstring Project::GetProjectSaveLocation()
7272
{
7373
auto file = GetSaveDirectory();
74-
file += L"\\" + name + L".vcxproj";
74+
file += L"\\" + name + GetProjectExtension();
7575
return file;
7676
}
7777

78+
std::wstring Project::GetProjectExtension()
79+
{
80+
switch (projectType)
81+
{
82+
case projecttype_Console:
83+
default:
84+
return L".vcxproj";
85+
case projecttype_CppSharedItemsProject:
86+
return L".vcxitems";
87+
}
88+
}
89+
90+
7891

7992
void Project::SetVsVersion(int _vsVersion)
8093
{
@@ -553,18 +566,33 @@ void Project::VisitConfigurations(std::function<void (VCConfiguration&)> visitCo
553566
//
554567
// Clears existing project
555568
//
556-
void Project::New()
569+
void Project::New(EProjectType _projectType)
557570
{
558571
// Reset parsing variables.
559572
markForPropertyGroup = projectGlobals = xml_node();
560573

561574
xmldoc.reset();
562575
guid = GUID_NULL;
563-
SetVsVersion(2017); // May change without further notice
576+
projectType = _projectType;
577+
578+
switch (projectType)
579+
{
580+
case projecttype_Console:
581+
{
582+
SetVsVersion(2017); // May change without further notice
583+
584+
ReflectConnectChildren(nullptr);
585+
586+
Globals.Keyword = keyword_Win32Proj;
587+
Globals.WindowsTargetPlatformVersion = "10.0.17134.0";
588+
}
589+
break;
590+
591+
case projecttype_CppSharedItemsProject:
592+
ReflectConnectChildren(nullptr);
593+
break;
594+
}
564595

565-
ReflectConnectChildren(nullptr);
566-
Globals.Keyword = projecttype_Win32Proj;
567-
Globals.WindowsTargetPlatformVersion = "10.0.17134.0";
568596
}
569597

570598

@@ -618,13 +646,17 @@ pugi::xml_node Project::project()
618646
if (proj.empty())
619647
{
620648
proj = xmldoc.append_child(L"Project");
621-
proj.append_attribute(L"DefaultTargets").set_value(L"Build");
649+
if(projectType == projecttype_Console)
650+
proj.append_attribute(L"DefaultTargets").set_value(L"Build");
622651
proj.append_attribute(L"xmlns").set_value(L"http://schemas.microsoft.com/developer/msbuild/2003");
623652
}
624653

625654
// Project configurations
655+
626656
xml_node itemGroup = proj.first_child();
627-
if (itemGroup.empty())
657+
bool needsSpecialTags = projectType == projecttype_Console;
658+
659+
if (needsSpecialTags && itemGroup.empty())
628660
{
629661
itemGroup = proj.append_child(L"ItemGroup");
630662
itemGroup.append_attribute(L"Label").set_value(L"ProjectConfigurations");
@@ -637,13 +669,16 @@ pugi::xml_node Project::project()
637669
if (projectGlobals.empty())
638670
{
639671
// Project globals (Guid, etc...)
640-
projectGlobals = proj.insert_child_after(PropertyGroup, itemGroup);
672+
if(itemGroup.empty())
673+
projectGlobals = proj.append_child(PropertyGroup);
674+
else
675+
projectGlobals = proj.insert_child_after(PropertyGroup, itemGroup);
641676
projectGlobals.append_attribute(L"Label").set_value(L"Globals");
642677
}
643678
}
644679

645680
// Magical xml imports.
646-
if (markForPropertyGroup.empty())
681+
if (needsSpecialTags && markForPropertyGroup.empty())
647682
{
648683
proj.append_child(L"Import").append_attribute(L"Project").set_value(Microsoft_Cpp_Default_props);
649684
proj.append_child(L"Import").append_attribute(L"Project").set_value(Microsoft_Cpp_props);
@@ -680,10 +715,14 @@ bool Project::Save(const wchar_t* file)
680715
guid = GUID_NULL;
681716
}
682717
else
683-
fpath = name + L".vcxproj";
718+
fpath = name + GetProjectExtension();
684719

685720
project();
686-
Globals.ProjectGuid = GetGuid().c_str();
721+
722+
if( projectType == projecttype_CppSharedItemsProject)
723+
Globals.ItemsProjectGuid = GetGuid().c_str();
724+
else
725+
Globals.ProjectGuid = GetGuid().c_str();
687726

688727
fpath = GetSaveDirectory() + L"\\" + fpath;
689728

SolutionProjectModel/Project.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
#include <functional> //std::functional
66
#include <guiddef.h> //GUID
77

8+
9+
typedef enum SPM_DLLEXPORT {
10+
projecttype_Console,
11+
projecttype_CppSharedItemsProject
12+
}EProjectType;
13+
14+
815
//---------------------------------------------------------
916
// Project
1017
//---------------------------------------------------------
@@ -24,11 +31,12 @@ class SPM_DLLEXPORT Project : public ReflectClassT<Project>
2431
//
2532
std::wstring GetSaveDirectory();
2633
std::wstring GetProjectSaveLocation();
34+
std::wstring GetProjectExtension();
2735

2836
//
2937
// Clears existing project
3038
//
31-
void New();
39+
void New(EProjectType projectType = projecttype_Console);
3240

3341
//
3442
// Loads .vcxproj file.
@@ -87,6 +95,8 @@ class SPM_DLLEXPORT Project : public ReflectClassT<Project>
8795

8896

8997
protected:
98+
EProjectType projectType;
99+
90100
// Project name, typically used to identify project within solution or specify saved filename if file is not specified during save.
91101
std::wstring name;
92102

SolutionProjectModel/ProjectFileTypes.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,41 +101,41 @@ class SPM_DLLEXPORT ProjectItemGeneralConf : public ReflectClassT<ProjectItemGen
101101
//
102102
// Visual Studio project tagging.
103103
//
104-
DECLARE_ENUM(EKeyword, "projecttype_",
104+
DECLARE_ENUM(EKeyword, "keyword_",
105105
//
106106
// For sub-folders for example (Also default value). Also for utility projects.
107107
//
108-
projecttype_None = 0,
108+
keyword_None = 0,
109109

110110
//
111111
// Windows project (32 or 64 bit)
112112
//
113-
projecttype_Win32Proj,
113+
keyword_Win32Proj,
114114

115115
//
116116
// Same as Win32Proj, for some reason exists as separate value
117117
//
118-
projecttype_ManagedCProj,
118+
keyword_ManagedCProj,
119119

120120
//
121121
// Android project
122122
//
123-
projecttype_Android,
123+
keyword_Android,
124124

125125
//
126126
// Windows application with MFC support
127127
//
128-
projecttype_MFCProj,
128+
keyword_MFCProj,
129129

130130
//
131131
// Android packaging project (does not exists on file format level)
132132
//
133-
projecttype_AntPackage,
133+
keyword_AntPackage,
134134

135135
/// <summary>
136136
/// Typically set for Android packaging project. (does not exists on file format level)
137137
/// </summary>
138-
projecttype_GradlePackage
138+
keyword_GradlePackage
139139
);
140140

141141
class SPM_DLLEXPORT ProjectGlobalConf : public ReflectClassT<ProjectGlobalConf>
@@ -144,6 +144,8 @@ class SPM_DLLEXPORT ProjectGlobalConf : public ReflectClassT<ProjectGlobalConf>
144144
REFLECTABLE(ProjectGlobalConf,
145145
// This is typically non-configurable by end-user.
146146
(CStringA)ProjectGuid,
147+
(CStringA)ItemsProjectGuid,
148+
147149
(EKeyword)Keyword,
148150
(CStringW)WindowsTargetPlatformVersion
149151
);

SolutionProjectModel/testCppApp.cpp

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,52 @@ using namespace filesystem;
66

77
void __declspec(dllexport) main(void)
88
{
9-
Project p(L"HelloWorld");
9+
Project p(L"sharedItems");
10+
p.New(projecttype_CppSharedItemsProject);
1011

1112
p.SetSaveDirectory(L".");
12-
p.AddPlatform(L"x64");
13-
p.AddFiles({ L"helloWorld.cpp" });
14-
15-
p.VisitConfigurations(
16-
[](VCConfiguration& c)
17-
{
18-
c.General.IntDir = LR"(obj\$(ProjectName)_$(Configuration)_$(Platform)\)";
19-
c.General.OutDir = LR"(bin\$(Configuration)_$(Platform)\)";
20-
c.General.UseDebugLibraries = true;
21-
c.General.LinkIncremental = true;
22-
c.CCpp.Optimization.Optimization = optimization_Disabled;
23-
c.Linker.System.SubSystem = subsystem_Console;
24-
c.Linker.Debugging.GenerateDebugInformation = debuginfo_true;
25-
}
26-
);
27-
28-
auto f = p.File(L"..\\SolutionProjectModel.dll", true);
29-
f->General.ItemType = CustomBuild;
30-
f->VisitTool(
31-
[](PlatformConfigurationProperties* props)
32-
{
33-
CustomBuildToolProperties& custtool= *((CustomBuildToolProperties*)props);
34-
CStringW cmd = "..\\cppexec.exe %(FullPath) >$(IntermediateOutputPath)%(Filename).def";
35-
cmd += "\n";
36-
cmd += "lib /nologo /def:$(IntermediateOutputPath)%(Filename).def /machine:$(Platform) /out:$(IntermediateOutputPath)%(Filename)_lib.lib";
37-
custtool.Message = "Generating static library for %(Identity)...";
38-
custtool.Command = cmd;
39-
custtool.Outputs = "$(IntermediateOutputPath)%(Filename)_lib.lib";
40-
}
41-
, &CustomBuildToolProperties::GetType());
42-
13+
p.Save();
4314

15+
//Project p(L"HelloWorld");
16+
17+
//p.SetSaveDirectory(L".");
18+
//p.AddPlatform(L"x64");
19+
//p.AddFiles({ L"helloWorld.cpp" });
20+
21+
//p.VisitConfigurations(
22+
// [](VCConfiguration& c)
23+
// {
24+
// c.General.IntDir = LR"(obj\$(ProjectName)_$(Configuration)_$(Platform)\)";
25+
// c.General.OutDir = LR"(bin\$(Configuration)_$(Platform)\)";
26+
// c.General.UseDebugLibraries = true;
27+
// c.General.LinkIncremental = true;
28+
// c.CCpp.Optimization.Optimization = optimization_Disabled;
29+
// c.Linker.System.SubSystem = subsystem_Console;
30+
// c.Linker.Debugging.GenerateDebugInformation = debuginfo_true;
31+
// }
32+
//);
33+
34+
//auto f = p.File(L"..\\SolutionProjectModel.dll", true);
35+
//f->General.ItemType = CustomBuild;
36+
//f->VisitTool(
37+
// [](PlatformConfigurationProperties* props)
38+
// {
39+
// CustomBuildToolProperties& custtool= *((CustomBuildToolProperties*)props);
40+
// CStringW cmd = "..\\cppexec.exe %(FullPath) >$(IntermediateOutputPath)%(Filename).def";
41+
// cmd += "\n";
42+
// cmd += "lib /nologo /def:$(IntermediateOutputPath)%(Filename).def /machine:$(Platform) /out:$(IntermediateOutputPath)%(Filename)_lib.lib";
43+
// custtool.Message = "Generating static library for %(Identity)...";
44+
// custtool.Command = cmd;
45+
// custtool.Outputs = "$(IntermediateOutputPath)%(Filename)_lib.lib";
46+
// }
47+
//, &CustomBuildToolProperties::GetType());
48+
49+
//p.Save();
50+
51+
//Project p(L"emptyProject");
52+
//p.SetSaveDirectory(L".");
53+
//p.AddPlatform(L"x64");
54+
//p.Save();
4455

45-
p.Save();
4656
}
4757

0 commit comments

Comments
 (0)