@@ -20,13 +20,15 @@ class CommandLineArguments : public ReflectClassT<CommandLineArguments>
2020public:
2121 CommandLineArguments ():
2222 _local (false ),
23+ _location (false ),
2324 _vs (0 )
2425 {
2526
2627 }
2728
2829 REFLECTABLE (CommandLineArguments,
2930 (bool )local,
31+ (bool )location,
3032 (int )vs
3133 );
3234};
@@ -133,62 +135,67 @@ int _wmain(int argc, wchar_t** argv)
133135 printf (" \r\n " );
134136 printf (" -local - Keep generated project next to script.\r\n " );
135137 printf (" -vs <version> - use specific Visual studio (2019, 2017...)\r\n " );
138+ printf (" -location - Only display where Visual studio is located\r\n " );
136139 return -2 ;
137140 }
138141
139142 path projectDir;
140143
141- if ( cmdargs.local )
144+ if ( cmdargs.local )
142145 projectDir = scriptToRun.parent_path ();
143146 else
144147 projectDir = temp_directory_path ().append (L" cppscript" ).append (scriptToRun.stem ().c_str ());
145148
146- if (!exists (projectDir))
147- create_directories (projectDir);
148-
149149 Project p (scriptToRun.stem ().c_str ());
150150 p.SetSaveDirectory (projectDir.c_str ());
151- p.AddPlatform (L" x64" );
152- p.File (scriptToRun.c_str (), true );
153151
154- p.VisitConfigurations (
155- [&](VCConfiguration& c)
156- {
157- c.General .IntDir = LR"( obj\$(ProjectName)_$(Configuration)_$(Platform)\)" ;
158- c.General .OutDir = LR"( .\)" ;
159- c.General .UseDebugLibraries = true ;
160- c.General .LinkIncremental = true ;
161- c.General .ConfigurationType = conftype_DynamicLibrary;
162- c.CCpp .Optimization .Optimization = optimization_Disabled;
163- c.CCpp .General .AdditionalIncludeDirectories = path (exeDir).append (" SolutionProjectModel" ).c_str ();
164- c.CCpp .Language .LanguageStandard = cpplang_stdcpp17;
165- c.Linker .System .SubSystem = subsystem_Windows;
166- c.Linker .Debugging .GenerateDebugInformation = debuginfo_true;
167- }
168- );
152+ if (!cmdargs.location )
153+ {
154+ if (!exists (projectDir))
155+ create_directories (projectDir);
156+
157+ p.AddPlatform (L" x64" );
158+ p.File (scriptToRun.c_str (), true );
169159
170- auto dll = path (exeDir).append (" SolutionProjectModel.dll" );
171- auto f = p.File (dll.c_str (), true );
172- f->General .ItemType = CustomBuild;
173- auto exePathRelative = relative (exePath, projectDir);
174- f->VisitTool (
175- [&](PlatformConfigurationProperties* props)
160+ p.VisitConfigurations (
161+ [&](VCConfiguration& c)
162+ {
163+ c.General .IntDir = LR"( obj\$(ProjectName)_$(Configuration)_$(Platform)\)" ;
164+ c.General .OutDir = LR"( .\)" ;
165+ c.General .UseDebugLibraries = true ;
166+ c.General .LinkIncremental = true ;
167+ c.General .ConfigurationType = conftype_DynamicLibrary;
168+ c.CCpp .Optimization .Optimization = optimization_Disabled;
169+ c.CCpp .General .AdditionalIncludeDirectories = path (exeDir).append (" SolutionProjectModel" ).c_str ();
170+ c.CCpp .Language .LanguageStandard = cpplang_stdcpp17;
171+ c.Linker .System .SubSystem = subsystem_Windows;
172+ c.Linker .Debugging .GenerateDebugInformation = debuginfo_true;
173+ }
174+ );
175+
176+ auto dll = path (exeDir).append (" SolutionProjectModel.dll" );
177+ auto f = p.File (dll.c_str (), true );
178+ f->General .ItemType = CustomBuild;
179+ auto exePathRelative = relative (exePath, projectDir);
180+ f->VisitTool (
181+ [&](PlatformConfigurationProperties* props)
182+ {
183+ CustomBuildToolProperties& custtool = *((CustomBuildToolProperties*)props);
184+ CStringW cmd = CStringW (" \" " ) + exePathRelative.c_str () + " \" %(FullPath) >$(IntermediateOutputPath)%(Filename).def" ;
185+ cmd += " \n " ;
186+ cmd += " lib /nologo /def:$(IntermediateOutputPath)%(Filename).def /machine:$(Platform) /out:$(IntermediateOutputPath)%(Filename)_lib.lib" ;
187+ custtool.Message = " Generating static library for %(Identity)..." ;
188+ custtool.Command = cmd;
189+ custtool.Outputs = " $(IntermediateOutputPath)%(Filename)_lib.lib" ;
190+ }
191+ , &CustomBuildToolProperties::GetType ());
192+
193+ if ( !p.Save () )
176194 {
177- CustomBuildToolProperties& custtool = *((CustomBuildToolProperties*)props);
178- CStringW cmd = CStringW (" \" " ) + exePathRelative.c_str () + " \" %(FullPath) >$(IntermediateOutputPath)%(Filename).def" ;
179- cmd += " \n " ;
180- cmd += " lib /nologo /def:$(IntermediateOutputPath)%(Filename).def /machine:$(Platform) /out:$(IntermediateOutputPath)%(Filename)_lib.lib" ;
181- custtool.Message = " Generating static library for %(Identity)..." ;
182- custtool.Command = cmd;
183- custtool.Outputs = " $(IntermediateOutputPath)%(Filename)_lib.lib" ;
195+ printf (" Error: Could not save project file '%S'" , scriptToRun.stem ().c_str () );
196+ return -4 ;
184197 }
185- , &CustomBuildToolProperties::GetType ());
186-
187- if ( !p.Save () )
188- {
189- printf (" Error: Could not save project file '%S'" , scriptToRun.stem ().c_str () );
190- return -4 ;
191- }
198+ } // if
192199
193200 vector<VisualStudioInfo> instances;
194201
@@ -248,13 +255,30 @@ int _wmain(int argc, wchar_t** argv)
248255
249256 if (it == instances.end ())
250257 throwFormat (" Visual studio %d was not found on this machine" , cmdargs.vs );
258+
259+ if (cmdargs.location )
260+ {
261+ wprintf (L" %s\n " , it->InstallPath .c_str ());
262+ return 0 ;
263+ }
251264 }
252265 else
253266 {
254267 it = max_element (instances.begin (), instances.end (), [](auto e1 , auto e2 ) { return e1 .version < e2 .version ; });
255268
256269 if (it == instances.end ())
257270 throw exception (" No Visual Studio installation found" );
271+
272+ if (cmdargs.location )
273+ {
274+ for ( auto vsinfo: instances)
275+ {
276+ wprintf (L" Visual studio %d:\n " , vsinfo.version );
277+ wprintf (L" location: %s\n\n " , vsinfo.InstallPath .c_str ());
278+ }
279+
280+ return 0 ;
281+ }
258282 }
259283
260284 auto devenv = path (it->InstallPath ).append (" Common7\\ IDE\\ devenv.com" );
0 commit comments