]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxBuildOptions and check that they are the same for the program and the library...
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 7 May 2002 19:56:43 +0000 (19:56 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 7 May 2002 19:56:43 +0000 (19:56 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15409 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/app.h
include/wx/build.h [new file with mode: 0644]
src/common/appcmn.cpp

index 226be5346fe3ef330bec37e4be7d84914a4fdc3c..801c549d6483df0d0b7590bc0e30cba1085da793 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// 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
@@ -51,6 +51,8 @@ class WXDLLEXPORT wxCmdLineParser;
     #include "wx/icon.h"
 #endif
 
+#include "wx/build.h"
+
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
@@ -321,6 +323,11 @@ public:
     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!
     // -------------------------------------------------------------
 
@@ -539,9 +546,19 @@ public:
     #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; }
diff --git a/include/wx/build.h b/include/wx/build.h
new file mode 100644 (file)
index 0000000..58e2a0d
--- /dev/null
@@ -0,0 +1,55 @@
+///////////////////////////////////////////////////////////////////////////////
+// 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_
+
index 314a7654eb7f4ca830d5c843d318f4c536fbb288..a53be00281a6a70525a58c3dfe2a90992a83493e 100644 (file)
   #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
@@ -348,8 +349,39 @@ bool wxAppBase::OnCmdLineError(wxCmdLineParser& parser)
 // 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)
 {