前两天初步研究了一下给工程文件添加版本信息的方法,今天在查阅其它资料的时候,又继续挖掘了一些内容,增强一下自己的理解。
在wxWidgets的make.gcc文件中有如下内容:
$(OBJS)\monodll_version_rc.o: ../../src/msw/version.rc
$(WINDRES) -i$< -o$@ --define __WXMSW__ $(__WXUNIV_DEFINE_p_67) $(__DEBUG_DEFINE_p_66) $(__NDEBUG_DEFINE_p_65) $(__EXCEPTIONS_DEFINE_p_65) $(__RTTI_DEFINE_p_65) $(__THREAD_DEFINE_p_65) $(__UNICODE_DEFINE_p_67) $(__MSLU_DEFINE_p_65) --include-dir $(SETUPHDIR) --include-dir ../../include $(__CAIRO_INCLUDEDIR_p) --define WXBUILDING --define WXDLLNAME=wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)$(WXCOMPILER)$(VENDORTAG) --include-dir ../../src/tiff/libtiff --include-dir ../../src/jpeg --include-dir ../../src/png --include-dir ../../src/zlib --include-dir ../../src/regex --include-dir ../../src/expat/lib --include-dir ../../src/stc/scintilla/include --include-dir ../../src/stc/scintilla/lexlib --include-dir ../../src/stc/scintilla/src --define __WX__ --define SCI_LEXER --define LINK_LEXERS --define wxUSE_BASE=1 --define WXMAKINGDLL
其中有个定义是"--define WXDLLNAME=wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)$(WXCOMPILER)$(VENDORTAG) ",再比对version.rc文件,终于明白了如何将make参数中的宏替换至资源文件的方法(以前从网上只言片语中看到,但那时候很不理解怎么回事)
version.rc 内容如下:
///
// Name: src/msw/version.rc
// Purpose: contains version info resource for wxMSW DLL build
// Author: Vadim Zeitlin
// Modified by:
// Created: 09.07.00
// Copyright: (c) 2000 Vadim Zeitlin
// Licence: wxWindows licence
///
#include "wx/version.h"
// see http://msdn.microsoft.com/library/psdk/winui/rc_7x2d.htm for values: we
// don't use symbolic constants because older compilers might not have them
#ifdef WXMAKINGDLL
#define wxVFT 2 // VFT_DLL
#else
#define wxVFT 1 // VFT_APP
#endif
#ifdef _DEBUG
#define DLL_FLAGS 0x1L
#else
#define DLL_FLAGS 0x0L
#endif
// 0x0409 is US English, 0x04b0 is Unicode and 0x0000 is 7 bit ASCII. see
// http://msdn.microsoft.com/en-us/library/aa381049(VS.85).aspx for the full
// list of languages and charsets
#define LANG 0x0409
#ifdef _UNICODE
#define CHARSET 0x4b0
#define LANG_WITH_CHARSET "040904b0"
#else
#define CHARSET 0
#define LANG_WITH_CHARSET "04090000"
#endif
#ifdef WXMAKINGDLL_BASE
#define WXLIBDESC "base"
#elif defined WXMAKINGDLL_NET
#define WXLIBDESC "network"
#elif defined WXMAKINGDLL_CORE
#define WXLIBDESC "core"
#elif defined WXMAKINGDLL_ADV
#define WXLIBDESC "advanced"
#elif defined WXMAKINGDLL_QA
#define WXLIBDESC "qa"
#elif defined WXMAKINGDLL_HTML
#define WXLIBDESC "html"
#elif defined WXMAKINGDLL_GL
#define WXLIBDESC "OpenGL"
#elif defined WXMAKINGDLL_XML
#define WXLIBDESC "XML"
#elif defined WXMAKINGDLL_XRC
#define WXLIBDESC "XRC"
#elif defined WXMAKINGDLL_AUI
#define WXLIBDESC "AUI"
#elif defined WXMAKINGDLL_RIBBON
#define WXLIBDESC "ribbon"
#elif defined WXMAKINGDLL_PROPGRID
#define WXLIBDESC "property grid"
#elif defined WXMAKINGDLL_RICHTEXT
#define WXLIBDESC "rich text"
#elif defined WXMAKINGDLL_MEDIA
#define WXLIBDESC "multimedia"
#elif defined WXMAKINGDLL_STC
#define WXLIBDESC "styled text"
#elif defined WXMAKINGDLL_WEBVIEW
#define WXLIBDESC "webview"
#elif defined WXMAKINGDLL
#define WXLIBDESC "monolithic"
#else
#error "What are we building?"
#endif
1 VERSIONINFO
FILEVERSION wxMAJOR_VERSION,wxMINOR_VERSION,wxRELEASE_NUMBER,wxSUBRELEASE_NUMBER
PRODUCTVERSION wxMAJOR_VERSION,wxMINOR_VERSION,wxRELEASE_NUMBER,wxSUBRELEASE_NUMBER
FILEFLAGSMASK 0x3fL
FILEFLAGS DLL_FLAGS
FILEOS 0x40004L // VOS_NT_WINDOWS32
FILETYPE wxVFT
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK LANG_WITH_CHARSET
BEGIN
VALUE "Comments", "wxWidgets cross-platform GUI framework\0"
VALUE "CompanyName", "wxWidgets development team\0"
VALUE "FileDescription", "wxWidgets " WXLIBDESC " library\0"
VALUE "FileVersion", wxVERSION_NUM_DOT_STRING "\0"
VALUE "InternalName", wxSTRINGIZE(WXDLLNAME) "\0"
VALUE "LegalCopyright", "Copyright ?1993-2013 wxWidgets development team\0"
VALUE "OriginalFilename", wxSTRINGIZE(WXDLLNAME) ".dll\0"
VALUE "ProductName", "wxWidgets\0"
VALUE "ProductVersion", wxVERSION_NUM_DOT_STRING "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", LANG, CHARSET
END
END
看到这样的versioninfo的定义,结合#define中"##","#","@"妙用一文,才发觉宏定义真的太有意思了!
version.h片断:
/* helpers for wxVERSION_NUM_XXX */
#define wxMAKE_VERSION_STRING(x, y, z) \
wxSTRINGIZE(x) wxSTRINGIZE(y) wxSTRINGIZE(z)
#define wxMAKE_VERSION_DOT_STRING(x, y, z) \
wxSTRINGIZE(x) "." wxSTRINGIZE(y) "." wxSTRINGIZE(z)
#define wxMAKE_VERSION_STRING_T(x, y, z) \
wxSTRINGIZE_T(x) wxSTRINGIZE_T(y) wxSTRINGIZE_T(z)
#define wxMAKE_VERSION_DOT_STRING_T(x, y, z) \
wxSTRINGIZE_T(x) wxT(".") wxSTRINGIZE_T(y) wxT(".") wxSTRINGIZE_T(z)
/* these are used by src/msw/version.rc and should always be ASCII, not Unicode */
#define wxVERSION_NUM_STRING \
wxMAKE_VERSION_STRING(wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER)
#define wxVERSION_NUM_DOT_STRING \
wxMAKE_VERSION_DOT_STRING(wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER)
在cpp.h中有wxSTRINGIZE宏定义:
/* wxSTRINGIZE works as the preprocessor # operator but also works with macros */
#define wxSTRINGIZE_HELPER(x) #x
#define wxSTRINGIZE(x) wxSTRINGIZE_HELPER(x)
上图,看看wxWidgets的版本信息