📄 valvelibaw.cpp
字号:
// valvelibaw.cpp : implementation file
//
#include "stdafx.h"
#include "valvelib.h"
#include "valvelibaw.h"
#include "chooser.h"
#include <assert.h>
#include<atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
#include <initguid.h>
#include<comdef.h>
#ifdef _PSEUDO_DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define STUPID_MS_BUG 1
enum Config_t
{
CONFIG_DEBUG = 0,
CONFIG_RELEASEWITHSYMBOLS,
CONFIG_RELEASE
};
enum Project_t
{
PROJECT_LIB = 0,
PROJECT_DLL,
PROJECT_EXE
};
struct ProjectInfo_t
{
DSProjectSystem::IConfigurationPtr m_pConfig;
long m_ConfigIndex;
Config_t m_Config;
Project_t m_Project;
CString m_RelativeTargetPath;
CString m_RelativeImplibPath;
CString m_RelativeRootPath;
CString m_RelativeSrcPath;
CString m_TargetPath;
CString m_RootName;
CString m_BuildName;
CString m_Ext;
bool m_Tool;
bool m_Console;
bool m_Public;
bool m_PublishImportLib;
};
// This is called immediately after the custom AppWizard is loaded. Initialize
// the state of the custom AppWizard here.
void CValvelibAppWiz::InitCustomAppWiz()
{
// Create a new dialog chooser; CDialogChooser's constructor initializes
// its internal array with pointers to the steps.
m_pChooser = new CDialogChooser;
// Set the maximum number of steps.
SetNumberOfSteps(LAST_DLG);
// TODO: Add any other custom AppWizard-wide initialization here.
}
// This is called just before the custom AppWizard is unloaded.
void CValvelibAppWiz::ExitCustomAppWiz()
{
// Deallocate memory used for the dialog chooser
ASSERT(m_pChooser != NULL);
delete m_pChooser;
m_pChooser = NULL;
// TODO: Add code here to deallocate resources used by the custom AppWizard
}
// This is called when the user clicks "Create..." on the New Project dialog
// or "Next" on one of the custom AppWizard's steps.
CAppWizStepDlg* CValvelibAppWiz::Next(CAppWizStepDlg* pDlg)
{
// Delegate to the dialog chooser
return m_pChooser->Next(pDlg);
}
// This is called when the user clicks "Back" on one of the custom
// AppWizard's steps.
CAppWizStepDlg* CValvelibAppWiz::Back(CAppWizStepDlg* pDlg)
{
// Delegate to the dialog chooser
return m_pChooser->Back(pDlg);
}
//-----------------------------------------------------------------------------
// Deals with compiler settings
//-----------------------------------------------------------------------------
static void SetupCompilerSettings(ProjectInfo_t& info)
{
_bstr_t varTool;
_bstr_t varSwitch;
_variant_t varj = info.m_ConfigIndex;
// We're going to modify settings associated with cl.exe
varTool = "cl.exe";
// Standard include directories
CString includePath;
if (info.m_Public)
{
includePath.Format("/I%scommon /I%spublic", info.m_RelativeSrcPath,
info.m_RelativeSrcPath );
}
else
{
includePath.Format("/I%scommon", info.m_RelativeSrcPath );
}
info.m_pConfig->AddToolSettings(varTool, (char const*)includePath, varj);
// Control which version of the debug libraries to use (static single thread
// for normal projects, multithread for tools)
if (info.m_Tool)
{
if (info.m_Config == CONFIG_DEBUG)
varSwitch = "/MTd";
else
varSwitch = "/MT";
}
else
{
// Suppress use of non-filesystem stuff in new non-tool projects...
if (info.m_Config == CONFIG_DEBUG)
varSwitch = "/D \"fopen=dont_use_fopen\" /MLd";
else
varSwitch = "/D \"fopen=dont_use_fopen\" /ML";
}
info.m_pConfig->AddToolSettings(varTool, varSwitch, varj);
// If it's a DLL, define a standard exports macro...
if (info.m_Project == PROJECT_DLL)
{
CString dllExport;
dllExport.Format("/D \"%s_DLL_EXPORT\"", info.m_RootName );
dllExport.MakeUpper();
info.m_pConfig->AddToolSettings(varTool, (char const*)dllExport, varj);
}
// /W4 - Warning level 4
// /FD - Generates file dependencies
// /G6 - optimize for pentium pro
// Add _WIN32, as that's what all our other code uses
varSwitch = "/W4 /FD /G6 /D \"_WIN32\"";
info.m_pConfig->AddToolSettings(varTool, varSwitch, varj);
// Remove Preprocessor def for MFC DLL specifier, _AFXDLL
// /GX - No exceptions,
// /YX - no precompiled headers
// Remove WIN32, it's put there by default
varSwitch = "/D \"_AFXDLL\" /GX /YX /D \"WIN32\"";
info.m_pConfig->RemoveToolSettings(varTool, varSwitch, varj);
switch (info.m_Config)
{
case CONFIG_DEBUG:
// Remove the following switches (avoid duplicates, in addition to other things)
varSwitch = "/D \"NDEBUG\" /Zi /ZI /GZ";
info.m_pConfig->RemoveToolSettings(varTool, varSwitch, varj);
// Add the following switches:
// /ZI - Includes debug information in a program database compatible with Edit and Continue.
// /Zi - Includes debug information in a program database (no Edit and Continue)
// /Od - Disable optimization
// /GZ - Catch release build problems (uninitialized variables, fp stack problems)
// /Op - Improves floating-point consistency
// /Gm - Minimal rebuild
// /FR - Generate Browse Info
varSwitch = "/D \"_DEBUG\" /Od /GZ /Op /Gm /FR\"Debug/\"";
info.m_pConfig->AddToolSettings(varTool, varSwitch, varj);
if (info.m_Project == PROJECT_LIB)
{
// Static libraries cannot use edit-and-continue, why compile it in?
varSwitch = "/Zi";
info.m_pConfig->AddToolSettings(varTool, varSwitch, varj);
}
else
{
varSwitch = "/ZI";
info.m_pConfig->AddToolSettings(varTool, varSwitch, varj);
}
break;
case CONFIG_RELEASE:
case CONFIG_RELEASEWITHSYMBOLS:
// Remove the following switches:
// /Zi - Generates complete debugging information
// /ZI - Includes debug information in a program database compatible with Edit and Continue.
// /Gm - Minimal rebuild
// /GZ - Catch release build problems (uninitialized variables, fp stack problems)
varSwitch = "/D \"_DEBUG\" /Gm /Zi /ZI /GZ";
info.m_pConfig->RemoveToolSettings(varTool, varSwitch, varj);
// Add the following switches:
// /Ox - Uses maximum optimization (/Ob1gity /Gs)
// /Ow - Assumes aliasing across function calls
// /Op - Improves floating-point consistency
// /Gf - String pooling
// /Oi - Generates intrinsic functions
// /Ot - Favors fast code
// /Og - Uses global optimizations
// /Gy - Enable function level linking
varSwitch = "/D \"NDEBUG\" /Ox /Ow /Op /Oi /Ot /Og /Gf /Gy";
info.m_pConfig->AddToolSettings(varTool, varSwitch, varj);
break;
}
// A little fixup for release with symbols
if (info.m_Config == CONFIG_RELEASEWITHSYMBOLS)
{
#ifndef STUPID_MS_BUG
CString oldPath;
oldPath.Format("/Fo\"%s___Win32_ReleaseWithSymbols/\" /Fd\"%s___Win32_ReleaseWithSymbols/\" /FR\"%s___Win32_ReleaseWithSymbols/\"", info.m_RootName, info.m_RootName, info.m_RootName );
info.m_pConfig->RemoveToolSettings(varTool, (char const*)oldPath, varj);
varSwitch = "/Zi /Fo\"ReleaseWithSymbols/\" /Fd\"ReleaseWithSymbols/\" /FR\"ReleaseWithSymbols/\"";
info.m_pConfig->AddToolSettings(varTool, varSwitch, varj);
#else
CString releaseStuff;
releaseStuff.Format("/D \"_MBCS\" /Zi /FR\"%s___Win32_ReleaseWithSymbols/\"", info.m_RootName );
info.m_pConfig->AddToolSettings(varTool, (char const*)releaseStuff, varj);
#endif
}
}
//-----------------------------------------------------------------------------
// Deals with resource compiler
//-----------------------------------------------------------------------------
static void SetupResourceCompilerSettings(ProjectInfo_t& info)
{
_bstr_t varTool;
_bstr_t varSwitch;
_variant_t varj = info.m_ConfigIndex;
// Remove Preprocessor def for MFC DLL specifier, _AFXDLL
varTool = "rc.exe";
varSwitch = "/d \"_AFXDLL\"";
info.m_pConfig->RemoveToolSettings(varTool, varSwitch, varj);
if (info.m_Config == CONFIG_RELEASEWITHSYMBOLS)
{
varSwitch = "/d \"_DEBUG\"";
info.m_pConfig->RemoveToolSettings(varTool, varSwitch, varj);
varSwitch = "/d \"NDEBUG\"";
info.m_pConfig->AddToolSettings(varTool, varSwitch, varj);
}
}
//-----------------------------------------------------------------------------
// Deals with linker settings
//-----------------------------------------------------------------------------
static void SetupLinkerSettings(ProjectInfo_t& info)
{
_bstr_t varTool;
_bstr_t varSwitch;
_variant_t varj = info.m_ConfigIndex;
// We're going to modify settings associated with cl.exe
varTool = "link.exe";
// Remove windows libraries by default... hopefully we don't have windows dependencies
varSwitch = "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib";
info.m_pConfig->RemoveToolSettings(varTool, varSwitch, varj);
// Add libraries we always want to use
varSwitch = "tier0.lib";
info.m_pConfig->AddToolSettings(varTool, varSwitch, varj);
#ifndef STUPID_MS_BUG
if (info.m_Config == CONFIG_RELEASEWITHSYMBOLS)
{
// Fixup the pdb file name
CString pdbFileName;
pdbFileName.Format( "/pdb:\"%s___Win32_ReleaseWithSymbols/%s.pdb\"", info.m_RootName, info.m_RootName );
info.m_pConfig->RemoveToolSettings(varTool, (char const*)pdbFileName, varj);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -