Click here to Skip to main content
15,881,281 members
Articles / Programming Languages / Javascript

A Visual Studio Wizard to add more project configurations

Rate me:
Please Sign up or sign in to vote.
4.78/5 (7 votes)
22 May 2011CPOL14 min read 30.7K   504   27  
This article explains how to automate Visual C++ project configurations using the Visual Studio wizard engine.
#ifndef _PROJECT1_AUTO_LINK_HEADER_FILE_
#define _PROJECT1_AUTO_LINK_HEADER_FILE_

#include "Project1_Version.h"
#ifndef AFX_STATIC
#define AFX_STATIC static
#endif

//------------------------------------------------------------------------
// NOTE: If using the Project1 as a static library linked to an
// application that is dynamically linked with MFC or C-Runtime library, you will need to do the
// following:
//
// Open the Project1 project workspace and select one of the
// Win32 Dynamic build settings and build the library. Add the following
// lines of code to your stdafx.h file:
//
// #define _PROJECT1_STATICLINK
// #include <Project1.h>
//
// Add the following line of code to your *.rc2 file after the comment:
// "Add manually edited resources here...":
//
// #include "Project1.rc"
//------------------------------------------------------------------------

#undef _PROJECT1_EXT_CLASS

#if !defined(_DLL) || defined(_PROJECT1_STATICLINK)
#define _PROJECT1_EXT_CLASS
#else
#define _PROJECT1_EXT_CLASS  __declspec(dllimport)
#endif // !defined(_AFXDLL) || defined(_CODE_ROCK_UTILITIES_STATICLINK)

#define _PROJECT1_FILE_VERSION_STRING_(x) #x
#define _PROJECT1_STRING(x) _PROJECT1_FILE_VERSION_STRING_(x)

/*---------------------------------------------------------------------------
	Defines for the suffixes of the library file name to be automatically linked:
	 The library file name to be auto-linked is made up of the following:
		- Library base name: Project1
		- Library Version suffix:  100
		- Static lib or import lib for dll suffix. 
			If it is an import library for dll, then, the suffix is: 
			If it is a static library, then , the suffix is: _S
		- Debug or release suffix.
			If the library is release version, then the suffix is: 
			If the library is debug version, then the suffix is:   _D
		- Unicode or Ansi suffix. 
			If the library is Unicode, then the suffix is: _U
			If the library is ANSI , then the suffix is: 
		-  C-Runtime Library (CRT) suffix. 
			If the library is linked dynamically to CRT, then the suffix is: _DCRT
			If the library is linked statically to CRT, then the suffix is: _SCRT
			Notice that linking MFC library follows the same CRT library linking method.
		- Multithreaded or single-threaded CRT is used for linking. 
		   If the library is single-threaded, then the suffix is: _ST
		   If the library is multi-threaded, then the suffix is: 
		- 32-bit or 64-bit platform suffix: 
			If the library is 32-bit, then the suffix is: 
			If the library is 64-bit, then the suffix is: _X64
		9- Visual Studio version suffix:  
		
		For now, the order of the library file name parts is as follows:
		LibraryBaseName + FileVersion + ConfigurationSuffix + VisualStudioSuffix
		
		Where ConfigurationSuffix = CRTSuffix + UnicodeSuffix + DebugSuffix + PlatformSuffix
		CRTSuffix = CRTDllSuffix + DLLImportLibSuffix + CRTThreadingSuffix
		CRTDllSuffix =  "_DCRT" if the library uses CRT dynamically OR "_SCRT" if linked statically to CRT
		DLLImportLibSuffix = "_S" if the library is static OR "" if it is an import library 
		CRTThreadingSuffix = "_ST" for single threading CRT OR "" for multithreaded
		UnicodeSuffix = "_U" if the library is Unicode OR "" if it is an ANSI library
		DebugSuffix = "_D" if the library is Debug OR "" if it is Release
		PlatformSuffix = "_X64" if the library is 64-bit OR "" if it is 32-bit


#define _PROJECT1_CRT_SUFFIX _CODE_ROCK_CRT_DLL_SUFFIX _CODE_ROCK_DLL_IMPORT_LIB_SUFFIX _CODE_ROCK_CRT_THREADED_SUFFIX
#define _CODE_ROCK_UTILITIES_UNICODE_DEBUG_PLATFORM_SUFFIX _CODE_ROCK_UNICODE_SUFFIX _CODE_ROCK_DEBUG_SUFFIX _CODE_ROCK_PLATFORM_SUFFIX
#define _CODE_ROCK_UTILITIES_CONFIG_SUFFIX _CODE_ROCK_UTILITIES_CRT_SUFFIX _CODE_ROCK_UTILITIES_UNICODE_DEBUG_PLATFORM_SUFFIX _CODE_ROCK_VISUALSTUIDO_VERSION
*/

//Visual studio version suffix
#if !defined(_PROJECT1_DEMOMODE) && !defined(_PROJECT1_RETAIL)
#define _PROJECT1_VISUALSTUDIO_VERSION ""
#else
#if _MSC_VER < 1200
#define _PROJECT1_VISUALSTUDIO_VERSION "_vc50"
#endif
#if _MSC_VER == 1200
#define _PROJECT1_VISUALSTUDIO_VERSION "_vc60"
#endif
#if _MSC_VER == 1300
#define _PROJECT1_VISUALSTUDIO_VERSION "_vc70"
#endif
#if _MSC_VER == 1310
#define _PROJECT1_VISUALSTUDIO_VERSION "_vc71"
#endif
#if _MSC_VER == 1400
#define _PROJECT1_VISUALSTUDIO_VERSION "_vc80"
#endif
#if _MSC_VER == 1500
#define _PROJECT1_VISUALSTUDIO_VERSION "_vc90"
#endif


#ifndef _PROJECT1_VISUALSTUDIO_VERSION
#error "Unknown Visual Studio version"
#endif
#endif

//CRT suffixes
/*
	By default, if the application is linked to CRT dynamically, then we link to dynamically
	otherwise, we link statically. If the application is linked dynamically to CRT, then 
	to choose static lib configuration, a macro _PROJECT1_STATICLINK must be defined.
*/
#if !defined(_PROJECT1_STATICLINK)
	#ifdef _DLL
		#define _PROJECT1_CRT_DLL_SUFFIX	"_DCRT"
		#define _PROJECT1_DLL_IMPORT_LIB_SUFFIX ""
	#else
		#define _PROJECT1_CRT_DLL_SUFFIX	"_SCRT"
		#define _PROJECT1_DLL_IMPORT_LIB_SUFFIX	"_S"
	#endif 
#else
	#ifdef _DLL
		#define _PROJECT1_CRT_DLL_SUFFIX	"_DCRT"
		#define _PROJECT1_DLL_IMPORT_LIB_SUFFIX	"_S"
	#else
		#define _PROJECT1_CRT_DLL_SUFFIX	"_SCRT"
		#define _PROJECT1_DLL_IMPORT_LIB_SUFFIX	"_S"
	#endif 

#endif //!defined(_CODE_ROCK_UTILITIES_STATICLINK)

#ifdef _MT
#define _PROJECT1_CRT_THREADED_SUFFIX	""
#else
#define _PROJECT1_CRT_THREADED_SUFFIX	"_ST"
#endif 



//Debug suffix
#ifdef _DEBUG
#define _PROJECT1_DEBUG_SUFFIX	"_D"
#else
#define _PROJECT1_DEBUG_SUFFIX	""
#endif 

//Unicode suffix
#if defined(_UNICODE) || defined(UNICODE)
#define _PROJECT1_UNICODE_SUFFIX	"_U"
#else
#define _PROJECT1_UNICODE_SUFFIX	""
#endif 


//64/32-bit suffix
#if defined(_M_IX86)
	#define _PROJECT1_PLATFORM_SUFFIX	""
#elif defined(_M_X64)
	#define _PROJECT1_PLATFORM_SUFFIX	"_X64"
#else
	#error "Unsupported platform. Only Intel IX86 and AMD64 platforms are supported."
#endif 

//Define for the project configuration suffix that includes all of the suffixes (apart from the file version)

#define _PROJECT1_CRT_SUFFIX _PROJECT1_CRT_DLL_SUFFIX _PROJECT1_DLL_IMPORT_LIB_SUFFIX _PROJECT1_CRT_THREADED_SUFFIX
#define _PROJECT1_UNICODE_DEBUG_PLATFORM_SUFFIX _PROJECT1_UNICODE_SUFFIX _PROJECT1_DEBUG_SUFFIX _PROJECT1_PLATFORM_SUFFIX
#define _PROJECT1_CONFIG_SUFFIX _PROJECT1_CRT_SUFFIX _PROJECT1_UNICODE_DEBUG_PLATFORM_SUFFIX _PROJECT1_VISUALSTUDIO_VERSION


//The file version and the name of the file
#define _PROJECT1_FILE_VERSION _PROJECT1_STRING(_PROJECT1_VERSION_PREFIX)
#define _PROJECT1_LIBRARY_FILE_NAME _PROJECT1_PACKAGE_NAME _PROJECT1_FILE_VERSION _PROJECT1_CONFIG_SUFFIX ".lib"



#ifndef _PROJECT1_NOAUTOLINK
	#pragma comment(lib,  _PROJECT1_LIBRARY_FILE_NAME )
	#pragma message("Automatically linking with " _PROJECT1_LIBRARY_FILE_NAME )
#endif //#ifndef _PROJECT1_NOAUTOLINK

#undef _PROJECT1_FILE_VERSION
#undef _PROJECT1_CONFIG_SUFFIX
#undef _PROJECT1_LIBRARY_FILE_NAME



#endif //#ifnedef _PROJECT1_AUTO_LINK_HEADER_FILE_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
As a professional software developer with more than 6 years experience, I've involved in a variety of projects in many areas. I started with developing desktop applications for Windows 95 (both 16-bit and 32-bit programs), moved to developing client/server applications using Windows NT technologies, and now I'm up to my ears working with .NET development.

Comments and Discussions