/////////////////////////////////////////////////////////////////////////////
-// Name: app.h
+// Name: wx/app.h
// Purpose: wxAppBase class and macros used for declaration of wxApp
// derived class in the user code
// Author: Julian Smart
#include "wx/icon.h"
#endif
+#include "wx/build.h"
+
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
virtual void OnAssert(const wxChar *file, int line, const wxChar *msg);
#endif // __WXDEBUG__
+ // check that the wxBuildOptions object (constructed in the application
+ // itself, usually the one from IMPLEMENT_APP() macro) matches the build
+ // options of the library and abort if it doesn't
+ static bool CheckBuildOptions(const wxBuildOptions& buildOptions);
+
// deprecated functions, please updae your code to not use them!
// -------------------------------------------------------------
#define IMPLEMENT_WX_THEME_SUPPORT
#endif
+// define the build options object for the application which is compared to the
+// one used for building the library on the program startup
+#define WX_DEFINE_BUILDOPTS() \
+ const wxBuildOptions& wxGetBuildOptions() \
+ { \
+ static wxBuildOptions s_buildOptions; \
+ return s_buildOptions; \
+ }
+
// Use this macro if you want to define your own main() or WinMain() function
// and call wxEntry() from there.
#define IMPLEMENT_APP_NO_MAIN(appname) \
+ WX_DEFINE_BUILDOPTS() \
wxApp *wxCreateApp() { return new appname; } \
wxAppInitializer wxTheAppInitializer((wxAppInitializerFunction) wxCreateApp); \
appname& wxGetApp() { return *(appname *)wxTheApp; }
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: wx/build.h
+// Purpose: wxBuildOptions class declaration
+// Author: Vadim Zeitlin
+// Modified by:
+// Created: 07.05.02
+// RCS-ID: $Id$
+// Copyright: (c) 2002 Vadim Zeitlin <vadim@wxwindows.org>
+// Licence: wxWindows license
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_BUILD_H_
+#define _WX_BUILD_H_
+
+#include "wx/version.h"
+
+// ----------------------------------------------------------------------------
+// wxBuildOptions
+// ----------------------------------------------------------------------------
+
+class wxBuildOptions
+{
+public:
+ // the ctor must be inline to get the compilation settings of the code
+ // which included this header
+ wxBuildOptions()
+ {
+ // debug/release
+#ifdef __WXDEBUG__
+ m_isDebug = TRUE;
+#else
+ m_isDebug = FALSE;
+#endif
+
+ // version: we don't test the micro version as hopefully changes
+ // between 2 micro versions don't result in fatal compatibility
+ // problems
+ m_verMaj = wxMAJOR_VERSION;
+ m_verMin = wxMINOR_VERSION;
+ }
+
+private:
+ // the version
+ int m_verMaj,
+ m_verMin;
+
+ // compiled with __WXDEBUG__?
+ bool m_isDebug;
+
+ // actually only CheckBuildOptions() should be our friend but well...
+ friend class wxAppBase;
+};
+
+#endif // _WX_BUILD_H_
+
#include "wx/mac/private.h" // includes mac headers
#endif
+// private functions prototypes
+#ifdef __WXDEBUG__
+ static void LINKAGEMODE SetTraceMasks();
+#endif // __WXDEBUG__
+
// ===========================================================================
// implementation
// ===========================================================================
// initialization and termination
// ----------------------------------------------------------------------------
-#ifdef __WXDEBUG__
-static void LINKAGEMODE SetTraceMasks()
+wxAppBase::wxAppBase()
{
- wxString mask;
- if ( wxGetEnv(wxT("WXTRACE"), &mask) )
+ // this function is defined by IMPLEMENT_APP() macro in the user code
+ extern const wxBuildOptions& wxGetBuildOptions();
+
+ if ( !CheckBuildOptions(wxGetBuildOptions()) )
{
- wxStringTokenizer tkn(mask, wxT(","));
- while ( tkn.HasMoreTokens() )
- wxLog::AddTraceMask(tkn.GetNextToken());
+ wxLogFatalError(_T("Mismatch between the program and library build ")
+ _T("versions detected."));
}
-}
-#endif
-wxAppBase::wxAppBase()
-{
wxTheApp = (wxApp *)this;
#if WXWIN_COMPATIBILITY_2_2
// debugging support
// ----------------------------------------------------------------------------
+/* static */
+bool wxAppBase::CheckBuildOptions(const wxBuildOptions& opts)
+{
+#define wxCMP(what) (what == opts.m_ ## what)
+
+ bool
+#ifdef __WXDEBUG__
+ isDebug = TRUE;
+#else
+ isDebug = FALSE;
+#endif
+
+ int verMaj = wxMAJOR_VERSION,
+ verMin = wxMINOR_VERSION;
+
+ return wxCMP(isDebug) && wxCMP(verMaj) && wxCMP(verMin);
+
+#undef wxCMP
+}
+
#ifdef __WXDEBUG__
+static void LINKAGEMODE SetTraceMasks()
+{
+ wxString mask;
+ if ( wxGetEnv(wxT("WXTRACE"), &mask) )
+ {
+ wxStringTokenizer tkn(mask, wxT(","));
+ while ( tkn.HasMoreTokens() )
+ wxLog::AddTraceMask(tkn.GetNextToken());
+ }
+}
+
// wxASSERT() helper
bool wxAssertIsEqual(int x, int y)
{