Skip to content

Commit 5855cba

Browse files
committed
Tune: Add initial .dll generation with main entrypoint for launching script
1 parent bbaf392 commit 5855cba

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

SolutionProjectModel/cppexec/cppexec.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ string getFileExtension( const wchar_t* filePath )
3535

3636
int _wmain(int argc, wchar_t** argv)
3737
{
38-
path exePath(argv[0]);
39-
auto exeDir = weakly_canonical(exePath).parent_path();
38+
path exePath = weakly_canonical(argv[0]);
39+
auto exeDir = exePath.parent_path();
4040
path scriptToRun;
4141

4242
for (auto& pit : directory_iterator(exeDir))
@@ -131,14 +131,32 @@ int _wmain(int argc, wchar_t** argv)
131131
c.General.OutDir = LR"(.\)";
132132
c.General.UseDebugLibraries = true;
133133
c.General.LinkIncremental = true;
134+
c.General.ConfigurationType = conftype_DynamicLibrary;
134135
c.CCpp.Optimization.Optimization = optimization_Disabled;
135-
c.CCpp.General.AdditionalIncludeDirectories = exeDir.append("SolutionProjectModel").c_str();
136+
c.CCpp.General.AdditionalIncludeDirectories = path(exeDir).append("SolutionProjectModel").c_str();
136137
c.CCpp.Language.LanguageStandard = cpplang_stdcpp17;
137138
c.Linker.System.SubSystem = subsystem_Windows;
138139
c.Linker.Debugging.GenerateDebugInformation = debuginfo_true;
139140
}
140141
);
141142

143+
auto dll = path(exeDir).append("SolutionProjectModel.dll");
144+
auto f = p.File(dll.c_str(), true);
145+
f->General.ItemType = CustomBuild;
146+
auto exePathRelative = relative(exePath, projectDir);
147+
f->VisitTool(
148+
[&](PlatformConfigurationProperties* props)
149+
{
150+
CustomBuildToolProperties& custtool = *((CustomBuildToolProperties*)props);
151+
CStringW cmd = CStringW("\"") + exePathRelative.c_str() + "\" %(FullPath) >$(IntermediateOutputPath)%(Filename).def";
152+
cmd += "\n";
153+
cmd += "lib /nologo /def:$(IntermediateOutputPath)%(Filename).def /machine:$(Platform) /out:$(IntermediateOutputPath)%(Filename)_lib.lib";
154+
custtool.Message = "Generating static library for %(Identity)...";
155+
custtool.Command = cmd;
156+
custtool.Outputs = "$(IntermediateOutputPath)%(Filename)_lib.lib";
157+
}
158+
, &CustomBuildToolProperties::GetType());
159+
142160
if( !p.Save() )
143161
{
144162
printf("Error: Could not save project file '%S'", scriptToRun.stem().c_str() );

SolutionProjectModel/testCppApp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using namespace std;
55
using namespace filesystem;
66

7-
void main(void)
7+
void __declspec(dllexport) main(void)
88
{
99
Project p(L"HelloWorld");
1010

0 commit comments

Comments
 (0)