vcprojtool.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # @brief VCProject file generator
00004 # @date $Date: 2008-02-29 04:52:14 $
00005 # @author Norkai Ando <n-ando@aist.go.jp>
00006 #
00007 # Copyright (C) 2008
00008 #     Noriaki Ando
00009 #     Task-intelligence Research Group,
00010 #     Intelligent Systems Research Institute,
00011 #     National Institute of
00012 #         Advanced Industrial Science and Technology (AIST), Japan
00013 #     All rights reserved.
00014 #
00015 # $Id: vcprojtool.py 775 2008-07-28 16:14:45Z n-ando $
00016 #
00017 
00018 #------------------------------------------------------------
00019 # Generic vcproj template
00020 #------------------------------------------------------------
00021 vcproj_template = """<?xml version="1.0" encoding="shift_jis"?>
00022 <VisualStudioProject
00023         ProjectType="[ProjectType]"
00024         Version="[Version]"
00025         Name="[RootNamespace]"
00026         ProjectGUID="{[ProjectGUID]}"
00027         RootNamespace="[RootNamespace]"
00028         Keyword="Win32Proj"
00029         >
00030         <Platforms>
00031                 <Platform
00032                         Name="Win32"
00033                 />
00034         </Platforms>
00035         <ToolFiles>
00036         </ToolFiles>
00037         <Configurations>
00038 [for conf in Configurations]
00039                 <Configuration
00040                         Name="[conf.Name]"
00041                         OutputDirectory="[conf.OutputDirectory]"
00042                         IntermediateDirectory="[conf.IntermediateDirectory]"
00043                         ConfigurationType="%d"
00044                         CharacterSet="0"
00045 [if-any conf.InheritedPropertySheets]
00046                         InheritedPropertySheets="[conf.InheritedPropertySheets]"
00047 [endif]
00048                         >
00049 %s
00050                 </Configuration>
00051 [endfor]
00052         </Configurations>
00053         <References>
00054         </References>
00055         <Files>
00056 [if-any Source]
00057                 <Filter
00058                         Name="[Source.Name]"
00059                         Filter="[Source.Filter]"
00060                         UniqueIdentifier="{[Source.GUID]}"
00061                         >
00062 [if-any Source.Files][for file in Source.Files]
00063                         <File
00064                                 RelativePath="[file.Path]"
00065                                 >
00066                         </File>
00067 [endfor][endif]
00068                 </Filter>
00069 [endif]
00070 [if-any Header]
00071                 <Filter
00072                         Name="[Header.Name]"
00073                         Filter="[Header.Filter]"
00074                         UniqueIdentifier="{[Header.GUID]}"
00075                         >
00076 [if-any Header.Files][for file in Header.Files]
00077                         <File
00078                                 RelativePath="[file.Path]"
00079                                 >
00080                         </File>
00081 [endfor][endif]
00082                 </Filter>
00083 [endif]
00084 [if-any Resource]
00085                 <Filter
00086                         Name="[Resource.Name]"
00087                         Filter="[Resource.Filter]"
00088                         UniqueIdentifier="{[Resource.GUID]}"
00089                         >
00090 [if-any Resoruce.Files][for file in Resoruce.Files]
00091                         <File
00092                                 RelativePath="[file.Path]"
00093                                 >
00094                         </File>
00095 [endfor][endif]
00096                 </Filter>
00097 [endif]
00098         </Files>
00099         <Globals>
00100         </Globals>
00101 </VisualStudioProject>
00102 """
00103 
00104 #------------------------------------------------------------
00105 # ConfigurationType
00106 #------------------------------------------------------------
00107 conf_type = {"EXE": 1, "DLL": 2, "NMAKE": 3, "LIB": 4,
00108              "RTCEXE": 1, "RTCDLL": 2}
00109 
00110 #------------------------------------------------------------
00111 # Tool set for configuration
00112 #------------------------------------------------------------
00113 tools = {"EXE":
00114              ["VCPreBuildEventTool",
00115               "VCCustomBuildTool",
00116               "VCXMLDataGeneratorTool",
00117               "VCWebServiceProxyGeneratorTool",
00118               "VCMIDLTool",
00119               "VCCLCompilerTool",
00120               "VCManagedResourceCompilerTool",
00121               "VCResourceCompilerTool",
00122               "VCPreLinkEventTool",
00123               "VCLinkerTool",
00124               "VCALinkTool",
00125               "VCManifestTool",
00126               "VCXDCMakeTool",
00127               "VCBscMakeTool",
00128               "VCFxCopTool",
00129               "VCAppVerifierTool",
00130               "VCWebDeploymentTool",
00131               "VCPostBuildEventTool"],
00132          "DLL":
00133              ["VCPreBuildEventTool",
00134               "VCCustomBuildTool",
00135               "VCXMLDataGeneratorTool",
00136               "VCWebServiceProxyGeneratorTool",
00137               "VCMIDLTool",
00138               "VCCLCompilerTool",
00139               "VCManagedResourceCompilerTool",
00140               "VCResourceCompilerTool",
00141               "VCPreLinkEventTool",
00142               "VCLinkerTool",
00143               "VCALinkTool",
00144               "VCManifestTool",
00145               "VCXDCMakeTool",
00146               "VCBscMakeTool",
00147               "VCFxCopTool",
00148               "VCAppVerifierTool",
00149               "VCWebDeploymentTool",
00150               "VCPostBuildEventTool"],
00151          "LIB":
00152              ["VCPreBuildEventTool",
00153               "VCCustomBuildTool",
00154               "VCXMLDataGeneratorTool",
00155               "VCWebServiceProxyGeneratorTool",
00156               "VCMIDLTool",
00157               "VCCLCompilerTool",
00158               "VCManagedResourceCompilerTool",
00159               "VCResourceCompilerTool",
00160               "VCPreLinkEventTool",
00161               "VCLibrarianTool",
00162               "VCALinkTool",
00163               "VCXDCMakeTool",
00164               "VCBscMakeTool",
00165               "VCFxCopTool",
00166               "VCPostBuildEventTool"]
00167          }
00168 tools["RTCEXE"] = tools["EXE"]
00169 tools["RTCDLL"] = tools["DLL"]
00170 
00171 
00172 #------------------------------------------------------------
00173 # Tool element
00174 #------------------------------------------------------------
00175 tool_elem = """                 <Tool
00176                                 Name="%s"
00177 [if-any conf.%s][for tool in conf.%s]
00178 [if-any tool.Key]
00179                                 [tool.Key]="[tool.Value]"
00180 [endif]
00181 [endfor][endif]
00182                         />
00183 """
00184 
00185 
00186 exeproj_yaml = """
00187 ProjectType: Visual C++
00188 Version: 8.00
00189 Name: # Your Project Name
00190 ProjectGUID: __GUID__
00191 RootNamespace: 
00192 Keyword: Win32Proj
00193 Platforms:
00194   Platform:
00195     Name: Win32
00196 Configurations:
00197   - Name: Debug
00198     OutputDirectory: $(ProjectDir)$(ConfigurationName)
00199     IntermediateDirectory: $(ConfigurationName)
00200     InheritedPropertySheets: # Set vsprops file if you need
00201 """
00202 
00203 
00204 #------------------------------------------------------------
00205 # Yaml template
00206 #------------------------------------------------------------
00207 exe_yaml = """ProjectType: "Visual C++"
00208 Version: "8.00"
00209 Name: __PROJECT_NAME__
00210 ProjectGUID: __GUID__
00211 RootNamespace: __PROJECT_NAME__
00212 Keyword: "Win32Proj"
00213 Configurations:
00214 #------------------------------------------------------------
00215 # Debug Configuration
00216 #------------------------------------------------------------
00217   - Name: "Debug|Win32"
00218     OutputDirectory: $(ProjectDir)$(ConfigurationName)"
00219     IntermediateDirectory: "$(ConfiguratioName)"
00220     ConfigurationType: "1"
00221 #    InheritedPropertySheets:
00222     CharacterSet: "0"
00223 #    VCPreBuildEventTool:
00224 #    VCCustomBuildTool:
00225 #    VCXMLDataGeneratorTool:
00226 #    VCWebServiceProxyGeneratorTool:
00227 #    VCMIDLTool:
00228     VCCLCompilerTool:
00229       - Key: Optimization
00230         Value: 0
00231       - Key: PreprocessorDefinitions
00232         Value: "WIN32;_DEBUG;_CONSOLE;__WIN32__;__x86__;_WIN32_WINNT=0x0500;__NT__;__OSVERSION__=4"
00233       - Key: MinimalRebuild
00234         Value: "true"
00235       - Key: BasicRuntimeChecks
00236         Value: "3"
00237       - Key: RuntimeLibrary
00238         Value: "3"
00239       - Key: UsePrecompiledHeader
00240         Value: "0"
00241       - Key: WarningLevel
00242         Value: "3"
00243       - Key: Detect64BitPortabilityProblems
00244         Value: "false"
00245       - Key: DebugInformationFormat
00246         Value: "4"
00247 #    VCManagedResourceCompilerTool:
00248 #    VCResourceCompilerTool:
00249 #    VCPreLinkEventTool:
00250     VCLinkerTool:
00251       - Key: AdditionalDependencies
00252         Value: ""
00253       - Key: OutputFile
00254         Value: "$(OutDir)\\\\__PROJECT_NAME__.exe"
00255       - Key: LinkIncremental
00256         Value: "2"
00257       - Key: IgnoreDefaultLibraryNames
00258         Value: ""
00259       - Key: GenerateDebugInformation
00260         Value: "true"
00261       - Key: SubSystem
00262         Value: "1"
00263       - Key: TargetMachine
00264         Value: "1"
00265 #    VCALinkTool:
00266 #    VCManifestTool:
00267 #    VCXDCMakeTool:
00268 #    VCBscMakeTool:
00269 #    VCFxCopTool:
00270 #    VCAppVerifierTool:
00271 #    VCWebDeploymentTool:
00272     VCPostBuildEventTool:
00273 #------------------------------------------------------------
00274 # Release Configuration
00275 #------------------------------------------------------------
00276   - Name: "Release|Win32"
00277     OutputDirectory: $(ProjectDir)$(ConfigurationName)"
00278     IntermediateDirectory: "$(ConfiguratioName)"
00279     ConfigurationType: "1"
00280     InheritedPropertySheets: ""
00281     CharacterSet: "0"
00282     WholeProgramOptimization: "0"
00283 #    VCPreBuildEventTool:
00284 #    VCCustomBuildTool:
00285 #    VCXMLDataGeneratorTool:
00286 #    VCWebServiceProxyGeneratorTool:
00287 #    VCMIDLTool:
00288     VCCLCompilerTool:
00289       - Key: PreprocessorDefinitions
00290         Value: "WIN32;NDEBUG;_CONSOLE;__WIN32__;__x86__;_WIN32_WINNT=0x0500;__NT__;__OSVERSION__=4"
00291       - Key: RuntimeLibrary
00292         Value: "2"
00293       - Key: UsePrecompiledHeader
00294         Value: "0"
00295       - Key: WarningLevel
00296         Value: "3"
00297       - Key: Detect64BitPortabilityProblems
00298         Value: "false"
00299       - Key: DebugInformationFormat
00300         Value: "3"
00301 #    VCManagedResourceCompilerTool"
00302 #    VCResourceCompilerTool"
00303 #    VCPreLinkEventTool"
00304     VCLinkerTool:
00305       - Key: AdditionalDependencies
00306         Value: ""
00307       - Key: OutputFile
00308         Value: "$(OutDir)\\\\__PROJECT_NAME__.exe"
00309       - Key: LinkIncremental
00310         Value: "1"
00311       - Key: GenerateDebugInformation
00312         Value: "false"
00313       - Key: SubSystem
00314         Value: "1"
00315       - Key: OptimizeReferences
00316         Value: "2"
00317       - Key: EnableCOMDATFolding
00318         Value: "2"
00319       - Key: LinkTimeCodeGeneration
00320         Value: "0"
00321       - Key: TargetMachine
00322         Value: "1"
00323 #    VCALinkTool:
00324 #    VCManifestTool:
00325 #    VCXDCMakeTool:
00326 #    VCBscMakeTool:
00327 #    VCFxCopTool:
00328 #    VCAppVerifierTool:
00329 #    VCWebDeploymentTool:
00330 #    VCPostBuildEventTool:
00331 """
00332 
00333 dll_yaml = """ProjectType: "Visual C++"
00334 Version: "8.00"
00335 Name: __PROJECT_NAME__
00336 ProjectGUID: __GUID__
00337 RootNamespace: __PROJECT_NAME__
00338 Keyword: "Win32Proj"
00339 Configurations:
00340   - Name: "Debug|Win32"
00341     OutputDirectory: "$(ProjectDir)$(ConfigurationName)"
00342     IntermediateDirectory: "$(ConfigurationName)"
00343     ConfigurationType: "2"
00344 #    InheritedPropertySheets: ""
00345     CharacterSet: "0"
00346 #    VCPreBuildEventTool:
00347 #    VCCustomBuildTool:
00348 #    VCXMLDataGeneratorTool:
00349 #    VCWebServiceProxyGeneratorTool:
00350 #    VCMIDLTool:
00351     VCCLCompilerTool:
00352       - Key: Optimization
00353         Value: "0"
00354       - Key: PreprocessorDefinitions
00355         Value: "WIN32;_DEBUG;_WINDOWS;_USRDLL;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0500;_CRT_SECURE_NO_DEPRECATE"
00356       - Key: MinimalRebuild
00357         Value: "true"
00358       - Key: BasicRuntimeChecks
00359         Value: "3"
00360       - Key: RuntimeLibrary
00361         Value: "3"
00362       - Key: UsePrecompiledHeader
00363         Value: "0"
00364       - Key: WarningLevel
00365         Value: "3"
00366       - Key: Detect64BitPortabilityProblems
00367         Value: "false"
00368       - Key: DebugInformationFormat
00369         Value: "4"
00370 #    VCManagedResourceCompilerTool:
00371 #    VCResourceCompilerTool:
00372     VCPreLinkEventTool:
00373       - Key: CommandLine
00374         Value: |
00375           lib -out:"$(TargetDir)RTC_static.lib" "$(TargetDir)*.obj" "$(SolutionDir)\\\\rtm\\\\idl\\\\$(ConfigurationName)\\\\*.obj"
00376           set PATH=%PATH%;$(rtm_path)
00377           cd $(OutDir)
00378           start /wait cmd /c makedeffile.py RTC_static.lib RTC042d 0.4.1 RTC042d.def
00379           move RTC042d.def ..\\\\
00380     VCLinkerTool:
00381       - Key: AdditionalDependencies
00382         Value: ""
00383       - Key: OutputFile
00384         Value: "$(OutDir)\\\\__PROJECT_NAME__.dll"
00385       - Key: Version
00386         Value: __VERSION__
00387       - Key: LinkIncremental
00388         Value: "2"
00389       - Key: ModuleDefinitionFile
00390         Value: "$(TargetName).def"
00391       - Key: GenerateDebugInformation
00392         Value: "true"
00393       - Key: SubSystem
00394         Value: "2"
00395       - Key: TargetMachine
00396         Value: "1"
00397 #    VCALinkTool:
00398 #    VCManifestTool:
00399 #    VCXDCMakeTool:
00400 #    VCBscMakeTool:
00401 #    VCFxCopTool:
00402 #    VCAppVerifierTool:
00403 #    VCWebDeploymentTool:
00404     VCPostBuildEventTool:
00405       - Key: CommandLine
00406         Value: |
00407           copy "$(OutDir)\\\\$(TargetName).lib" "$(SolutionDir)bin\\\\"
00408           copy "$(OutDir)\\\\$(TargetName).dll" "$(SolutionDir)bin\\\\"
00409   - Name: "Release|Win32"
00410     OutputDirectory: "$(ProjectDir)$(ConfigurationName)"
00411     IntermediateDirectory: "$(ConfigurationName)"
00412     ConfigurationType: "2"
00413     InheritedPropertySheets: ""
00414     CharacterSet: "0"
00415     WholeProgramOptimization: "0"
00416 #    VCPreBuildEventTool:
00417 #    VCCustomBuildTool:
00418 #    VCXMLDataGeneratorTool:
00419 #    VCWebServiceProxyGeneratorTool:
00420 #    VCMIDLTool:
00421     VCCLCompilerTool:
00422       - Key: PreprocessorDefinitions
00423         Value: "WIN32;NDEBUG;_WINDOWS;_USRDLL;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0500;_CRT_SECURE_NO_DEPRECATE"
00424       - Key:         RuntimeLibrary
00425         Value: "2"
00426       - Key:         UsePrecompiledHeader
00427         Value: "0"
00428       - Key:         WarningLevel
00429         Value: "3"
00430       - Key:         Detect64BitPortabilityProblems
00431         Value: "false"
00432       - Key:         DebugInformationFormat
00433         Value: "3"
00434 #    VCManagedResourceCompilerTool:
00435 #    VCResourceCompilerTool:
00436     VCPreLinkEventTool:
00437       - Key: CommandLine
00438         Value: |
00439           lib -out:"$(TargetDir)RTC_static.lib" "$(TargetDir)*.obj" "$(SolutionDir)\\\\rtm\\\\idl\\\\$(ConfigurationName)\\\\*.obj"
00440           set PATH=%PATH%;$(rtm_path)
00441           cd "$(OutDir)"
00442           start /wait cmd /c makedeffile.py RTC_static.lib RTC042 0.4.1 RTC042.def
00443           move RTC042.def ..\\\\
00444     VCLinkerTool:
00445       - Key: AdditionalDependencies
00446         Value: ""
00447       - Key: OutputFile
00448         Value: "$(OutDir)\\\\__PROJECT_NAME__.dll"
00449       - Key: LinkIncremental
00450         Value: "1"
00451       - Key: ModuleDefinitionFile
00452         Value: "$(TargetName).def"
00453       - Key: GenerateDebugInformation
00454         Value: "false"
00455       - Key: SubSystem
00456         Value: "2"
00457       - Key: OptimizeReferences
00458         Value: "2"
00459       - Key: EnableCOMDATFolding
00460         Value: "2"
00461       - Key: TargetMachine
00462         Value: "1"
00463 #    VCALinkTool:
00464 #    VCManifestTool:
00465 #    VCXDCMakeTool:
00466 #    VCBscMakeTool:
00467 #    VCFxCopTool:
00468 #    VCAppVerifierTool:
00469 #    VCWebDeploymentTool:
00470     VCPostBuildEventTool:
00471       - Key: CommandLine
00472         Value: |
00473           copy "$(OutDir)\\\\$(TargetName).lib" "$(SolutionDir)bin\\\\"
00474           copy "$(OutDir)\\\\$(TargetName).dll" "$(SolutionDir)bin\\\\"
00475 """
00476 #------------------------------------------------------------
00477 lib_yaml = """ProjectType: "Visual C++"
00478 Version: "8.00"
00479 Name: __PROJECT_NAME__
00480 ProjectGUID: __GUID__
00481 RootNamespace: __PROJECT_NAME__
00482 Keyword: "Win32Proj"
00483 Configurations:
00484   - Name: "Debug|Win32"
00485     OutputDirectory: "$(ProjectDir)$(ConfigurationName)"
00486     IntermediateDirectory: "$(ConfigurationName)"
00487     ConfigurationType: "4"
00488 #    InheritedPropertySheets: "..\\\\..\\\\OpenRTM-aist.vsprops"
00489     CharacterSet: "0"
00490     DeleteExtensionsOnClean: ""
00491     PreBuildEventTool:
00492       - Key: CommandLine
00493         Value: |
00494           set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
00495           for %%x in (*.idl) do makewrapper.py %%x
00496           for %%x in (*.idl) do omniidl -bcxx -Wba -nf %%x
00497 #    VCCustomBuildTool:
00498 #    VCXMLDataGeneratorTool:
00499 #    VCWebServiceProxyGeneratorTool:
00500 #    VCMIDLTool:
00501     VCCLCompilerTool:
00502       - Key: Optimization
00503         Value: "0"
00504       - Key: PreprocessorDefinitions
00505         Value: "WIN32;_DEBUG;_LIB;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0500;_CRT_SECURE_NO_DEPRECATE"
00506       - Key: MinimalRebuild
00507         Value: "true"
00508       - Key: BasicRuntimeChecks
00509         Value: "3"
00510       - Key: RuntimeLibrary
00511         Value: "3"
00512       - Key: UsePrecompiledHeader
00513         Value: "0"
00514       - Key: WarningLevel
00515         Value: "3"
00516       - Key: Detect64BitPortabilityProblems
00517         Value: "false"
00518       - Key: DebugInformationFormat
00519         Value: "4"
00520 #    VCManagedResourceCompilerTool:
00521 #    VCResourceCompilerTool:
00522 #    VCPreLinkEventTool:
00523     VCLibrarianTool:
00524       - Key: OutputFile
00525         Value: "$(OutDir)\\\\__PROJECT_NAME__.lib"
00526 #    VCALinkTool:
00527 #    VCXDCMakeTool:
00528 #    VCBscMakeTool:
00529 #    VCFxCopTool:
00530     VCPostBuildEventTool:
00531       - Key: Description
00532         Value: "make .def file"
00533       - Key: CommandLine
00534         Value: |
00535           copy "$(OutDir)\\\\libRTCSkeld.lib" "$(SolutionDir)\\\\bin"
00536   - Name: "Release|Win32"
00537     OutputDirectory: "$(ProjectDir)$(ConfigurationName)"
00538     IntermediateDirectory: "$(ConfigurationName)"
00539     ConfigurationType: "4"
00540 #    InheritedPropertySheets: "..\\\\..\\\\OpenRTM-aist.vsprops"
00541     CharacterSet: "0"
00542     WholeProgramOptimization: "0"
00543     VCPreBuildEventTool:
00544       - Key: CommandLine
00545         Value: |
00546           set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
00547           for %%x in (*.idl) do makewrapper.py %%x
00548           for %%x in (*.idl) do omniidl -bcxx -Wba -nf %%x
00549 #    VCCustomBuildTool:
00550 #    VCXMLDataGeneratorTool:
00551 #    VCWebServiceProxyGeneratorTool:
00552 #    VCMIDLTool:
00553     VCCLCompilerTool:
00554       - Key: PreprocessorDefinitions
00555         Value: "WIN32;NDEBUG;_LIB;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0500;_CRT_SECURE_NO_DEPRECATE"
00556       - Key: RuntimeLibrary
00557         Value: "2"
00558       - Key: UsePrecompiledHeader
00559         Value: "0"
00560       - Key: WarningLevel
00561         Value: "3"
00562       - Key: Detect64BitPortabilityProblems
00563         Value: "false"
00564       - Key: DebugInformationFormat
00565         Value: "3"
00566 #    VCManagedResourceCompilerTool:
00567 #    VCResourceCompilerTool:
00568 #    VCPreLinkEventTool:
00569     VCLibrarianTool:
00570       - Key: OutputFile
00571         Value: "$(OutDir)\\\\__PROJECT_NAME__.lib"
00572 #    VCALinkTool:
00573 #    VCXDCMakeTool:
00574 #    VCBscMakeTool:
00575 #    VCFxCopTool:
00576     VCPostBuildEventTool:
00577       - Key: CommandLine
00578         Value: |
00579           copy "$(OutDir)\\\\libRTCSkel.lib" "$(SolutionDir)\\\\bin"
00580 """
00581 
00582 
00583 rtcexe_yaml="""ProjectType: "Visual C++"
00584 Version: "__VCVERSION__"
00585 Name: __PROJECT_NAME__
00586 ProjectGUID: __GUID__
00587 RootNamespace: __PROJECT_NAME__
00588 Keyword: "Win32Proj"
00589 Configurations:
00590 #------------------------------------------------------------
00591 # Debug Configuration
00592 #------------------------------------------------------------
00593   - Name: "Debug|Win32"
00594     OutputDirectory: "$(ProjectDir)__PROJECT_NAME__\\\\$(ConfigurationName)"
00595     IntermediateDirectory: "__PROJECT_NAME__\\\\$(ConfigurationName)"
00596     ConfigurationType: "1"
00597     InheritedPropertySheets: "$(SolutionDir)rtm_config.vsprops;$(SolutionDir)user_config.vsprops"
00598     CharacterSet: "0"
00599     VCPreBuildEventTool:
00600       - Key: CommandLine
00601         Value: |
00602           set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
00603           for %%x in (*.idl) do rtm-skelwrapper.py --include-dir="" --skel-suffix=Skel --stub-suffix=Stub --idl-file=%%x
00604           for %%x in (*.idl) do $(rtm_idlc) $(rtm_idlflags) %%x
00605     VCCLCompilerTool:
00606       - Key: Optimization
00607         Value: 0
00608       - Key: PreprocessorDefinitions
00609         Value: "USE_stub_in_nt_dll;WIN32;_DEBUG;_CONSOLE;__WIN32__;__x86__;_WIN32_WINNT=0x0500;__NT__;__OSVERSION__=4;_CRT_SECURE_NO_DEPRECATE"
00610       - Key: MinimalRebuild
00611         Value: "true"
00612       - Key: BasicRuntimeChecks
00613         Value: "3"
00614       - Key: RuntimeLibrary
00615         Value: "3"
00616       - Key: UsePrecompiledHeader
00617         Value: "0"
00618       - Key: WarningLevel
00619         Value: "3"
00620       - Key: Detect64BitPortabilityProblems
00621         Value: "true"
00622       - Key: DebugInformationFormat
00623         Value: "4"
00624     VCLinkerTool:
00625       - Key: AdditionalDependencies
00626         Value: "$(rtm_libd)"
00627       - Key: OutputFile
00628         Value: "$(OutDir)\\\\__PROJECT_NAME__.exe"
00629       - Key: LinkIncremental
00630         Value: "2"
00631       - Key: GenerateDebugInformation
00632         Value: "true"
00633       - Key: SubSystem
00634         Value: "1"
00635       - Key: TargetMachine
00636         Value: "1"
00637 #------------------------------------------------------------
00638 # Release Configuration
00639 #------------------------------------------------------------
00640   - Name: "Release|Win32"
00641     OutputDirectory: "$(ProjectDir)__PROJECT_NAME__\\\\$(ConfigurationName)"
00642     IntermediateDirectory: "__PROJECT_NAME__\\\\$(ConfigurationName)"
00643     ConfigurationType: "1"
00644     InheritedPropertySheets: "$(SolutionDir)rtm_config.vsprops;$(SolutionDir)user_config.vsprops"
00645     CharacterSet: "0"
00646     WholeProgramOptimization: "0"
00647     VCPreBuildEventTool:
00648       - Key: CommandLine
00649         Value: |
00650           set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
00651           for %%x in (*.idl) do rtm-skelwrapper.py --include-dir="" --skel-suffix=Skel --stub-suffix=Stub --idl-file=%%x
00652           for %%x in (*.idl) do $(rtm_idlc) $(rtm_idlflags) %%x
00653     VCPostBuildEventTool:
00654       - Key: CommandLine
00655         Value: |
00656           if NOT EXIST "$(SolutionDir)\\\\components" mkdir "$(SolutionDir)\\\\components"
00657           copy "$(OutDir)\\\\__PROJECT_NAME__.exe" "$(SolutionDir)\\\\components"
00658     VCCLCompilerTool:
00659       - Key: PreprocessorDefinitions
00660         Value: "USE_stub_in_nt_dll;WIN32;NDEBUG;_CONSOLE;__WIN32__;__x86__;_WIN32_WINNT=0x0500;__NT__;__OSVERSION__=4;_CRT_SECURE_NO_DEPRECATE"
00661       - Key: RuntimeLibrary
00662         Value: "2"
00663       - Key: UsePrecompiledHeader
00664         Value: "0"
00665       - Key: WarningLevel
00666         Value: "3"
00667       - Key: Detect64BitPortabilityProblems
00668         Value: "true"
00669       - Key: DebugInformationFormat
00670         Value: "3"
00671     VCLinkerTool:
00672       - Key: AdditionalDependencies
00673         Value: "$(rtm_lib)"
00674       - Key: OutputFile
00675         Value: "$(OutDir)\\\\__PROJECT_NAME__.exe"
00676       - Key: LinkIncremental
00677         Value: "1"
00678       - Key: GenerateDebugInformation
00679         Value: "false"
00680       - Key: SubSystem
00681         Value: "1"
00682       - Key: OptimizeReferences
00683         Value: "2"
00684       - Key: EnableCOMDATFolding
00685         Value: "2"
00686       - Key: LinkTimeCodeGeneration
00687         Value: "0"
00688       - Key: TargetMachine
00689         Value: "1"
00690 """
00691 
00692 rtcdll_yaml="""ProjectType: "Visual C++"
00693 Version: "__VCVERSION__"
00694 Name: __PROJECT_NAME__
00695 ProjectGUID: __GUID__
00696 RootNamespace: __PROJECT_NAME__
00697 Keyword: "Win32Proj"
00698 Configurations:
00699 #------------------------------------------------------------
00700 # Debug Configuration
00701 #------------------------------------------------------------
00702   - Name: "Debug|Win32"
00703     OutputDirectory: "$(ProjectDir)__PROJECT_NAME__\\\\$(ConfigurationName)"
00704     IntermediateDirectory: "__PROJECT_NAME__\\\\$(ConfigurationName)"
00705     ConfigurationType: "2"
00706     InheritedPropertySheets: "$(SolutionDir)rtm_config.vsprops;$(SolutionDir)user_config.vsprops"
00707     CharacterSet: "0"
00708     VCPreBuildEventTool:
00709       - Key: CommandLine
00710         Value: |
00711           set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
00712           for %%x in (*.idl) do rtm-skelwrapper.py --include-dir="" --skel-suffix=Skel --stub-suffix=Stub --idl-file=%%x
00713           for %%x in (*.idl) do $(rtm_idlc) $(rtm_idlflags) %%x
00714     VCCLCompilerTool:
00715       - Key: Optimization
00716         Value: "0"
00717       - Key: PreprocessorDefinitions
00718         Value: "USE_stub_in_nt_dll;WIN32;_DEBUG;_WINDOWS;_USRDLL;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0500;_CRT_SECURE_NO_DEPRECATE"
00719       - Key: MinimalRebuild
00720         Value: "true"
00721       - Key: BasicRuntimeChecks
00722         Value: "3"
00723       - Key: RuntimeLibrary
00724         Value: "3"
00725       - Key: UsePrecompiledHeader
00726         Value: "0"
00727       - Key: WarningLevel
00728         Value: "3"
00729       - Key: Detect64BitPortabilityProblems
00730         Value: "true"
00731       - Key: DebugInformationFormat
00732         Value: "4"
00733     VCLinkerTool:
00734       - Key: AdditionalDependencies
00735         Value: "$(rtm_libd)"
00736 #      - Key: OutputFile
00737 #        Value: "$(OutDir)\\\\__PROJECT_NAME__.dll"
00738 #      - Key: Version
00739 #        Value: __VERSION__
00740       - Key: LinkIncremental
00741         Value: "2"
00742 #      - Key: ModuleDefinitionFile
00743 #        Value: "$(TargetName).def"
00744       - Key: GenerateDebugInformation
00745         Value: "true"
00746       - Key: SubSystem
00747         Value: "2"
00748       - Key: TargetMachine
00749         Value: "1"
00750 #------------------------------------------------------------
00751 # Release Configuration
00752 #------------------------------------------------------------
00753   - Name: "Release|Win32"
00754     OutputDirectory: "$(ProjectDir)__PROJECT_NAME__\\\\$(ConfigurationName)"
00755     IntermediateDirectory: "__PROJECT_NAME__\\\\$(ConfigurationName)"
00756     ConfigurationType: "2"
00757     InheritedPropertySheets: "$(SolutionDir)rtm_config.vsprops;$(SolutionDir)user_config.vsprops"
00758     CharacterSet: "0"
00759     WholeProgramOptimization: "0"
00760     VCPreBuildEventTool:
00761       - Key: CommandLine
00762         Value: |
00763           set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
00764           for %%x in (*.idl) do rtm-skelwrapper.py --include-dir="" --skel-suffix=Skel --stub-suffix=Stub --idl-file=%%x
00765           for %%x in (*.idl) do $(rtm_idlc) $(rtm_idlflags) %%x
00766     VCPostBuildEventTool:
00767       - Key: CommandLine
00768         Value: |
00769           if NOT EXIST "$(SolutionDir)\\\\components" mkdir "$(SolutionDir)\\\\components"
00770           copy "$(OutDir)\\\\__PROJECT_NAME__.dll" "$(SolutionDir)\\\\components"
00771     VCCLCompilerTool:
00772       - Key: PreprocessorDefinitions
00773         Value: "USE_stub_in_nt_dll;WIN32;NDEBUG;_WINDOWS;_USRDLL;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0500;_CRT_SECURE_NO_DEPRECATE"
00774       - Key:         RuntimeLibrary
00775         Value: "2"
00776       - Key:         UsePrecompiledHeader
00777         Value: "0"
00778       - Key:         WarningLevel
00779         Value: "3"
00780       - Key:         Detect64BitPortabilityProblems
00781         Value: "true"
00782       - Key:         DebugInformationFormat
00783         Value: "3"
00784     VCLinkerTool:
00785       - Key: AdditionalDependencies
00786         Value: "$(rtm_lib)"
00787 #      - Key: OutputFile
00788 #        Value: "$(OutDir)\\\\__PROJECT_NAME__.dll"
00789       - Key: LinkIncremental
00790         Value: "1"
00791 #      - Key: ModuleDefinitionFile
00792 #        Value: "$(TargetName).def"
00793       - Key: GenerateDebugInformation
00794         Value: "false"
00795       - Key: SubSystem
00796         Value: "2"
00797       - Key: OptimizeReferences
00798         Value: "2"
00799       - Key: EnableCOMDATFolding
00800         Value: "2"
00801       - Key: TargetMachine
00802         Value: "1"
00803 """
00804 
00805 
00806 
00807 def usage():
00808     print """Usage:
00809   vcprojtool.py cmd options
00810 commands:
00811   vcproj: Generate vcproj
00812   yaml  : Generate example yaml file
00813   flist : Generate file list as yaml
00814 examples:
00815   vcprojtool.py vcproj --type [exe|dll|nmake|lib]
00816                      --output out_fname
00817                      --yaml *.yaml
00818                      --source *.cpp
00819                      --header *.h
00820                      --resource *.txt
00821   vcprojtool.py yaml --type [exe|dll|nmake|lib] --output
00822   vcprojtool.py flist --out --source|--header|--resource *
00823 """
00824 
00825 import sys
00826 
00827 #------------------------------------------------------------
00828 # Exceptions
00829 #------------------------------------------------------------
00830 class VCProjException:
00831     pass
00832 
00833 class InvalidOption(VCProjException):
00834     def __init__(self, msg):
00835         self.msg = "Error: InvalidOption:\n    "
00836         self.msg += msg
00837 
00838 class InvalidCommand(VCProjException):
00839     def __init__(self, msg):
00840         self.msg = "Error: InvalidCommand:\n    "
00841         self.msg += msg
00842 
00843 #------------------------------------------------------------
00844 # VCProject generator class
00845 #------------------------------------------------------------
00846 class VCProject:
00847     def __init__(self, type, yaml_text):
00848         import yaml
00849         self.type = type
00850         self.dict = yaml.load(yaml_text)
00851         self.escape_cmdline(self.dict)
00852 
00853     def generate(self):
00854         import yat
00855         self.template = yat.Template(self.get_template(self.type))
00856         return self.template.generate(self.dict).replace("\r\n", "\n").replace("\n", "\r\n")
00857 
00858     def tool_element(self, type):
00859         text = ""
00860         for tool in tools[type]:
00861             t = tool_elem % (tool, tool, tool)
00862             text += t
00863         return text
00864 
00865     def get_template(self, type):
00866         return vcproj_template % (conf_type[type], self.tool_element(type))
00867 
00868     def escape_cmdline(self, dict):
00869         if not dict.has_key("Configurations"): return
00870     
00871         def escape_cmd(text):
00872             text = text.replace("\"", "&quot;")
00873             text = text.replace("\r\n", "\n")
00874             text = text.replace("\n", "&#x0D;&#x0A;")
00875             return text
00876         from types import DictType, ListType
00877         for conf in dict["Configurations"]:
00878             for tool in conf.keys(): # Tool
00879                 if isinstance(conf[tool], ListType):
00880                     for keyval in conf[tool]:
00881                         if isinstance(keyval, DictType) \
00882                                 and keyval.has_key("Key") \
00883                                 and keyval.has_key("Value") \
00884                                 and keyval["Key"] == "CommandLine":
00885                             keyval["Value"] = escape_cmd(keyval["Value"])
00886 
00887 #------------------------------------------------------------
00888 # YAML configuration file generator
00889 #------------------------------------------------------------
00890 class YamlConfig:
00891     def __init__(self, type, vcversion, projectname, version, flist):
00892         self.type = type
00893         self.vcversion = vcversion
00894         self.projectname = projectname
00895         self.version = version
00896         self.flist = flist
00897 
00898         self.yaml_template = {"EXE": exe_yaml, "DLL": dll_yaml, "LIB": lib_yaml,
00899                               "RTCEXE": rtcexe_yaml, "RTCDLL": rtcdll_yaml}
00900 
00901     def load_yamls(self, yfiles):
00902         text = ""
00903         for f in yfiles:
00904             fd = open(f, "r")
00905             text += fd.read()
00906             fd.close()
00907         return text
00908 
00909     def replace_uuid(self, text):
00910         import uuid
00911         token0 = text.split("__GUID__")
00912         text0 = token0[0]
00913         for i in range(1, len(token0)):
00914             u = str(uuid.uuid1()).upper()
00915             text0 += u + token0[i]
00916     
00917         token1 = text0.split("__UUID")
00918         text1 = token1[0]
00919         for i in range(1, len(token1)):
00920             u = "_" + str(uuid.uuid1()).replace("-", "")
00921             text1 += u + token1[i]
00922         return text1
00923 
00924     def generate(self):
00925         text = ""
00926         loaded = ""
00927         if self.flist.has_key("yaml") and len(self.flist["yaml"]) > 0:
00928             loaded = self.load_yamls(self.flist["yaml"])
00929 
00930         if loaded.find("ProjectType:") < 0: # No toplevel config
00931             if self.yaml_template.has_key(self.type):
00932                 text = self.yaml_template[self.type]
00933                 text += loaded
00934             else:
00935                 print "type should be specified."
00936                 usage()
00937         else:
00938             text = loaded
00939 
00940         text += FileList(self.flist).generate()
00941 
00942         text = self.replace_uuid(text)
00943         if self.projectname:
00944             text = text.replace("__PROJECT_NAME__", self.projectname)
00945         if self.version:
00946             text = text.replace("__VERSION__", self.version)
00947         if self.vcversion:
00948             text = text.replace("__VCVERSION__", self.vcversion)
00949         return text
00950 
00951 #------------------------------------------------------------
00952 # File list yaml file generator
00953 #------------------------------------------------------------
00954 class FileList:
00955     def __init__(self, flist):
00956         self.flist = flist
00957         self.filter = {"source":
00958                       {"Id": "Source",
00959                        "name": "Source Files",
00960                        "filter": "cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx",
00961                        },
00962                   "header":
00963                       {"Id": "Header",
00964                        "name": "Header Files",
00965                        "filter": "h;hpp;hxx;hm;inl;inc;xsd",
00966                        },
00967                   "resource":
00968                       {"Id": "Resoruce",
00969                        "name": "Resource Files",
00970                        "filter": "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav",
00971                        }
00972                   }
00973         self.temp = """%s:
00974   Name: %s
00975   Filter: %s
00976   GUID: __GUID__
00977   Files:
00978 """
00979         return
00980 
00981     def generate(self):
00982         text = ""
00983         for f in ["source", "header", "resource"]:
00984             if len(self.flist[f]) > 0:
00985                 text += self.temp % \
00986                     (self.filter[f]["Id"], self.filter[f]["name"],
00987                      self.filter[f]["filter"])
00988                 for file in self.flist[f]:
00989                     # vcproj's path delimiter should be "\"
00990                     file = file.replace("/","\\")
00991                     text += "    - Path: " + file + "\n"
00992         return text
00993 
00994 
00995 
00996            
00997 
00998 #def generate_vcproj(type, projectname, version, flist):
00999 #    yaml_text = ""
01000 #    for f in flist["yaml"]:
01001 #        fd = open(f, "r")
01002 #        yaml_text += fd.read()
01003 #        fd.close()
01004 #    yaml_text += generate_flist(flist)
01005 #    yaml_text = replace_uuid(yaml_text)
01006 #    if projectname:
01007 #        yaml_text = yaml_text.replace("__PROJECT_NAME__", projectname)
01008 #    if version:
01009 #        yaml_text = yaml_text.replace("__VERSION__", version)
01010 #    vcproj = VCProject(type, yaml_text)
01011 #    return vcproj.generate()
01012 #
01013 # 
01014 #
01015 #
01016 #def generate_yaml(type, projectname, version, flist):
01017 #    yaml_template = {"EXE": exe_yaml, "DLL": dll_yaml, "LIB": lib_yaml}
01018 #    text = yaml_template[type]
01019 #    text += generate_flist(flist)
01020 #    if projectname:
01021 #        text = text.replace("__PROJECT_NAME__", projectname)
01022 #    if version:
01023 #        text = text.replace("__VERSION__", version)
01024 #    return text
01025 
01026 #------------------------------------------------------------
01027 # command option
01028 #------------------------------------------------------------
01029 def parse_args(argv):
01030     cmd = argv[0]
01031     if not (cmd == "vcproj" or cmd == "flist" or cmd == "yaml"):
01032         raise InvalidCommand("no such command: " + cmd)
01033         
01034     outfname = None
01035     type = None
01036     vcversion = None
01037     projectname = None
01038     version = None
01039     flist = {"yaml": [], "source": [], "header": [], "resource": []}
01040     i = 1
01041     argc = len(argv)
01042 
01043     while i < argc:
01044         opt = argv[i]
01045         if opt == "--projectname":
01046             i += 1
01047             if i < argc: projectname = argv[i]
01048             else: raise InvalidOption(opt + " needs value")
01049         elif opt == "--version":
01050             i += 1
01051             if i < argc: version = argv[i]
01052             else: raise InvalidOption(opt + " needs value")
01053         elif opt == "--vcversion":
01054             i += 1
01055             if i < argc: vcversion = argv[i]
01056             else: raise InvalidOption(opt + " needs value")
01057         elif opt == "--output" or opt == "--out" or opt == "-o":
01058             i += 1
01059             if i < argc: outfname = argv[i]
01060             else: raise InvalidOption(opt + " needs value")
01061         elif opt == "--type" or opt == "-t":
01062             i += 1
01063             if i < argc: type = argv[i]
01064             else: raise InvalidOption(opt + " needs value")
01065             type = type.upper()
01066             if not conf_type.has_key(type):
01067                 raise InvalidOption("unknown type: "
01068                                     + type + "\n" +
01069                                     "    --type should be [exe|dll|nmake|lib]")
01070         elif opt[:2] == "--" and flist.has_key(opt[2:]):
01071             lname = opt[2:]
01072             i += 1
01073             if not i < argc: raise InvalidOption(opt + " need value") 
01074             while i < argc and argv[i][:2] != "--":
01075                 flist[lname].append(argv[i])
01076                 i += 1
01077             if len(flist[lname]) == 0:
01078                 raise InvalidOption(opt + " needs value")
01079             i -= 1
01080         else:
01081             raise InvalidOption("unknown option: " + opt)
01082         i += 1
01083     return (cmd, vcversion, projectname, version, outfname, type, flist)
01084 
01085 #------------------------------------------------------------
01086 # main function
01087 #------------------------------------------------------------
01088 def main(argv):
01089     if len(argv) == 0:
01090         usage()
01091         sys.exit(-1)
01092 
01093     try:
01094         res = parse_args(argv)
01095     except VCProjException, e:
01096         print "\n" + e.msg + "\n"
01097         usage()
01098         sys.exit(-1)
01099 
01100     cmd = res[0]
01101     vcversion = res[1]
01102     projectname = res[2]
01103     version = res[3]
01104     outfile = res[4]
01105     type = res[5]
01106     flist = res[6]
01107 
01108     if cmd == "vcproj":
01109         t = VCProject(type,
01110                       YamlConfig(type, vcversion,
01111                                  projectname, version, flist).generate()
01112                       ).generate()
01113     elif cmd == "flist":
01114         t = FileList(flist).generate()
01115     elif cmd == "yaml":
01116         t = YamlConfig(type, vcversion, projectname, version, flist).generate()
01117 
01118     if outfile == None:
01119         fd = sys.stdout
01120     else:
01121         fd = open(outfile, "wb")
01122 
01123     fd.write(t)
01124         
01125 #------------------------------------------------------------
01126 # tests
01127 #------------------------------------------------------------
01128 def test_filelist():
01129     print FileList({"source": ["hoge.cpp", "hage.cpp", "fuga.cpp"],
01130                     "header": ["hoge.h", "hage.h", "fuga.h"],
01131                     "resource": []}).generate()
01132 
01133 def test_yamlconfig():
01134     print YamlConfig("EXE", "8.00", "Test", "0.9.1",
01135                      {"source":
01136                           ["hoge.cpp",
01137                            "hage.cpp",
01138                            "fuga.cpp"],
01139                       "header":
01140                           ["hoge.h", "hage.h", "fuga.h"],
01141                       "resource":
01142                           []}).generate()
01143 
01144 def test_vcproj():
01145     print VCProject("EXE", YamlConfig("EXE", "8.00", "Test", "1.0.0",
01146                                       {"source":
01147                                            ["hoge.cpp",
01148                                             "hage.cpp",
01149                                             "fuga.cpp"],
01150                                        "header":
01151                                            ["hoge.h", "hage.h", "fuga.h"],
01152                                        "resource":
01153                                           [],
01154                                        "yaml":
01155                                            []}).generate()).generate()
01156 
01157 #------------------------------------------------------------
01158 # entry point
01159 #------------------------------------------------------------
01160 if __name__ == "__main__":
01161 #    test_filelist()
01162 #    test_yamlconfig()
01163 #    test_vcproj()
01164     main(sys.argv[1:])
01165     


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:17