⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 valvelibaw.cpp

📁 hl2 source code. Do not use it illegal.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		pdbFileName.Format( "/pdb:\"ReleaseWithSymbols/%s.pdb\"", info.m_RootName );
		info.m_pConfig->AddToolSettings(varTool, (char const*)pdbFileName, varj);

		// Fixup the importlib file name
		if (info.m_Project == PROJECT_DLL)
		{
			CString implibFileName;
			implibFileName.Format( "/implib:\"%s___Win32_ReleaseWithSymbols/%s.lib\"", info.m_RootName, info.m_RootName );
			info.m_pConfig->RemoveToolSettings(varTool, (char const*)implibFileName, varj);

			implibFileName.Format( "/implib:\"ReleaseWithSymbols/%s.lib\"", info.m_RootName );
			info.m_pConfig->AddToolSettings(varTool, (char const*)implibFileName, varj);
		}
	}
#endif

	// Hook in the static library path
	CString libPath;

	// FIXME: Still haven't decided on build-specific publish dir

	if (info.m_Public)
	{
		libPath.Format( "/libpath:\"%slib\\common\\\" /libpath:\"%slib\\public\\\"",
			info.m_RelativeSrcPath, info.m_RelativeSrcPath );
	}
	else
	{
		libPath.Format( "/libpath:\"%slib\\common\\\"", info.m_RelativeSrcPath );
	}

	info.m_pConfig->AddToolSettings(varTool, (char const*)libPath, varj);
}

//-----------------------------------------------------------------------------
// Deals with lib settings
//-----------------------------------------------------------------------------

static void SetupLibSettings(ProjectInfo_t& info)
{
	// ARGHRHGHGHH!!!
	// My beautiful plan of getting everything in a subdirectory that 
	// doesn't has Foo___Win32_ReleaseWithSymbols is toast becasue of this
	// one small bug that causes AddToolSettings to barf when you pass it lib.exe
	// It works with obscure things like midl and bscmake. Why can't
	// they get it right?  WAAAHH!!!

#ifndef STUPID_MS_BUG
	_variant_t varj = info.m_ConfigIndex;

	// Browse settings...
	if (info.m_Config == CONFIG_RELEASEWITHSYMBOLS)
	{
		CString libFile;
		libFile.Format("/out:\"%s___Win32_ReleaseWithSymbols\\%s.lib\"", info.m_RootName, info.m_RootName );
		info.m_pConfig->RemoveToolSettings("lib.exe", (char const*)libFile, varj );

		libFile.Format("/out:\"ReleaseWithSymbols\\%s.lib\"", info.m_RootName );
		info.m_pConfig->AddToolSettings("lib.exe", (char const*)libFile, varj );
	}
#endif
}

//-----------------------------------------------------------------------------
// Deals with custom build steps
//-----------------------------------------------------------------------------

static void SetupCustomBuildSteps(ProjectInfo_t& info)
{
	// Create the custom build steps
	CString copySteps;
	CString targets;

	if (info.m_Project == PROJECT_LIB)
	{
		CString targetPath;

		targetPath.Format( "%s%s.%s", info.m_RelativeTargetPath, info.m_RootName, info.m_Ext );

		// NOTE: The second attrib is commented out because I'm fairly certain it causes
		// a bug in VSS to make it overwrite the target on a get
		copySteps.Format( 
			"if exist %s attrib -r %s\n"
			"copy $(TargetPath) %s\n"
			"if exist $(TargetDir)\\%s.map copy $(TargetDir)\\%s.map %s%s.map", 
			targetPath, targetPath,
			targetPath,
			info.m_RootName, info.m_RootName, info.m_RelativeTargetPath, info.m_RootName );

		targets.Format( "%s\n", targetPath );
	}
	else
	{
		CString targetPath;
		targetPath.Format( "%s%s.%s", info.m_RelativeTargetPath, info.m_RootName, info.m_Ext );

		// NOTE: The second attrib is commented out because I'm fairly certain it causes
		// a bug in VSS to make it overwrite the target on a get
		copySteps.Format( 
			"if exist %s attrib -r %s\n"
			"copy $(TargetPath) %s\n"
			"if exist $(TargetDir)\\%s.map copy $(TargetDir)\\%s.map %s%s.map", 
			targetPath, targetPath,
			targetPath,
			info.m_RootName, info.m_RootName, info.m_RelativeTargetPath, info.m_RootName );

		targets.Format( "%s", targetPath );

		if ((info.m_Project == PROJECT_DLL) && info.m_PublishImportLib)
		{
			CString targetPath;

 			targetPath.Format( "%s%s.lib", info.m_RelativeImplibPath, info.m_RootName );

			CString impLibCopy;
			impLibCopy.Format( 
				"\nif exist %s attrib -r %s\n"
				"if exist $(TargetDir)\\%s.lib copy $(TargetDir)\\%s.lib %s\n",
				targetPath, targetPath,
				info.m_RootName, info.m_RootName, targetPath
				);
			copySteps += impLibCopy;

			CString implibTarget;
			implibTarget.Format( "\n%s", targetPath );
			targets += implibTarget;
		}
	}

	CString publishDir;
	publishDir.Format( "Publishing to target directory (%s)...", info.m_RelativeTargetPath );
	info.m_pConfig->AddCustomBuildStep( (char const*)copySteps, (char const*)targets, (char const*)publishDir );
}

//-----------------------------------------------------------------------------
// Deals with MIDL build steps
//-----------------------------------------------------------------------------

static void SetupMIDLSettings(ProjectInfo_t& info)
{
	_bstr_t varSwitch;
	_variant_t varj = info.m_ConfigIndex;

	// MIDL settings...
	if (info.m_Config == CONFIG_RELEASEWITHSYMBOLS)
	{
		varSwitch = "/D \"_DEBUG\"";
		info.m_pConfig->RemoveToolSettings("midl", varSwitch, varj);

		varSwitch = "/D \"NDEBUG\"";
		info.m_pConfig->AddToolSettings("midl", varSwitch, varj);
	}
}

//-----------------------------------------------------------------------------
// Deals with browse build steps
//-----------------------------------------------------------------------------

static void SetupBrowseSettings(ProjectInfo_t& info)
{
#ifndef STUPID_MS_BUG
	_variant_t varj = info.m_ConfigIndex;

	// Browse settings...
	if (info.m_Config == CONFIG_RELEASEWITHSYMBOLS)
	{
		CString browseFile;
		browseFile.Format("/o\"%s___Win32_ReleaseWithSymbols/%s.bsc\"", info.m_RootName, info.m_RootName );
		info.m_pConfig->RemoveToolSettings("bscmake", (char const*)browseFile, varj );

		browseFile.Format("/o\"ReleaseWithSymbols/%s.bsc\"", info.m_RootName );
		info.m_pConfig->AddToolSettings("bscmake", (char const*)browseFile, varj );
	}
#endif
}

void CValvelibAppWiz::CustomizeProject(IBuildProject* pProject)
{
	// This is called immediately after the default Debug and Release
	//  configurations have been created for each platform.  You may customize
	//  existing configurations on this project by using the methods
	//  of IBuildProject and IConfiguration such as AddToolSettings,
	//  RemoveToolSettings, and AddCustomBuildStep. These are documented in
	//  the Developer Studio object model documentation.

	// WARNING!!  IBuildProject and all interfaces you can get from it are OLE
	//  COM interfaces.  You must be careful to release all new interfaces
	//  you acquire.  In accordance with the standard rules of COM, you must
	//  NOT release pProject, unless you explicitly AddRef it, since pProject
	//  is passed as an "in" parameter to this function.  See the documentation
	//  on CCustomAppWiz::CustomizeProject for more information.

	using namespace DSProjectSystem;

	long lNumConfigs;
	IConfigurationsPtr pConfigs;
	IBuildProjectPtr pProj;

	// Needed to convert IBuildProject to the DSProjectSystem namespace
	pProj.Attach((DSProjectSystem::IBuildProject*)pProject, true);

	// Add a release with symbols configuration
	pProj->AddConfiguration( "ReleaseWithSymbols" );

	pProj->get_Configurations(&pConfigs);
	pConfigs->get_Count(&lNumConfigs);

	// Needed for OLE2T below
	USES_CONVERSION;
	CComBSTR configName;

	ProjectInfo_t info;
	if (!Valvelibaw.m_Dictionary.Lookup("VALVE_RELATIVE_PATH", info.m_RelativeTargetPath))
		return;
	if (!Valvelibaw.m_Dictionary.Lookup("root", info.m_RootName))
		return;
	if (!Valvelibaw.m_Dictionary.Lookup("VALVE_TARGET_TYPE", info.m_Ext))
		return;
	if (!Valvelibaw.m_Dictionary.Lookup("VALVE_ROOT_RELATIVE_PATH", info.m_RelativeRootPath))
		return;
	if (!Valvelibaw.m_Dictionary.Lookup("VALVE_SRC_RELATIVE_PATH", info.m_RelativeSrcPath))
		return;
	if (!Valvelibaw.m_Dictionary.Lookup("VALVE_TARGET_PATH", info.m_TargetPath))
		return;

	CString tmp;
	info.m_Tool = (Valvelibaw.m_Dictionary.Lookup("VALVE_TOOL", tmp) != 0);
	info.m_Console = (Valvelibaw.m_Dictionary.Lookup("PROJTYPE_CON", tmp) != 0);
	info.m_Public = (Valvelibaw.m_Dictionary.Lookup("VALVE_PUBLIC_PROJECT", tmp) != 0);
	info.m_PublishImportLib = (Valvelibaw.m_Dictionary.Lookup("VALVE_PUBLISH_IMPORT_LIB", tmp) != 0);
	info.m_Project = PROJECT_LIB;
	if ( strstr( info.m_Ext, "dll" ) != 0 )
	{
		info.m_Project = PROJECT_DLL;
		if (!Valvelibaw.m_Dictionary.Lookup("VALVE_IMPLIB_RELATIVE_PATH", info.m_RelativeImplibPath))
			return;
	}
	else if ( strstr( info.m_Ext, "exe" ) != 0 )
	{
		info.m_Project = PROJECT_EXE;
	}

	//Get each individual configuration
	for (long j = 1 ; j <= lNumConfigs ; j++)
	{
		_bstr_t varTool;
		_bstr_t varSwitch;
		_variant_t varj = j;
		info.m_ConfigIndex = j;

		info.m_pConfig = pConfigs->Item(varj);
		
		// Figure if we're debug or release
		info.m_pConfig->get_Name( &configName );
		info.m_Config = CONFIG_RELEASE;
		info.m_BuildName = "Release";
		if ( strstr( OLE2T(configName), "Debug" ) != 0 )
		{
			info.m_Config = CONFIG_DEBUG;
			info.m_BuildName = "Debug";
		}
		else if ( strstr( OLE2T(configName), "ReleaseWithSymbols" ) != 0 )
		{
			info.m_Config = CONFIG_RELEASEWITHSYMBOLS;
			info.m_BuildName = "ReleaseWithSymbols";
		}

		// Not using MFC...
		info.m_pConfig->AddToolSettings("mfc", "0", varj);

		SetupCompilerSettings(info);
		SetupResourceCompilerSettings(info);
		if (info.m_Project != PROJECT_LIB)
		{
			SetupLinkerSettings(info);

			if (!info.m_Console)
				SetupMIDLSettings(info);
		}
		else
		{
			SetupLibSettings(info);
		}
		SetupCustomBuildSteps(info);
		SetupBrowseSettings(info);

		info.m_pConfig->MakeCurrentSettingsDefault();
	}
}
	

// Here we define one instance of the CValvelibAppWiz class.  You can access
//  m_Dictionary and any other public members of this class through the
//  global Valvelibaw.
CValvelibAppWiz Valvelibaw;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -