📄 vcprojconfiguration.cpp
字号:
/////////////////////////////////////////////////////////////////////////////////
//
// vcprojconfiguration class implementation
//
// S.Rodriguez - Sept 2002
//
//
// purpose : fill class members with actual configuration data from the .vcproj file
//
//
//
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <atlbase.h> // CComPtr
#include <comutil.h> // _variant_t
#pragma comment(lib, "comsupp.lib")
#include <msxml2.h>
#include "slnprocess.h"
#include "symbols.h"
#include "vcprojconfiguration.h"
vcprojconfiguration::vcprojconfiguration()
{
setMasterProjConfigurations(NULL);
}
// Accessors
void vcprojconfiguration::setMasterProjConfigurations(vcprojconfiguration *p) // used for FileConfiguration
{
m_cpParentConfigurations = p;
}
CString vcprojconfiguration::getConfigName()
{
CString s;
s = General.GetValue(XMLATTRIB_NAME);
return s;
}
BOOL vcprojconfiguration::hasVCConfigTool(CString &szToolName)
{
if (szToolName.CompareNoCase(VCCOMPILERTOOL))
return VCCLCompilerTool.GetValue(XMLATTRIB_NAME).GetLength()>0;
else if (szToolName.CompareNoCase(VCLIBRARIANTOOL))
return VCLibrarianTool.GetValue(XMLATTRIB_NAME).GetLength()>0;
else if (szToolName.CompareNoCase(VCLINKERTOOL))
return VCLinkerTool.GetValue(XMLATTRIB_NAME).GetLength()>0;
else if (szToolName.CompareNoCase(VCRESOURCECOMPILERTOOL))
return VCResourceCompilerTool.GetValue(XMLATTRIB_NAME).GetLength()>0;
else if (szToolName.CompareNoCase(VCMIDLTOOL))
return VCMidlTool.GetValue(XMLATTRIB_NAME).GetLength()>0;
else if (szToolName.CompareNoCase(VCBSCMAKETOOL))
return VCBscMakeTool.GetValue(XMLATTRIB_NAME).GetLength()>0;
else if (szToolName.CompareNoCase(VCPREBUILDEVENTTOOL))
return VCPreBuildEventTool.GetValue(XMLATTRIB_NAME).GetLength()>0;
else if (szToolName.CompareNoCase(VCPRELINKEVENTTOOL))
return VCPreLinkEventTool.GetValue(XMLATTRIB_NAME).GetLength()>0;
else if (szToolName.CompareNoCase(VCPOSTBUILDEVENTTOOL))
return VCPostBuildEventTool.GetValue(XMLATTRIB_NAME).GetLength()>0;
else if (szToolName.CompareNoCase(VCCUSTOMBUILDTOOL))
return VCCustomBuildTool.GetValue(XMLATTRIB_NAME).GetLength()>0;
else if (szToolName.CompareNoCase(VCNMAKETOOL))
return VCNMakeTool.GetValue(XMLATTRIB_NAME).GetLength()>0;
else if (szToolName.CompareNoCase(VCDEBUGSETTINGSTOOL))
return VCDebugSettingsTool.GetValue(XMLATTRIB_NAME).GetLength()>0;
return FALSE;
}
void vcprojconfiguration::fill(/*in*/IXMLDOMElement *p) // fill class members
{
if (!p) return; // good bye!
// first of all, store all attribute names/values in the "General" member
//
fillFromAttributes(p, General);
// then proceed, with all <Tool> occurences
//
CComPtr<IXMLDOMNodeList> pTools;
p->getElementsByTagName( _bstr_t(XMLNODE_TOOL), &pTools);
if (pTools)
{
long nb = 0;
pTools->get_length(&nb);
for (long i=0; i<nb; i++)
{
CComPtr<IXMLDOMNode> pToolNode;
pTools->get_item(i,&pToolNode);
if (pToolNode)
{
CComQIPtr<IXMLDOMElement> pTool( pToolNode );
CString szToolName;
getAttribValue(pTool, XMLATTRIB_NAME, szToolName);
if (szToolName.CompareNoCase(VCCOMPILERTOOL))
fillFromAttributes(pTool, VCCLCompilerTool);
else if (szToolName.CompareNoCase(VCLIBRARIANTOOL))
fillFromAttributes(pTool, VCLibrarianTool);
else if (szToolName.CompareNoCase(VCLINKERTOOL))
fillFromAttributes(pTool, VCLinkerTool);
else if (szToolName.CompareNoCase(VCRESOURCECOMPILERTOOL))
fillFromAttributes(pTool, VCResourceCompilerTool);
else if (szToolName.CompareNoCase(VCMIDLTOOL))
fillFromAttributes(pTool, VCMidlTool);
else if (szToolName.CompareNoCase(VCBSCMAKETOOL))
fillFromAttributes(pTool, VCBscMakeTool);
else if (szToolName.CompareNoCase(VCPREBUILDEVENTTOOL))
fillFromAttributes(pTool, VCPreBuildEventTool);
else if (szToolName.CompareNoCase(VCPRELINKEVENTTOOL))
fillFromAttributes(pTool, VCPreLinkEventTool);
else if (szToolName.CompareNoCase(VCPOSTBUILDEVENTTOOL))
fillFromAttributes(pTool, VCPostBuildEventTool);
else if (szToolName.CompareNoCase(VCCUSTOMBUILDTOOL))
fillFromAttributes(pTool, VCCustomBuildTool);
else if (szToolName.CompareNoCase(VCNMAKETOOL))
fillFromAttributes(pTool, VCNMakeTool);
else if (szToolName.CompareNoCase(VCDEBUGSETTINGSTOOL))
fillFromAttributes(pTool, VCDebugSettingsTool);
}
}
} // end if (pTools)
}
void vcprojconfiguration::fillFromAttributes(/*in*/IXMLDOMElement *p, /*out*/FindableArray &arrAttribs)
{
CComPtr<IXMLDOMNamedNodeMap> pAttributes;
p->get_attributes(&pAttributes);
if (pAttributes)
{
long nbAttribs = 0;
pAttributes->get_length(&nbAttribs);
for (long i=0; i<nbAttribs; i++)
{
CComPtr<IXMLDOMNode> pAttrib;
pAttributes->get_item(i,&pAttrib);
if (pAttrib)
{
BSTR bstrName;
pAttrib->get_nodeName(&bstrName);
CString szName;
BSTR_to_CString(bstrName,szName);
VARIANT vtValue;
pAttrib->get_nodeValue( &vtValue);
CString szValue;
VARIANT_to_CString( vtValue, szValue);
// add this name/value pair
if (!szName.IsEmpty())
{
SINGLEVALUEPARAM *p = new SINGLEVALUEPARAM();
if (p)
{
p->szName = szName;
p->szValue = szValue;
}
arrAttribs.Add( p );
}
}
}
} // end if (pAttributes)
}
CString vcprojconfiguration::serializeCPPSymbols(BOOL bFileConfiguration)
{
long i;
CString szReturn, s;
// sections are divided wrt to VC++7 (rescrambled for any reason by MS from VC++6)
// -- general tab
//
CString szAdditionalIncludeDirectories;
ArrayCString arrAdditionalIncludeDirectories;
s = VCCLCompilerTool.GetValue("AdditionalIncludeDirectories");
if (s.Find(0,",")>-1)
TokenizeString(s,',',arrAdditionalIncludeDirectories); // parse comma-separated path
else
TokenizeString(s,';',arrAdditionalIncludeDirectories); // or parse semi-colon-separated path
for (i=0; i<arrAdditionalIncludeDirectories.GetSize(); i++)
{
CString szDirectory = arrAdditionalIncludeDirectories.GetAt(i);
if ( !szDirectory.CompareNoCase("$(NOINHERIT)") )
szAdditionalIncludeDirectories += "/I \"" + szDirectory + "\" ";
}
CString szDebugInformationFormat;
s = VCCLCompilerTool.GetValue("DebugInformationFormat");
if (s.CompareNoCase("1"))
szDebugInformationFormat = "/Z7 ";
else if (s.CompareNoCase("2"))
szDebugInformationFormat = "/Zd ";
else if (s.CompareNoCase("3"))
szDebugInformationFormat = "/Zi ";
else if (s.CompareNoCase("4"))
szDebugInformationFormat = "/ZI ";
CString szSuppressStartupBanner = "/nologo "; // default VC7 behaviour is "suppress banner"
if ( VCCLCompilerTool.GetValue("SuppressStartupBanner").CompareNoCase("FALSE") )
szSuppressStartupBanner.Empty();
CString szWarningLevel;
s = VCCLCompilerTool.GetValue("WarningLevel");
if (s.CompareNoCase("0") || s.CompareNoCase("1") || s.CompareNoCase("2") || s.CompareNoCase("3") || s.CompareNoCase("4"))
{
szWarningLevel = "/W" + s + " ";
}
CString szWarnAsError;
if ( VCCLCompilerTool.GetValue("WarnAsError").CompareNoCase("TRUE") )
szWarnAsError += "/WX ";
// -- optimization tab
//
CString szOptimization;
s = VCCLCompilerTool.GetValue("Optimization");
if (s.CompareNoCase("0"))
szOptimization = "/Od "; // disabled
else if (s.CompareNoCase("1"))
szOptimization = "/O1 "; // minimize size
else if (s.CompareNoCase("2"))
szOptimization = "/O2 "; // maximize speed
else if (s.CompareNoCase("3"))
szOptimization = "/Ox "; // combined optim (/Ob1 /Og /Oi /Ot /Oy /Gs)
CString szGlobalOptimizations;
if ( VCCLCompilerTool.GetValue("GlobalOptimizations").CompareNoCase("TRUE") )
szGlobalOptimizations = "/Og ";
CString szInlineFunctionExpansion; // disabled (/Ob0 is useless because it is the default VC++ 6.0 value)
s = VCCLCompilerTool.GetValue("InlineFunctionExpansion");
if (s.CompareNoCase("1"))
szInlineFunctionExpansion = "/Ob1 "; // only __inline
else if (s.CompareNoCase("2"))
szInlineFunctionExpansion = "/Ob2 "; // any suitable
CString szEnableIntrinsicFunctions;
if ( VCCLCompilerTool.GetValue("EnableIntrinsicFunctions").CompareNoCase("TRUE") )
szEnableIntrinsicFunctions = "/Oi ";
CString szImproveFloatingPointConsistency;
if ( VCCLCompilerTool.GetValue("ImproveFloatingPointConsistency").CompareNoCase("TRUE") )
szImproveFloatingPointConsistency = "/Op ";
CString szFavorSizeOrSpeed;
s = VCCLCompilerTool.GetValue("FavorSizeOrSpeed");
if (s.CompareNoCase("1"))
szFavorSizeOrSpeed = "/Ot "; // favor speed
else if (s.CompareNoCase("2"))
szFavorSizeOrSpeed = "/Os "; // favor size
CString szOmitFramePointers;
if ( VCCLCompilerTool.GetValue("OmitFramePointers").CompareNoCase("TRUE") )
szOmitFramePointers = "/Oy ";
CString szEnableFiberSafeOptimizations;
if ( VCCLCompilerTool.GetValue("EnableFiberSafeOptimizations").CompareNoCase("TRUE") )
szEnableFiberSafeOptimizations = "/GT ";
CString szOptimizeForProcessor;
s = VCCLCompilerTool.GetValue("OptimizeForProcessor");
if (s.CompareNoCase("1"))
szOptimizeForProcessor = "/G5 "; // for Pentium
else if (s.CompareNoCase("2"))
szOptimizeForProcessor = "/G6 "; // for Pentium Pro
CString szOptimizeForWindowsApplication;
if ( VCCLCompilerTool.GetValue("OptimizeForWindowsApplication").CompareNoCase("TRUE") )
szOptimizeForWindowsApplication = "/GA ";
// -- preprocessor tab
//
s = VCCLCompilerTool.GetValue("PreprocessorDefinitions");
CString szPreprocessorDefs;
ArrayCString arrPreprocessorDefs;
if (s.Find(0,",")>-1)
TokenizeString(s,',',arrPreprocessorDefs); // parse comma-separated symbols
else
TokenizeString(s,';',arrPreprocessorDefs); // or parse semi-colon-separated symbols
for (i=0; i<arrPreprocessorDefs.GetSize(); i++)
{
CString szSymbol = arrPreprocessorDefs.GetAt(i);
if ( !szSymbol.CompareNoCase("$(NOINHERIT)") )
szPreprocessorDefs += "/D \"" + szSymbol + "\" ";
// if we see the _AFXEXT symbol, then don't forget to add the _WINDLL too
if ( szSymbol.CompareNoCase("_AFXEXT") )
szPreprocessorDefs += "/D \"_WINDLL\" ";
}
// special treatment if we are using shared MFC
// (we have to add this symbol by hand, because in VC++7 this symbol is inherited instead of explicit)
if ( General.GetValue("UseOfMFC").CompareNoCase("2") )
{
szPreprocessorDefs += "/D \"_AFXDLL\" "; // MFC dynamically linked
}
// special treatment if we are using shared ATL
// (we have to add this symbol by hand, because in VC++7 this symbol is inherited instead of explicit)
if ( General.GetValue("UseOfATL").CompareNoCase("2") )
{
// ATL dynamically linked (see msdev atl source code)
szPreprocessorDefs += "/D \"_ATL_DLL\" ";
}
// special treatment if we are using a specific charset
// (we have to add this symbol by hand, because in VC++7 this symbol is inherited instead of explicit)
CString szMBCSSymbol;
s = General.GetValue("CharacterSet");
if (s.CompareNoCase("1"))
szMBCSSymbol = "_UNICODE"; // 16-bit chars
else if (s.CompareNoCase("2"))
szMBCSSymbol = "_MBCS"; // standard multi-byte chars (local charset)
if (!szMBCSSymbol.IsEmpty())
{
szPreprocessorDefs += "/D \"" + szMBCSSymbol + "\" ";
}
CString szIgnoreStandardIncludePath;
if ( VCCLCompilerTool.GetValue("IgnoreStandardIncludePath").CompareNoCase("TRUE") )
szIgnoreStandardIncludePath = "/X ";
CString szGeneratePreprocessedFile;
s = VCCLCompilerTool.GetValue("GeneratePreprocessedFile");
if (s.CompareNoCase("1"))
szGeneratePreprocessedFile = "/P "; // with #lines
else if (s.CompareNoCase("2"))
szGeneratePreprocessedFile = "/EP "; // without #lines
CString szKeepComments;
if ( VCCLCompilerTool.GetValue("KeepComments").CompareNoCase("TRUE") )
szKeepComments = "/C ";
// -- code generation tab
//
CString szStringPooling;
if ( VCCLCompilerTool.GetValue("StringPooling").CompareNoCase("TRUE") )
szStringPooling = "/GF ";
CString szMinimalRebuild;
if ( VCCLCompilerTool.GetValue("MinimalRebuild").CompareNoCase("TRUE") )
szMinimalRebuild = "/Gm ";
CString szExceptionHandling;
if ( VCCLCompilerTool.GetValue("ExceptionHandling").CompareNoCase("TRUE") )
szExceptionHandling = "/EHsc ";
CString szRuntimeLibrary;
s = VCCLCompilerTool.GetValue("RuntimeLibrary");
if (s.CompareNoCase("0"))
szRuntimeLibrary = "/MT "; // MultiThreaded
else if (s.CompareNoCase("1"))
szRuntimeLibrary = "/MTd "; // MultiThreadedDebug
else if (s.CompareNoCase("2"))
szRuntimeLibrary = "/MD "; // MultiThreadedDLL
else if (s.CompareNoCase("3"))
szRuntimeLibrary = "/MDd "; // MultiThreadedDebugDLL
else if (s.CompareNoCase("4"))
szRuntimeLibrary = "/ML "; // SingleThreaded
else if (s.CompareNoCase("5"))
szRuntimeLibrary = "/MLd "; // SingleThreadedDebug
// of course, at this point, if we are in a Release config, and we see runtimelibrary=1,3 or 5 then there is a problem
CString szStructMemberAlignment;
s = VCCLCompilerTool.GetValue("StructMemberAlignment");
if (s.CompareNoCase("1"))
szStructMemberAlignment = "/Zp1 "; // 1-byte alignment
else if (s.CompareNoCase("2"))
szStructMemberAlignment = "/Zp2 "; // 2-byte alignment
else if (s.CompareNoCase("3"))
szStructMemberAlignment = "/Zp4 "; // 4-byte alignment
else if (s.CompareNoCase("4"))
szStructMemberAlignment = "/Zp8 "; // 8-byte alignment
else if (s.CompareNoCase("5"))
szStructMemberAlignment = "/Zp16 "; // 16-byte alignment
CString szEnableFunctionLevelLinking;
if ( VCCLCompilerTool.GetValue("EnableFunctionLevelLinking").CompareNoCase("TRUE") )
szEnableFunctionLevelLinking = "/Gy ";
// -- language tab
//
CString szDisableLanguageExtensions;
if ( VCCLCompilerTool.GetValue("DisableLanguageExtensions").CompareNoCase("TRUE") )
szDisableLanguageExtensions = "/Za ";
CString szDefaultCharIsUnsigned;
if ( VCCLCompilerTool.GetValue("DefaultCharIsUnsigned").CompareNoCase("TRUE") )
szDefaultCharIsUnsigned = "/J ";
CString szRuntimeTypeInfo;
if ( VCCLCompilerTool.GetValue("RuntimeTypeInfo").CompareNoCase("TRUE") )
szRuntimeTypeInfo = "/GR ";
// -- precompiled headers tab
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -