vcxprojtool.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # @brief VCXProject file generator
4 # @date $Date: 2008-02-29 04:52:14 $
5 # @author Norkai Ando <n-ando@aist.go.jp>
6 #
7 # Copyright (C) 2008
8 # Tsuyoto Katami, Noriaki Ando
9 # Intelligent Systems Research Institute,
10 # National Institute of
11 # Advanced Industrial Science and Technology (AIST), Japan
12 # All rights reserved.
13 #
14 # $Id: vcxprojtool.py 1668 2010-01-16 17:13:48Z n-ando $
15 #
16 
17 #------------------------------------------------------------
18 # Generic vcxproj template
19 #------------------------------------------------------------
20 vcxproj_template = """<?xml version="1.0" encoding="utf-8"?>
21 <Project DefaultTargets="Build" ToolsVersion="[Version]" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22  <ItemGroup Label="ProjectConfigurations">
23  <ProjectConfiguration Include="Debug|Win32">
24  <Configuration>Debug</Configuration>
25  <Platform>Win32</Platform>
26  </ProjectConfiguration>
27  <ProjectConfiguration Include="Debug|x64">
28  <Configuration>Debug</Configuration>
29  <Platform>x64</Platform>
30  </ProjectConfiguration>
31  <ProjectConfiguration Include="Release|Win32">
32  <Configuration>Release</Configuration>
33  <Platform>Win32</Platform>
34  </ProjectConfiguration>
35  <ProjectConfiguration Include="Release|x64">
36  <Configuration>Release</Configuration>
37  <Platform>x64</Platform>
38  </ProjectConfiguration>
39  </ItemGroup>
40  <PropertyGroup Label="Globals">
41  <ProjectName>[RootNamespace]</ProjectName>
42  <ProjectGuid>{[ProjectGUID]}</ProjectGuid>
43  <RootNamespace>[RootNamespace]</RootNamespace>
44  <Keyword>Win32Proj</Keyword>
45  </PropertyGroup>
46  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
47 [for conf in Configurations]
48  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='[conf.Name]'" Label="Configuration">
49  <ConfigurationType>%s</ConfigurationType>
50  <CharacterSet>NotSet</CharacterSet>
51  </PropertyGroup>
52 [endfor]
53  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
54  <ImportGroup Label="ExtensionSettings">
55  </ImportGroup>
56 [for conf in Configurations]
57  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='[conf.Name]'" Label="PropertySheets">
58  <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
59 [for inher in conf.VC10_InheritedPropertySheets]
60 [if-any inher]
61  <Import Project="[inher]" />
62 [endif]
63 [endfor]
64  </ImportGroup>
65 [endfor]
66  <PropertyGroup Label="UserMacros" />
67  <PropertyGroup>
68  <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
69 [for conf in Configurations]
70  <OutDir Condition="'$(Configuration)|$(Platform)'=='[conf.Name]'">[conf.VC10_OutputDirectory]</OutDir>
71  <IntDir Condition="'$(Configuration)|$(Platform)'=='[conf.Name]'">[conf.VC10_IntermediateDirectory]</IntDir>
72  <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='[conf.Name]'">[conf.VC10_LinkIncrementalCondition]</LinkIncremental>
73 [endfor]
74  </PropertyGroup>
75 
76 [for conf in Configurations]
77  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='[conf.Name]'">
78  <!-- PreBuildEvent -->
79  <PreBuildEvent>
80 %s
81  </PreBuildEvent>
82  <!-- ClCompile -->
83  <ClCompile>
84 %s
85  </ClCompile>
86  <!-- Lib -->
87  <Lib>
88 %s
89  </Lib>
90  <!-- PreLinkEvent -->
91  <PreLinkEvent>
92 %s
93  </PreLinkEvent>
94  <!-- Link -->
95  <Link>
96 %s
97  </Link>
98  <!-- PostBuildEvent -->
99  <PostBuildEvent>
100 %s
101  </PostBuildEvent>
102  </ItemDefinitionGroup>
103 [endfor]
104  <ItemGroup>
105 [if-any Source]
106  <Filter Include="[Source.Name]">
107  <UniqueIdentifier>{[Source.GUID]}</UniqueIdentifier>
108  <Extensions>[Source.Filter]</Extensions>
109  </Filter>
110 [endif]
111 [if-any Header]
112  <Filter Include="[Header.Name]">
113  <UniqueIdentifier>{[Header.GUID]}</UniqueIdentifier>
114  <Extensions>[Header.Filter]</Extensions>
115  </Filter>
116 [endif]
117  </ItemGroup>
118  <ItemGroup>
119 [if-any Source.Files][for file in Source.Files]
120  <ClCompile Include="[file.Path]">
121  <Filter>[Source.Name]</Filter>
122  </ClCompile>
123 [endfor][endif]
124  </ItemGroup>
125  <ItemGroup>
126 [if-any Header.Files][for file in Header.Files]
127  <ClInclude Include="[file.Path]">
128  <Filter>[Header.Name]</Filter>
129  </ClInclude>
130 [endfor][endif]
131  </ItemGroup>
132  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
133  <ImportGroup Label="ExtensionTargets">
134  </ImportGroup>
135 </Project>
136 
137 """
138 
139 #------------------------------------------------------------
140 # ConfigurationType
141 #------------------------------------------------------------
142 conf_type = {"EXE": "Application", "DLL": "DynamicLibrary",
143  "NMAKE": "Makefile",
144  "LIB": "StaticLibrary",
145  "RTCEXE": "Application", "RTCDLL": "DynamicLibrary"}
146 
147 
148 #------------------------------------------------------------
149 # Tool set for configuration
150 #------------------------------------------------------------
151 PreBuildEventtools = {"EXE":
152  ["VC10_VCPreBuildEventTool",
153  "VCCustomBuildTool",
154  "VCXMLDataGeneratorTool",
155  "VCWebServiceProxyGeneratorTool",
156  "VCMIDLTool",
157  "VCManagedResourceCompilerTool",
158  "VCResourceCompilerTool",
159  "VCManifestTool"],
160  "DLL":
161  ["VC10_VCPreBuildEventTool"],
162  "LIB":
163  ["VC10_VCPreBuildEventTool"]
164  }
165 PreBuildEventtools["RTCEXE"] = PreBuildEventtools["EXE"]
166 PreBuildEventtools["RTCDLL"] = PreBuildEventtools["DLL"]
167 Cltools = {"EXE":
168  ["VCCustomBuildTool",
169  "VCXMLDataGeneratorTool",
170  "VCWebServiceProxyGeneratorTool",
171  "VCMIDLTool",
172  "VC10_VCCLCompilerTool",
173  "VCManagedResourceCompilerTool",
174  "VCResourceCompilerTool",
175  "VCManifestTool"],
176  "DLL":
177  ["VCCustomBuildTool",
178  "VCXMLDataGeneratorTool",
179  "VCWebServiceProxyGeneratorTool",
180  "VCMIDLTool",
181  "VC10_VCCLCompilerTool",
182  "VCManagedResourceCompilerTool",
183  "VCResourceCompilerTool",
184  "VCManifestTool"],
185  "LIB":
186  ["VCCustomBuildTool",
187  "VCXMLDataGeneratorTool",
188  "VCWebServiceProxyGeneratorTool",
189  "VCMIDLTool",
190  "VC10_VCCLCompilerTool",
191  "VCManagedResourceCompilerTool",
192  "VCResourceCompilerTool"]
193  }
194 Cltools["RTCEXE"] = Cltools["EXE"]
195 Cltools["RTCDLL"] = Cltools["DLL"]
196 Libtools = {"EXE":
197  ["VCLibrarianTool"],
198  "DLL":
199  ["VCLibrarianTool"],
200  "LIB":
201  ["VCLibrarianTool"]
202  }
203 Libtools["RTCEXE"] = Libtools["EXE"]
204 Libtools["RTCDLL"] = Libtools["DLL"]
205 PreLinkEventtools = {"EXE":
206  ["VC10_VCPreLinkEventTool"],
207  "DLL":
208  ["VC10_VCPreLinkEventTool"],
209  "LIB":
210  [""]
211  }
212 PreLinkEventtools["RTCEXE"] = PreLinkEventtools["EXE"]
213 PreLinkEventtools["RTCDLL"] = PreLinkEventtools["DLL"]
214 Linktools = {"EXE":
215  ["VC10_VCPreLinkEventTool",
216  "VC10_VCLinkerTool",
217  "VCALinkTool",
218  "VCManifestTool",
219  "VCXDCMakeTool",
220  "VCBscMakeTool",
221  "VCFxCopTool",
222  "VCAppVerifierTool",
223  "VCWebDeploymentTool"],
224  "DLL":
225  ["VC10_VCLinkerTool",
226  "VCALinkTool",
227  "VCManifestTool",
228  "VCXDCMakeTool",
229  "VCBscMakeTool",
230  "VCFxCopTool",
231  "VCAppVerifierTool",
232  "VCWebDeploymentTool"],
233  "LIB":
234  [""]
235  }
236 Linktools["RTCEXE"] = Linktools["EXE"]
237 Linktools["RTCDLL"] = Linktools["DLL"]
238 PostBuildEventtools = {"EXE":
239  ["VC10_VCPostBuildEventTool"],
240  "DLL":
241  ["VC10_VCPostBuildEventTool"],
242  "LIB":
243  ["VC10_VCPostBuildEventTool"]
244  }
245 PostBuildEventtools["RTCEXE"] = PostBuildEventtools["EXE"]
246 PostBuildEventtools["RTCDLL"] = PostBuildEventtools["DLL"]
247 
248 
249 #------------------------------------------------------------
250 # Tool element
251 #------------------------------------------------------------
252 tool_elem = """[if-any conf.%s][for tool in conf.%s]
253 [if-any tool.Key]
254  <[tool.Key]>[tool.Value]</[tool.Key]>
255 [endif]
256 [endfor][endif]"""
257 
258 
259 exeproj_yaml = """
260 ProjectType: Visual C++
261 Version: "__VCVERSION__"
262 Name: # Your Project Name
263 ProjectGUID: __GUID__
264 RootNamespace:
265 Keyword: Win32Proj
266 Platforms:
267  Platform:
268  Name: Win32
269 Configurations:
270  - Name: Debug
271  VC10_OutputDirectory: $(ProjectDir)$(Configuration)
272  VC10_IntermediateDirectory: $(Configuration)
273  VC10_InheritedPropertySheets: # Set vsprops file if you need
274 """
275 
277  import re
278  ret = ""
279  flag = False
280  for l in text.splitlines():
281  m = re.match("^Configurations:", l)
282  if m:
283  flag = True
284  continue
285  if flag:
286  ret += l.replace("Win32", "x64") + "\n"
287  return ret
288 
289 #------------------------------------------------------------
290 # Yaml template
291 #------------------------------------------------------------
292 exe_yaml = """ProjectType: "Visual C++"
293 Version: "__VCVERSION__"
294 Name: __PROJECT_NAME__
295 ProjectGUID: __GUID__
296 RootNamespace: __PROJECT_NAME__
297 Keyword: "Win32Proj"
298 Configurations:
299 #------------------------------------------------------------
300 # Debug Configuration
301 #------------------------------------------------------------
302  - Name: "Debug|Win32"
303  VC10_OutputDirectory: $(ProjectDir)$(Configuration)"
304  VC10_IntermediateDirectory: "$(Configuratio)"
305  ConfigurationType: "1"
306 # VC10_InheritedPropertySheets:
307  CharacterSet: "0"
308  VC10_LinkIncrementalCondition: "true"
309 # VCPreBuildEventTool:
310 # VCCustomBuildTool:
311 # VCXMLDataGeneratorTool:
312 # VCWebServiceProxyGeneratorTool:
313 # VCMIDLTool:
314  VC10_VCCLCompilerTool:
315  - Key: Optimization
316  Value: Disabled
317  - Key: PreprocessorDefinitions
318  Value: "WIN32;_DEBUG;_CONSOLE;__WIN32__;__x86__;_WIN32_WINNT=0x0400;__NT__;__OSVERSION__=4;%(PreprocessorDefinitions)"
319  - Key: MinimalRebuild
320  Value: "true"
321  - Key: BasicRuntimeChecks
322  Value: "EnableFastChecks"
323  - Key: RuntimeLibrary
324  Value: "MultiThreadedDebugDLL"
325  - Key: PrecompiledHeader
326  Value: "NotUsing"
327  - Key: WarningLevel
328  Value: "Level3"
329  - Key: Detect64BitPortabilityProblems
330  Value: "false"
331  - Key: DebugInformationFormat
332  Value: "EditAndContinue"
333 # VCManagedResourceCompilerTool:
334 # VCResourceCompilerTool:
335 # VC10_VCPreLinkEventTool:
336  VC10_VCLinkerTool:
337  - Key: AdditionalDependencies
338  Value: ""
339  - Key: OutputFile
340  Value: "$(OutDir)\\\\__PROJECT_NAME__.exe"
341  - Key: LinkIncremental
342  Value: "2"
343  - Key: IgnoreDefaultLibraryNames
344  Value: ""
345  - Key: GenerateDebugInformation
346  Value: "true"
347  - Key: SubSystem
348  Value: "Console"
349  - Key: TargetMachine
350  Value: "MachineX86"
351 # VCALinkTool:
352 # VCManifestTool:
353 # VCXDCMakeTool:
354 # VCBscMakeTool:
355 # VCFxCopTool:
356 # VCAppVerifierTool:
357 # VCWebDeploymentTool:
358  VC_10VCPostBuildEventTool:
359  VCPreLinkEvent: 'lib -out:"$(TargetDir)coil_static.lib" "$(TargetDir)*.obj"
360 set PATH=%PATH%%3b$(coil_path)
361 cd "$(TargetDir)"
362 start /wait cmd /c makedeffile.py coil_static.lib coil$(coil_dllver)d $(coil_version) coil$(coil_dllver)d.def
363 move coil$(coil_dllver)d.def ..\'
364  VC10_VCPostBuildEventTool: 'copy "$(OutDir)\$(TargetName).lib" "$(SolutionDir)bin\\coil$(coil_dllver)d.lib"
365 copy "$(OutDir)\coil$(coil_dllver)d.dll" "$(SolutionDir)bin\\"'
366  VCPreLinkEvent: 'lib -out:"$(TargetDir)coil_static.lib" "$(TargetDir)*.obj"
367 set PATH=%PATH%%3b$(coil_path)
368 cd "$(OutDir)"
369 start /wait cmd /c makedeffile.py coil_static.lib coil$(coil_dllver) $(coil_version) coil$(coil_dllver).def
370 move coil$(coil_dllver).def ..\\'
371  VC10_VCPostBuildEventTool: 'copy "$(OutDir)\$(TargetName).lib" "$(SolutionDir)bin\\coil$(coil_dllver).lib"
372 copy "$(OutDir)\coil$(coil_dllver).dll" "$(SolutionDir)bin\\"'
373 #------------------------------------------------------------
374 # Release Configuration
375 #------------------------------------------------------------
376  - Name: "Release|Win32"
377  VC10_OutputDirectory: $(ProjectDir)$(Configuration)"
378  VC10_IntermediateDirectory: "$(Configuratio)"
379  ConfigurationType: "1"
380 # VC10_InheritedPropertySheets: ""
381  CharacterSet: "0"
382  VC10_LinkIncrementalCondition: "false"
383  WholeProgramOptimization: "0"
384 # VCPreBuildEventTool:
385 # VCCustomBuildTool:
386 # VCXMLDataGeneratorTool:
387 # VCWebServiceProxyGeneratorTool:
388 # VCMIDLTool:
389  VC10_VCCLCompilerTool:
390  - Key: PreprocessorDefinitions
391  Value: "WIN32;NDEBUG;_CONSOLE;__WIN32__;__x86__;_WIN32_WINNT=0x0400;__NT__;__OSVERSION__=4;%(PreprocessorDefinitions)"
392  - Key: RuntimeLibrary
393  Value: "MultiThreadedDLL"
394  - Key: PrecompiledHeader
395  Value: "NotUsing"
396  - Key: WarningLevel
397  Value: "Level3"
398  - Key: Detect64BitPortabilityProblems
399  Value: "false"
400  - Key: DebugInformationFormat
401  Value: "ProgramDatabase"
402 # VCManagedResourceCompilerTool"
403 # VCResourceCompilerTool"
404 # VC10_VCPreLinkEventTool"
405  VC10_VCLinkerTool:
406  - Key: AdditionalDependencies
407  Value: ""
408  - Key: OutputFile
409  Value: "$(OutDir)\\\\__PROJECT_NAME__.exe"
410  - Key: LinkIncremental
411  Value: "1"
412  - Key: GenerateDebugInformation
413  Value: "false"
414  - Key: SubSystem
415  Value: "Console"
416  - Key: OptimizeReferences
417  Value: "true"
418  - Key: EnableCOMDATFolding
419  Value: "true"
420  - Key: LinkTimeCodeGeneration
421  Value: ""
422  - Key: TargetMachine
423  Value: "MachineX86"
424 # VCALinkTool:
425 # VCManifestTool:
426 # VCXDCMakeTool:
427 # VCBscMakeTool:
428 # VCFxCopTool:
429 # VCAppVerifierTool:
430 # VCWebDeploymentTool:
431 # VC10_VCPostBuildEventTool:
432 """
433 exe_yaml = exe_yaml + get_after_config(exe_yaml)
434 
435 dll_yaml = """ProjectType: "Visual C++"
436 Version: "__VCVERSION__"
437 Name: __PROJECT_NAME__
438 ProjectGUID: __GUID__
439 RootNamespace: __PROJECT_NAME__
440 Keyword: "Win32Proj"
441 Configurations:
442  - Name: "Debug|Win32"
443  VC10_OutputDirectory: "$(ProjectDir)$(Configuration)"
444  VC10_IntermediateDirectory: "$(Configuration)"
445  ConfigurationType: "2"
446 # VC10_InheritedPropertySheets: ""
447  CharacterSet: "0"
448  VC10_LinkIncrementalCondition: "true"
449 # VCPreBuildEventTool:
450 # VCCustomBuildTool:
451 # VCXMLDataGeneratorTool:
452 # VCWebServiceProxyGeneratorTool:
453 # VCMIDLTool:
454  VC10_VCCLCompilerTool:
455  - Key: Optimization
456  Value: "Disabled"
457  - Key: PreprocessorDefinitions
458  Value: "WIN32;_DEBUG;_WINDOWS;_USRDLL;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0400;_CRT_SECURE_NO_DEPRECATE"
459  - Key: MinimalRebuild
460  Value: "true"
461  - Key: BasicRuntimeChecks
462  Value: "EnableFastChecks"
463  - Key: RuntimeLibrary
464  Value: "MultiThreadedDebugDLL"
465  - Key: PrecompiledHeader
466  Value: "NotUsing"
467  - Key: WarningLevel
468  Value: "Level3"
469  - Key: Detect64BitPortabilityProblems
470  Value: "false"
471  - Key: DebugInformationFormat
472  Value: "EditAndContinue"
473 # VCManagedResourceCompilerTool:
474 # VCResourceCompilerTool:
475  VC10_VCPreLinkEventTool:
476  - Key: Command
477  Value: |
478  lib -out:"$(TargetDir)RTC_static.lib" "$(TargetDir)*.obj" "$(SolutionDir)\\\\rtm\\\\idl\\\\$(ConfigurationName)\\\\*.obj"
479  set PATH=%PATH%;$(rtm_path)
480  cd $(OutDir)
481  start /wait cmd /c makedeffile.py RTC_static.lib RTC042d 0.4.1 RTC042d.def
482  move RTC042d.def ..\\\\
483  VC10_VCLinkerTool:
484  - Key: AdditionalDependencies
485  Value: ""
486  - Key: OutputFile
487  Value: "$(OutDir)\\\\__PROJECT_NAME__.dll"
488  - Key: Version
489  Value: __VERSION__
490  - Key: LinkIncremental
491  Value: "2"
492  - Key: ModuleDefinitionFile
493  Value: "$(TargetName).def"
494  - Key: GenerateDebugInformation
495  Value: "true"
496  - Key: SubSystem
497  Value: "Windows"
498  - Key: TargetMachine
499  Value: "MachineX86"
500 # VCALinkTool:
501 # VCManifestTool:
502 # VCXDCMakeTool:
503 # VCBscMakeTool:
504 # VCFxCopTool:
505 # VCAppVerifierTool:
506 # VCWebDeploymentTool:
507  VC10_VCPostBuildEventTool:
508  - Key: Command
509  Value: |
510  copy "$(OutDir)\\\\$(TargetName).lib" "$(SolutionDir)bin\\\\"
511  copy "$(OutDir)\\\\$(TargetName).dll" "$(SolutionDir)bin\\\\"
512  - Name: "Release|Win32"
513  VC10_OutputDirectory: "$(ProjectDir)$(Configuration)"
514  VC10_IntermediateDirectory: "$(Configuration)"
515  ConfigurationType: "2"
516  VC10_InheritedPropertySheets: ""
517  CharacterSet: "0"
518  VC10_LinkIncrementalCondition: "false"
519  WholeProgramOptimization: "0"
520 # VCPreBuildEventTool:
521 # VCCustomBuildTool:
522 # VCXMLDataGeneratorTool:
523 # VCWebServiceProxyGeneratorTool:
524 # VCMIDLTool:
525  VC10_VCCLCompilerTool:
526  - Key: PreprocessorDefinitions
527  Value: "WIN32;NDEBUG;_WINDOWS;_USRDLL;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0400;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)"
528  - Key: RuntimeLibrary
529  Value: "MultiThreadedDLL"
530  - Key: UsePrecompiledHeader
531  Value: "NotUsing"
532  - Key: WarningLevel
533  Value: "Level3"
534  - Key: Detect64BitPortabilityProblems
535  Value: "false"
536  - Key: DebugInformationFormat
537  Value: "ProgramDatabase"
538 # VCManagedResourceCompilerTool:
539 # VCResourceCompilerTool:
540  VC10_VCPreLinkEventTool:
541  - Key: Command
542  Value: |
543  lib -out:"$(TargetDir)RTC_static.lib" "$(TargetDir)*.obj" "$(SolutionDir)\\\\rtm\\\\idl\\\\$(ConfigurationName)\\\\*.obj"
544  set PATH=%PATH%;$(rtm_path)
545  cd "$(OutDir)"
546  start /wait cmd /c makedeffile.py RTC_static.lib RTC042 0.4.1 RTC042.def
547  move RTC042.def ..\\\\
548  VC10_VCLinkerTool:
549  - Key: AdditionalDependencies
550  Value: ""
551  - Key: OutputFile
552  Value: "$(OutDir)\\\\__PROJECT_NAME__.dll"
553  - Key: LinkIncremental
554  Value: "1"
555  - Key: ModuleDefinitionFile
556  Value: "$(TargetName).def"
557  - Key: GenerateDebugInformation
558  Value: "false"
559  - Key: SubSystem
560  Value: "Windows"
561  - Key: OptimizeReferences
562  Value: "true"
563  - Key: EnableCOMDATFolding
564  Value: "true"
565  - Key: TargetMachine
566  Value: "MachineX86"
567 # VCALinkTool:
568 # VCManifestTool:
569 # VCXDCMakeTool:
570 # VCBscMakeTool:
571 # VCFxCopTool:
572 # VCAppVerifierTool:
573 # VCWebDeploymentTool:
574  VC10_VCPostBuildEventTool:
575  - Key: Command
576  Value: |
577  copy "$(OutDir)\\\\$(TargetName).lib" "$(SolutionDir)bin\\\\"
578  copy "$(OutDir)\\\\$(TargetName).dll" "$(SolutionDir)bin\\\\"
579 """
580 dll_yaml = dll_yaml + get_after_config(dll_yaml)
581 
582 #------------------------------------------------------------
583 lib_yaml = """ProjectType: "Visual C++"
584 Version: "__VCVERSION__"
585 Name: __PROJECT_NAME__
586 ProjectGUID: __GUID__
587 RootNamespace: __PROJECT_NAME__
588 Keyword: "Win32Proj"
589 Configurations:
590  - Name: "Debug|Win32"
591  VC10_OutputDirectory: "$(ProjectDir)$(Configuration)"
592  VC10_IntermediateDirectory: "$(Configuration)"
593  ConfigurationType: "4"
594 # VC10_InheritedPropertySheets: "..\\\\..\\\\OpenRTM-aist.vsprops"
595  CharacterSet: "0"
596  VC10_LinkIncrementalCondition: "true"
597  DeleteExtensionsOnClean: ""
598  PreBuildEvent:
599  - Key: Command
600  Value: |
601  set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
602  for %%x in (*.idl) do makewrapper.py %%x
603  for %%x in (*.idl) do omniidl -bcxx -Wba -nf %%x
604 # VCCustomBuildTool:
605 # VCXMLDataGeneratorTool:
606 # VCWebServiceProxyGeneratorTool:
607 # VCMIDLTool:
608  VC10_VCCLCompilerTool:
609  - Key: Optimization
610  Value: "Disabled"
611  - Key: PreprocessorDefinitions
612  Value: "WIN32;_DEBUG;_LIB;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0400;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)"
613  - Key: MinimalRebuild
614  Value: "true"
615  - Key: BasicRuntimeChecks
616  Value: "EnableFastChecks"
617  - Key: RuntimeLibrary
618  Value: "MultiThreadedDebugDLL"
619  - Key: PrecompiledHeader
620  Value: "NotUsing"
621  - Key: WarningLevel
622  Value: "Level3"
623  - Key: Detect64BitPortabilityProblems
624  Value: "false"
625  - Key: DebugInformationFormat
626  Value: "EditAndContinue"
627 # VCManagedResourceCompilerTool:
628 # VCResourceCompilerTool:
629 # VC10_VCPreLinkEventTool:
630  VCLibrarianTool:
631  - Key: OutputFile
632  Value: "$(OutDir)\\\\__PROJECT_NAME__.lib"
633 # VCALinkTool:
634 # VCXDCMakeTool:
635 # VCBscMakeTool:
636 # VCFxCopTool:
637  VC10_VCPostBuildEventTool:
638  - Key: Description
639  Value: "make .def file"
640  - Key: Command
641  Value: |
642  copy "$(OutDir)\\\\libRTCSkeld.lib" "$(SolutionDir)\\\\bin"
643  - Name: "Release|Win32"
644  VC10_OutputDirectory: "$(ProjectDir)$(Configuration)"
645  VC10_IntermediateDirectory: "$(Configuration)"
646  ConfigurationType: "4"
647 # VC10_InheritedPropertySheets: "..\\\\..\\\\OpenRTM-aist.vsprops"
648  CharacterSet: "0"
649  VC10_LinkIncrementalCondition: "false"
650  WholeProgramOptimization: "0"
651  PreBuildEvent:
652  - Key: Command
653  Value: |
654  set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
655  for %%x in (*.idl) do makewrapper.py %%x
656  for %%x in (*.idl) do omniidl -bcxx -Wba -nf %%x
657 # VCCustomBuildTool:
658 # VCXMLDataGeneratorTool:
659 # VCWebServiceProxyGeneratorTool:
660 # VCMIDLTool:
661  VC10_VCCLCompilerTool:
662  - Key: PreprocessorDefinitions
663  Value: "WIN32;NDEBUG;_LIB;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0400;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)"
664  - Key: RuntimeLibrary
665  Value: "MultiThreadedDLL"
666  - Key: PrecompiledHeader
667  Value: "NotUsing"
668  - Key: WarningLevel
669  Value: "Level3"
670  - Key: Detect64BitPortabilityProblems
671  Value: "false"
672  - Key: DebugInformationFormat
673  Value: "ProgramDatabase"
674 # VCManagedResourceCompilerTool:
675 # VCResourceCompilerTool:
676 # VC10_VCPreLinkEventTool:
677  VCLibrarianTool:
678  - Key: OutputFile
679  Value: "$(OutDir)\\\\__PROJECT_NAME__.lib"
680 # VCALinkTool:
681 # VCXDCMakeTool:
682 # VCBscMakeTool:
683 # VCFxCopTool:
684  VC10_VCPostBuildEventTool:
685  - Key: Command
686  Value: |
687  copy "$(OutDir)\\\\libRTCSkel.lib" "$(SolutionDir)\\\\bin"
688 """
689 lib_yaml = lib_yaml + get_after_config(lib_yaml)
690 
691 rtcexe_yaml="""ProjectType: "Visual C++"
692 Version: "__VCVERSION__"
693 Name: __PROJECT_NAME__
694 ProjectGUID: __GUID__
695 RootNamespace: __PROJECT_NAME__
696 Keyword: "Win32Proj"
697 Configurations:
698 #------------------------------------------------------------
699 # Debug Configuration
700 #------------------------------------------------------------
701  - Name: "Debug|Win32"
702  VC10_OutputDirectory: "$(ProjectDir)__PROJECT_NAME__\\\\$(Configuration)"
703  VC10_IntermediateDirectory: "__PROJECT_NAME__\\\\$(Configuration)"
704  ConfigurationType: "1"
705  VC10_InheritedPropertySheets:
706  - "$(SolutionDir)user_config.props"
707  - "$(SolutionDir)rtm_config.props"
708  CharacterSet: "0"
709  VC10_LinkIncrementalCondition: "true"
710  PreBuildEvent:
711  - Key: Command
712  Value: |
713  set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
714  for %%x in (*.idl) do rtm-skelwrapper.py --include-dir="" --skel-suffix=Skel --stub-suffix=Stub --idl-file=%%x
715  for %%x in (*.idl) do $(rtm_idlc) $(rtm_idlflags) %%x
716  VC10_VCCLCompilerTool:
717  - Key: Optimization
718  Value: Disabled
719  - Key: PreprocessorDefinitions
720  Value: "USE_stub_in_nt_dll;WIN32;_DEBUG;_CONSOLE;__WIN32__;__x86__;_WIN32_WINNT=0x0400;__NT__;__OSVERSION__=4;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)"
721  - Key: MinimalRebuild
722  Value: "true"
723  - Key: BasicRuntimeChecks
724  Value: "EnableFastChecks"
725  - Key: RuntimeLibrary
726  Value: "MultiThreadedDebugDLL"
727  - Key: PrecompiledHeader
728  Value: "NotUsing"
729  - Key: WarningLevel
730  Value: "Level3"
731  - Key: Detect64BitPortabilityProblems
732  Value: "false"
733  - Key: DebugInformationFormat
734  Value: "EditAndContinue"
735  VC10_VCLinkerTool:
736  - Key: AdditionalDependencies
737  Value: "$(rtm_libd);%(AdditionalDependencies)"
738  - Key: OutputFile
739  Value: "$(OutDir)\\\\__PROJECT_NAME__.exe"
740  - Key: LinkIncremental
741  Value: "2"
742  - Key: GenerateDebugInformation
743  Value: "true"
744  - Key: SubSystem
745  Value: "Console"
746  - Key: TargetMachine
747  Value: "MachineX86"
748 #------------------------------------------------------------
749 # Release Configuration
750 #------------------------------------------------------------
751  - Name: "Release|Win32"
752  VC10_OutputDirectory: "$(ProjectDir)__PROJECT_NAME__\\\\$(Configuration)"
753  VC10_IntermediateDirectory: "__PROJECT_NAME__\\\\$(Configuration)"
754  ConfigurationType: "1"
755  VC10_InheritedPropertySheets:
756  - "$(SolutionDir)user_config.props"
757  - "$(SolutionDir)rtm_config.props"
758  CharacterSet: "0"
759  VC10_LinkIncrementalCondition: "false"
760  WholeProgramOptimization: "0"
761  PreBuildEvent:
762  - Key: Command
763  Value: |
764  set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
765  for %%x in (*.idl) do rtm-skelwrapper.py --include-dir="" --skel-suffix=Skel --stub-suffix=Stub --idl-file=%%x
766  for %%x in (*.idl) do $(rtm_idlc) $(rtm_idlflags) %%x
767  VC10_VCPostBuildEventTool:
768  - Key: Command
769  Value: |
770  if NOT EXIST "$(SolutionDir)\\\\components" mkdir "$(SolutionDir)\\\\components"
771  copy "$(OutDir)\\\\__PROJECT_NAME__.exe" "$(SolutionDir)\\\\components"
772  VC10_VCCLCompilerTool:
773  - Key: PreprocessorDefinitions
774  Value: "USE_stub_in_nt_dll;WIN32;NDEBUG;_CONSOLE;__WIN32__;__x86__;_WIN32_WINNT=0x0400;__NT__;__OSVERSION__=4;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)"
775  - Key: RuntimeLibrary
776  Value: "MultiThreadedDLL"
777  - Key: PrecompiledHeader
778  Value: "NotUsing"
779  - Key: WarningLevel
780  Value: "Level3"
781  - Key: Detect64BitPortabilityProblems
782  Value: "false"
783  - Key: DebugInformationFormat
784  Value: "ProgramDatabase"
785  VC10_VCLinkerTool:
786 
787  - Key: AdditionalDependencies
788  Value: "$(rtm_lib);%(AdditionalDependencies)"
789  - Key: OutputFile
790  Value: "$(OutDir)\\\\__PROJECT_NAME__.exe"
791  - Key: LinkIncremental
792  Value: "1"
793  - Key: GenerateDebugInformation
794  Value: "false"
795  - Key: SubSystem
796  Value: "Console"
797  - Key: OptimizeReferences
798  Value: "true"
799  - Key: EnableCOMDATFolding
800  Value: "true"
801  - Key: LinkTimeCodeGeneration
802  Value: ""
803  - Key: TargetMachine
804  Value: "MachineX86"
805 """
806 rtcexe_yaml = rtcexe_yaml + get_after_config(rtcexe_yaml)
807 
808 rtcdll_yaml="""ProjectType: "Visual C++"
809 Version: "__VCVERSION__"
810 Name: __PROJECT_NAME__
811 ProjectGUID: __GUID__
812 RootNamespace: __PROJECT_NAME__
813 Keyword: "Win32Proj"
814 Configurations:
815 #------------------------------------------------------------
816 # Debug Configuration
817 #------------------------------------------------------------
818  - Name: "Debug|Win32"
819  VC10_OutputDirectory: "$(ProjectDir)__PROJECT_NAME__\\\\$(Configuration)"
820  VC10_IntermediateDirectory: "__PROJECT_NAME__\\\\$(Configuration)"
821  ConfigurationType: "2"
822  VC10_InheritedPropertySheets:
823  - "$(SolutionDir)user_config.props"
824  - "$(SolutionDir)rtm_config.props"
825  CharacterSet: "0"
826  VC10_LinkIncrementalCondition: "true"
827  PreBuildEvent:
828  - Key: Command
829  Value: |
830  set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
831  for %%x in (*.idl) do rtm-skelwrapper.py --include-dir="" --skel-suffix=Skel --stub-suffix=Stub --idl-file=%%x
832  for %%x in (*.idl) do $(rtm_idlc) $(rtm_idlflags) %%x
833  VC10_VCCLCompilerTool:
834  - Key: Optimization
835  Value: "Disabled"
836  - Key: PreprocessorDefinitions
837  Value: "USE_stub_in_nt_dll;WIN32;_DEBUG;_WINDOWS;_USRDLL;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0400;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)"
838  - Key: MinimalRebuild
839  Value: "true"
840  - Key: BasicRuntimeChecks
841  Value: "EnableFastChecks"
842  - Key: RuntimeLibrary
843  Value: "MultiThreadedDebugDLL"
844  - Key: PrecompiledHeader
845  Value: "NotUsing"
846  - Key: WarningLevel
847  Value: "Level3"
848  - Key: Detect64BitPortabilityProblems
849  Value: "false"
850  - Key: DebugInformationFormat
851  Value: "EditAndContinue"
852  VC10_VCLinkerTool:
853  - Key: AdditionalDependencies
854  Value: "$(rtm_libd);%(AdditionalDependencies)"
855 # - Key: OutputFile
856 # Value: "$(OutDir)\\\\__PROJECT_NAME__.dll"
857 # - Key: Version
858 # Value: __VERSION__
859  - Key: LinkIncremental
860  Value: "2"
861 # - Key: ModuleDefinitionFile
862 # Value: "$(TargetName).def"
863  - Key: GenerateDebugInformation
864  Value: "true"
865  - Key: SubSystem
866  Value: "Windows"
867  - Key: TargetMachine
868  Value: "MachineX86"
869 #------------------------------------------------------------
870 # Release Configuration
871 #------------------------------------------------------------
872  - Name: "Release|Win32"
873  VC10_OutputDirectory: "$(ProjectDir)__PROJECT_NAME__\\\\$(Configuration)"
874  VC10_IntermediateDirectory: "__PROJECT_NAME__\\\\$(Configuration)"
875  ConfigurationType: "2"
876  VC10_InheritedPropertySheets:
877  - "$(SolutionDir)user_config.props"
878  - "$(SolutionDir)rtm_config.props"
879  CharacterSet: "0"
880  VC10_LinkIncrementalCondition: "false"
881  WholeProgramOptimization: "0"
882  PreBuildEvent:
883  - Key: Command
884  Value: |
885  set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
886  for %%x in (*.idl) do rtm-skelwrapper.py --include-dir="" --skel-suffix=Skel --stub-suffix=Stub --idl-file=%%x
887  for %%x in (*.idl) do $(rtm_idlc) $(rtm_idlflags) %%x
888  VC10_VCPostBuildEventTool:
889  - Key: Command
890  Value: |
891  if NOT EXIST "$(SolutionDir)\\\\components" mkdir "$(SolutionDir)\\\\components"
892  copy "$(OutDir)\\\\__PROJECT_NAME__.dll" "$(SolutionDir)\\\\components"
893  VC10_VCCLCompilerTool:
894  - Key: PreprocessorDefinitions
895  Value: "USE_stub_in_nt_dll;WIN32;NDEBUG;_WINDOWS;_USRDLL;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0400;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)"
896  - Key: RuntimeLibrary
897  Value: "MultiThreadedDLL"
898  - Key: PrecompiledHeader
899  Value: "NotUsing"
900  - Key: WarningLevel
901  Value: "Level3"
902  - Key: Detect64BitPortabilityProblems
903  Value: "false"
904  - Key: DebugInformationFormat
905  Value: "ProgramDatabase"
906  VC10_VCLinkerTool:
907  - Key: AdditionalDependencies
908  Value: "$(rtm_lib);%(AdditionalDependencies)"
909 # - Key: OutputFile
910 # Value: "$(OutDir)\\\\__PROJECT_NAME__.dll"
911  - Key: LinkIncremental
912  Value: "1"
913 # - Key: ModuleDefinitionFile
914 # Value: "$(TargetName).def"
915  - Key: GenerateDebugInformation
916  Value: "false"
917  - Key: SubSystem
918  Value: "Windows"
919  - Key: OptimizeReferences
920  Value: "true"
921  - Key: EnableCOMDATFolding
922  Value: "true"
923  - Key: TargetMachine
924  Value: "MachineX86"
925 """
926 
927 
928 
929 def usage():
930  print """Usage:
931  vcprojtool.py cmd options
932 commands:
933  vcproj: Generate vcproj
934  yaml : Generate example yaml file
935  flist : Generate file list as yaml
936 examples:
937  vcprojtool.py vcproj --type [exe|dll|nmake|lib]
938  --output out_fname
939  --yaml *.yaml
940  --source *.cpp
941  --header *.h
942  --resource *.txt
943  vcprojtool.py yaml --type [exe|dll|nmake|lib] --output
944  vcprojtool.py flist --out --source|--header|--resource *
945 """
946 rtcdll_yaml = rtcdll_yaml + get_after_config(rtcdll_yaml)
947 
948 import sys
949 
950 #------------------------------------------------------------
951 # Exceptions
952 #------------------------------------------------------------
954  pass
955 
956 class InvalidOption(VCProjException):
957  def __init__(self, msg):
958  self.msg = "Error: InvalidOption:\n "
959  self.msg += msg
960 
962  def __init__(self, msg):
963  self.msg = "Error: InvalidCommand:\n "
964  self.msg += msg
965 
966 #------------------------------------------------------------
967 # VCProject generator class
968 #------------------------------------------------------------
969 class VCProject:
970  def __init__(self, type, yaml_text):
971  import yaml
972  self.type = type
973  self.dict = yaml.load(yaml_text)
974  self.escape_cmdline(self.dict)
975 
976  def generate(self):
977  import yat
979  return self.template.generate(self.dict).replace("\r\n", "\n").replace("\n", "\r\n")
980 
981  def PreBuildEventtool_element(self, type):
982  text = ""
983  for tool in PreBuildEventtools[type]:
984  t = tool_elem % (tool, tool)
985  text += t
986  return text
987 
988  def CLtool_element(self, type):
989  text = ""
990  for tool in Cltools[type]:
991  t = tool_elem % (tool, tool)
992  text += t
993  return text
994 
995  def Libtool_element(self, type):
996  text = ""
997  for tool in Libtools[type]:
998  t = tool_elem % (tool, tool)
999  text += t
1000  return text
1001 
1002  def PreLinkEventtool_element(self, type):
1003  text = ""
1004  for tool in PreLinkEventtools[type]:
1005  t = tool_elem % (tool, tool)
1006  text += t
1007  return text
1008 
1009  def Linktool_element(self, type):
1010  text = ""
1011  for tool in Linktools[type]:
1012  t = tool_elem % (tool, tool)
1013  text += t
1014  return text
1015 
1017  text = ""
1018  for tool in PostBuildEventtools[type]:
1019  t = tool_elem % (tool, tool)
1020  text += t
1021  return text
1022 
1023 
1024  def get_template(self, type):
1025  #return vcxproj_template % (conf_type[type], conf_type[type], self.tool_element(type))
1026  return vcxproj_template % (conf_type[type], self.PreBuildEventtool_element(type), self.CLtool_element(type), self.Libtool_element(type), self.PreLinkEventtool_element(type), self.Linktool_element(type), self.PostBuildEventtool_element(type))
1027 
1028  def escape_cmdline(self, dict):
1029  if not dict.has_key("Configurations"): return
1030 
1031  def escape_cmd(text):
1032  text = text.replace("\"", "&quot;")
1033  text = text.replace("\r\n", "\n")
1034  text = text.replace("\n", "&#x0D;&#x0A;")
1035  return text
1036  from types import DictType, ListType
1037  for conf in dict["Configurations"]:
1038  for tool in conf.keys(): # Tool
1039  if isinstance(conf[tool], ListType):
1040  for keyval in conf[tool]:
1041  if isinstance(keyval, DictType) \
1042  and keyval.has_key("Key") \
1043  and keyval.has_key("Value") \
1044  and keyval["Key"] == "Command":
1045  keyval["Value"] = escape_cmd(keyval["Value"])
1046 
1047 #------------------------------------------------------------
1048 # YAML configuration file generator
1049 #------------------------------------------------------------
1051  def __init__(self, type, vcversion, projectname, version, flist):
1052  self.type = type
1053  self.vcversion = vcversion
1054  self.projectname = projectname
1055  self.version = version
1056  self.flist = flist
1057 
1058  self.yaml_template = {"EXE": exe_yaml, "DLL": dll_yaml, "LIB": lib_yaml,
1059  "RTCEXE": rtcexe_yaml, "RTCDLL": rtcdll_yaml}
1060 
1061  def load_yamls(self, yfiles):
1062  text = ""
1063  for f in yfiles:
1064  fd = open(f, "r")
1065  text += fd.read()
1066  fd.close()
1067  return text
1068 
1069  def replace_uuid(self, text):
1070  import uuid
1071  token0 = text.split("__GUID__")
1072  text0 = token0[0]
1073  for i in range(1, len(token0)):
1074  u = str(uuid.uuid1()).upper()
1075  text0 += u + token0[i]
1076 
1077  token1 = text0.split("__UUID")
1078  text1 = token1[0]
1079  for i in range(1, len(token1)):
1080  u = "_" + str(uuid.uuid1()).replace("-", "")
1081  text1 += u + token1[i]
1082  return text1
1083 
1084  def generate(self):
1085  text = ""
1086  loaded = ""
1087  if self.flist.has_key("yaml") and len(self.flist["yaml"]) > 0:
1088  loaded = self.load_yamls(self.flist["yaml"])
1089 
1090  if loaded.find("ProjectType:") < 0: # No toplevel config
1091  if self.yaml_template.has_key(self.type):
1092  text = self.yaml_template[self.type]
1093  text += loaded
1094  else:
1095  print "type should be specified."
1096  usage()
1097  else:
1098  text = loaded
1099 
1100  print self.flist
1101 
1102  text += FileList(self.flist).generate()
1103 
1104  text = self.replace_uuid(text)
1105  if self.projectname:
1106  text = text.replace("__PROJECT_NAME__", self.projectname)
1107  if self.version:
1108  text = text.replace("__VERSION__", self.version)
1109  if self.vcversion:
1110  text = text.replace("__VCVERSION__", self.vcversion)
1111  text = text.replace("__VCSHORTVER__",
1112  self.vcversion.replace(".",""))
1113  return text
1114 
1115 #------------------------------------------------------------
1116 # File list yaml file generator
1117 #------------------------------------------------------------
1118 class FileList:
1119  def __init__(self, flist):
1120  self.flist = flist
1121  self.filter = {"source":
1122  {"Id": "Source",
1123  "name": "Source Files",
1124  "filter": "cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx",
1125  },
1126  "header":
1127  {"Id": "Header",
1128  "name": "Header Files",
1129  "filter": "h;hpp;hxx;hm;inl;inc;xsd",
1130  },
1131  "resource":
1132  {"Id": "Resoruce",
1133  "name": "Resource Files",
1134  "filter": "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav",
1135  }
1136  }
1137  self.temp = """%s:
1138  Name: %s
1139  Filter: %s
1140  GUID: __GUID__
1141  Files:
1142 """
1143  return
1144 
1145  def generate(self):
1146  text = ""
1147  for f in ["source", "header", "resource"]:
1148  if len(self.flist[f]) > 0:
1149  text += self.temp % \
1150  (self.filter[f]["Id"], self.filter[f]["name"],
1151  self.filter[f]["filter"])
1152  for file in self.flist[f]:
1153  # vcproj's path delimiter should be "\"
1154  file = file.replace("/","\\")
1155  text += " - Path: " + file + "\n"
1156  return text
1157 
1158 
1159 
1160 
1161 
1162 #def generate_vcproj(type, projectname, version, flist):
1163 # yaml_text = ""
1164 # for f in flist["yaml"]:
1165 # fd = open(f, "r")
1166 # yaml_text += fd.read()
1167 # fd.close()
1168 # yaml_text += generate_flist(flist)
1169 # yaml_text = replace_uuid(yaml_text)
1170 # if projectname:
1171 # yaml_text = yaml_text.replace("__PROJECT_NAME__", projectname)
1172 # if version:
1173 # yaml_text = yaml_text.replace("__VERSION__", version)
1174 # vcproj = VCProject(type, yaml_text)
1175 # return vcproj.generate()
1176 #
1177 #
1178 #
1179 #
1180 #def generate_yaml(type, projectname, version, flist):
1181 # yaml_template = {"EXE": exe_yaml, "DLL": dll_yaml, "LIB": lib_yaml}
1182 # text = yaml_template[type]
1183 # text += generate_flist(flist)
1184 # if projectname:
1185 # text = text.replace("__PROJECT_NAME__", projectname)
1186 # if version:
1187 # text = text.replace("__VERSION__", version)
1188 # return text
1189 
1190 #------------------------------------------------------------
1191 # command option
1192 #------------------------------------------------------------
1193 def parse_args(argv):
1194  cmd = argv[0]
1195  if not (cmd == "vcxproj" or cmd == "flist" or cmd == "yaml"):
1196  raise InvalidCommand("no such command: " + cmd)
1197 
1198  outfname = None
1199  type = None
1200  vcversion = None
1201  projectname = None
1202  version = None
1203  flist = {"yaml": [], "source": [], "header": [], "resource": []}
1204  i = 1
1205  argc = len(argv)
1206 
1207  while i < argc:
1208  opt = argv[i]
1209  if opt == "--projectname":
1210  i += 1
1211  if i < argc: projectname = argv[i]
1212  else: raise InvalidOption(opt + " needs value")
1213  elif opt == "--version":
1214  i += 1
1215  if i < argc: version = argv[i]
1216  else: raise InvalidOption(opt + " needs value")
1217  elif opt == "--vcversion":
1218  i += 1
1219  if i < argc: vcversion = argv[i]
1220  else: raise InvalidOption(opt + " needs value")
1221  elif opt == "--output" or opt == "--out" or opt == "-o":
1222  i += 1
1223  if i < argc: outfname = argv[i]
1224  else: raise InvalidOption(opt + " needs value")
1225  elif opt == "--type" or opt == "-t":
1226  i += 1
1227  if i < argc: type = argv[i]
1228  else: raise InvalidOption(opt + " needs value")
1229  type = type.upper()
1230  if not conf_type.has_key(type):
1231  raise InvalidOption("unknown type: "
1232  + type + "\n" +
1233  " --type should be [exe|dll|nmake|lib]")
1234  elif opt[:2] == "--" and flist.has_key(opt[2:]):
1235  lname = opt[2:]
1236  i += 1
1237  if not i < argc: raise InvalidOption(opt + " need value")
1238  while i < argc and argv[i][:2] != "--":
1239  flist[lname].append(argv[i])
1240  i += 1
1241  if len(flist[lname]) == 0:
1242  raise InvalidOption(opt + " needs value")
1243  i -= 1
1244  else:
1245  raise InvalidOption("unknown option: " + opt)
1246  i += 1
1247  return (cmd, vcversion, projectname, version, outfname, type, flist)
1248 
1249 #------------------------------------------------------------
1250 # main function
1251 #------------------------------------------------------------
1252 def main(argv):
1253  if len(argv) == 0:
1254  usage()
1255  sys.exit(-1)
1256 
1257  try:
1258  res = parse_args(argv)
1259  except VCProjException, e:
1260  print "\n" + e.msg + "\n"
1261  usage()
1262  sys.exit(-1)
1263 
1264  cmd = res[0]
1265  vcversion = res[1]
1266  projectname = res[2]
1267  version = res[3]
1268  outfile = res[4]
1269  type = res[5]
1270  flist = res[6]
1271 
1272  if cmd == "vcxproj":
1273  t = VCProject(type,
1274  YamlConfig(type, vcversion,
1275  projectname, version, flist).generate()
1276  ).generate()
1277  elif cmd == "flist":
1278  t = FileList(flist).generate()
1279  elif cmd == "yaml":
1280  t = YamlConfig(type, vcversion, projectname, version, flist).generate()
1281 
1282  if outfile == None:
1283  fd = sys.stdout
1284  else:
1285  fd = open(outfile, "wb")
1286 
1287  fd.write(t)
1288 
1289 #------------------------------------------------------------
1290 # tests
1291 #------------------------------------------------------------
1293  print FileList({"source": ["hoge.cpp", "hage.cpp", "fuga.cpp"],
1294  "header": ["hoge.h", "hage.h", "fuga.h"],
1295  "resource": []}).generate()
1296 
1298  print YamlConfig("EXE", "10.00", "Test", "0.9.1",
1299  {"source":
1300  ["hoge.cpp",
1301  "hage.cpp",
1302  "fuga.cpp"],
1303  "header":
1304  ["hoge.h", "hage.h", "fuga.h"],
1305  "resource":
1306  []}).generate()
1307 
1309  print VCProject("EXE", YamlConfig("EXE", "10.00", "Test", "1.0.0",
1310  {"source":
1311  ["hoge.cpp",
1312  "hage.cpp",
1313  "fuga.cpp"],
1314  "header":
1315  ["hoge.h", "hage.h", "fuga.h"],
1316  "resource":
1317  [],
1318  "yaml":
1319  []}).generate()).generate()
1320 
1321 #------------------------------------------------------------
1322 # entry point
1323 #------------------------------------------------------------
1324 if __name__ == "__main__":
1325 # test_filelist()
1326 # test_yamlconfig()
1327 # test_vcproj()
1328  main(sys.argv[1:])
1329 
def PreLinkEventtool_element(self, type)
def test_yamlconfig()
def __init__(self, flist)
def __init__(self, msg)
Definition: vcxprojtool.py:957
def __init__(self, type, yaml_text)
Definition: vcxprojtool.py:970
def uuid1(node=None, clock_seq=None)
def CLtool_element(self, type)
Definition: vcxprojtool.py:988
def load_yamls(self, yfiles)
def parse_args(argv)
def Linktool_element(self, type)
def test_vcproj()
def escape_cmdline(self, dict)
def __init__(self, type, vcversion, projectname, version, flist)
def Libtool_element(self, type)
Definition: vcxprojtool.py:995
def PreBuildEventtool_element(self, type)
Definition: vcxprojtool.py:981
def replace_uuid(self, text)
def main(argv)
void append(SDOPackage::NVList &dest, const SDOPackage::NVList &src)
Append an element to NVList.
Definition: NVUtil.cpp:354
def get_after_config(text)
Definition: vcxprojtool.py:276
def PostBuildEventtool_element(self, type)
def test_filelist()
def get_template(self, type)
def generate(idl_file, preproc_args, impl_suffix, skel_suffix="Skel", fd_h=None, fd_cpp=None)


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:45