From 20125017a4bccd0920ee21e178950b0de0e4d63b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 13 Jul 2013 02:30:21 +0000 Subject: [PATCH] Extract compiler-specific macro definitions in a new wx/compiler.h. This solves the problem with wx/defs.h -> wx/platform.h -> wx/setup.h which resolves to msvc/wx/setup.h -> wx/version.h -> wx/cpp.h include path which resulted in __VISUALC__ not being defined in wx/cpp.h. This problem was not new but went unnoticed for a long time and was only discovered when wxCHECK_VISUALC_VERSION() started being used in wx/cpp.h too as now the compiler started warning about wrong #if syntax due to it being undefined. Putting the compiler-specific definitions in a separate file allows this file to be included from wx/cpp.h to ensure that these symbols are always defined in it and also makes things a little better organized. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74496 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- Makefile.in | 2 + build/bakefiles/files.bkl | 1 + build/msw/wx_base.dsp | 4 + build/msw/wx_vc7_base.vcproj | 3 + build/msw/wx_vc8_base.vcproj | 4 + build/msw/wx_vc9_base.vcproj | 4 + include/wx/compiler.h | 152 +++++++++++++++++++++++++++++++++++ include/wx/cpp.h | 4 +- include/wx/platform.h | 141 +------------------------------- wxGTK.spec | 1 + wxMotif.spec | 1 + wxX11.spec | 1 + 12 files changed, 180 insertions(+), 138 deletions(-) create mode 100644 include/wx/compiler.h diff --git a/Makefile.in b/Makefile.in index 4fd47ec055..3219e9000d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -359,6 +359,7 @@ ALL_BASE_HEADERS = \ wx/clntdata.h \ wx/cmdargs.h \ wx/cmdline.h \ + wx/compiler.h \ wx/confbase.h \ wx/config.h \ wx/convauto.h \ @@ -540,6 +541,7 @@ ALL_PORTS_BASE_HEADERS = \ wx/clntdata.h \ wx/cmdargs.h \ wx/cmdline.h \ + wx/compiler.h \ wx/confbase.h \ wx/config.h \ wx/convauto.h \ diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 787e7c64c2..b9e003d94d 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -406,6 +406,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! wx/clntdata.h wx/cmdargs.h wx/cmdline.h + wx/compiler.h wx/confbase.h wx/config.h wx/convauto.h diff --git a/build/msw/wx_base.dsp b/build/msw/wx_base.dsp index ff1d09c48c..9f6bac0e6b 100644 --- a/build/msw/wx_base.dsp +++ b/build/msw/wx_base.dsp @@ -937,6 +937,10 @@ SOURCE=..\..\include\wx\cmdline.h # End Source File # Begin Source File +SOURCE=..\..\include\wx\compiler.h +# End Source File +# Begin Source File + SOURCE=..\..\include\wx\confbase.h # End Source File # Begin Source File diff --git a/build/msw/wx_vc7_base.vcproj b/build/msw/wx_vc7_base.vcproj index aacc91ebb4..da4a27793e 100644 --- a/build/msw/wx_vc7_base.vcproj +++ b/build/msw/wx_vc7_base.vcproj @@ -911,6 +911,9 @@ + + diff --git a/build/msw/wx_vc8_base.vcproj b/build/msw/wx_vc8_base.vcproj index cf42bdc050..4647b1ecfb 100644 --- a/build/msw/wx_vc8_base.vcproj +++ b/build/msw/wx_vc8_base.vcproj @@ -1223,6 +1223,10 @@ RelativePath="..\..\include\wx\cmdline.h" > + + diff --git a/build/msw/wx_vc9_base.vcproj b/build/msw/wx_vc9_base.vcproj index 56c7b65eb7..fec80a1207 100644 --- a/build/msw/wx_vc9_base.vcproj +++ b/build/msw/wx_vc9_base.vcproj @@ -1221,6 +1221,10 @@ RelativePath="..\..\include\wx\cmdline.h" > + + diff --git a/include/wx/compiler.h b/include/wx/compiler.h new file mode 100644 index 0000000000..2517a90ad6 --- /dev/null +++ b/include/wx/compiler.h @@ -0,0 +1,152 @@ +/* + * Name: wx/compiler.h + * Purpose: Compiler-specific macro definitions. + * Author: Vadim Zeitlin + * Created: 2013-07-13 (extracted from wx/platform.h) + * Copyright: (c) 1997-2013 Vadim Zeitlin + * Licence: wxWindows licence + */ + +/* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */ + +#ifndef _WX_COMPILER_H_ +#define _WX_COMPILER_H_ + +/* + Compiler detection and related helpers. + */ + +#ifdef __INTEL_COMPILER +# define __INTELC__ +#elif defined(_MSC_VER) + /* + define another standard symbol for Microsoft Visual C++: the standard + one (_MSC_VER) is also defined by some other compilers. + */ +# define __VISUALC__ _MSC_VER + + /* + define special symbols for different VC version instead of writing tests + for magic numbers such as 1200, 1300 &c repeatedly + */ +#if __VISUALC__ < 1100 +# error "This Visual C++ version is too old and not supported any longer." +#elif __VISUALC__ < 1200 +# define __VISUALC5__ +#elif __VISUALC__ < 1300 +# define __VISUALC6__ +#elif __VISUALC__ < 1400 +# define __VISUALC7__ +#elif __VISUALC__ < 1500 +# define __VISUALC8__ +#elif __VISUALC__ < 1600 +# define __VISUALC9__ +#elif __VISUALC__ < 1700 +# define __VISUALC10__ +#elif __VISUALC__ < 1800 +# define __VISUALC11__ +#elif __VISUALC__ < 1900 +# define __VISUALC12__ +#else +# pragma message("Please update wx/compiler.h to recognize this VC++ version") +#endif + +#elif defined(__BCPLUSPLUS__) && !defined(__BORLANDC__) +# define __BORLANDC__ +#elif defined(__WATCOMC__) +#elif defined(__SC__) +# define __SYMANTECC__ +#elif defined(__SUNPRO_CC) +# ifndef __SUNCC__ +# define __SUNCC__ __SUNPRO_CC +# endif /* Sun CC */ +#elif defined(__SC__) +# ifdef __DMC__ +# define __DIGITALMARS__ +# else +# define __SYMANTEC__ +# endif +#endif /* compiler */ + +/* + Macros for checking compiler version. +*/ + +/* + This macro can be used to test the gcc version and can be used like this: + +# if wxCHECK_GCC_VERSION(3, 1) + ... we have gcc 3.1 or later ... +# else + ... no gcc at all or gcc < 3.1 ... +# endif +*/ +#if defined(__GNUC__) && defined(__GNUC_MINOR__) + #define wxCHECK_GCC_VERSION( major, minor ) \ + ( ( __GNUC__ > (major) ) \ + || ( __GNUC__ == (major) && __GNUC_MINOR__ >= (minor) ) ) +#else + #define wxCHECK_GCC_VERSION( major, minor ) 0 +#endif + +/* + This macro can be used to test the Visual C++ version. +*/ +#ifndef __VISUALC__ +# define wxVISUALC_VERSION(major) 0 +# define wxCHECK_VISUALC_VERSION(major) 0 +#else +# define wxVISUALC_VERSION(major) ( (6 + major) * 100 ) +# define wxCHECK_VISUALC_VERSION(major) ( __VISUALC__ >= wxVISUALC_VERSION(major) ) +#endif + +/** + This is similar to wxCHECK_GCC_VERSION but for Sun CC compiler. + */ +#ifdef __SUNCC__ + /* + __SUNCC__ is 0xVRP where V is major version, R release and P patch level + */ + #define wxCHECK_SUNCC_VERSION(maj, min) (__SUNCC__ >= (((maj)<<8) | ((min)<<4))) +#else + #define wxCHECK_SUNCC_VERSION(maj, min) (0) +#endif + +#ifndef __WATCOMC__ +# define wxWATCOM_VERSION(major,minor) 0 +# define wxCHECK_WATCOM_VERSION(major,minor) 0 +# define wxONLY_WATCOM_EARLIER_THAN(major,minor) 0 +# define WX_WATCOM_ONLY_CODE( x ) +#else +# if __WATCOMC__ < 1200 +# error "Only Open Watcom is supported in this release" +# endif + +# define wxWATCOM_VERSION(major,minor) ( major * 100 + minor * 10 + 1100 ) +# define wxCHECK_WATCOM_VERSION(major,minor) ( __WATCOMC__ >= wxWATCOM_VERSION(major,minor) ) +# define wxONLY_WATCOM_EARLIER_THAN(major,minor) ( __WATCOMC__ < wxWATCOM_VERSION(major,minor) ) +# define WX_WATCOM_ONLY_CODE( x ) x +#endif + +/* + This macro can be used to check that the version of mingw32 compiler is + at least maj.min + */ +#if ( defined( __GNUWIN32__ ) || defined( __MINGW32__ ) || \ + ( defined( __CYGWIN__ ) && defined( __WINDOWS__ ) ) || \ + wxCHECK_WATCOM_VERSION(1,0) ) && \ + !defined(__DOS__) && \ + !defined(__WXPM__) && \ + !defined(__WXMOTIF__) && \ + !defined(__WXX11__) +# include "wx/msw/gccpriv.h" +#else +# undef wxCHECK_W32API_VERSION +# define wxCHECK_W32API_VERSION(maj, min) (0) +# undef wxCHECK_MINGW32_VERSION +# define wxCHECK_MINGW32_VERSION(maj, min) (0) +#endif + + +#endif // _WX_COMPILER_H_ + diff --git a/include/wx/cpp.h b/include/wx/cpp.h index f8b1d2ef58..11cdc03c2f 100644 --- a/include/wx/cpp.h +++ b/include/wx/cpp.h @@ -13,6 +13,8 @@ #ifndef _WX_CPP_H_ #define _WX_CPP_H_ +#include "wx/compiler.h" /* wxCHECK_XXX_VERSION() macros */ + /* wxCONCAT works like preprocessor ## operator but also works with macros */ #define wxCONCAT_HELPER(text, line) text ## line @@ -130,7 +132,7 @@ #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ (defined(__cplusplus) && __cplusplus >= 201103L) #define HAVE_VARIADIC_MACROS - #elif defined(__GNUC__) && __GNUC__ >= 3 + #elif wxCHECK_GCC_VERSION(3,0) #define HAVE_VARIADIC_MACROS #elif wxCHECK_VISUALC_VERSION(8) #define HAVE_VARIADIC_MACROS diff --git a/include/wx/platform.h b/include/wx/platform.h index e322e88fce..928ca35743 100644 --- a/include/wx/platform.h +++ b/include/wx/platform.h @@ -164,12 +164,15 @@ # include "wx/android/config_android.h" #endif +#include "wx/compiler.h" + /* Include wx/setup.h for the Unix platform defines generated by configure and the library compilation options Note that it must be included before defining hardware symbols below as they - could be already defined by configure + could be already defined by configure but it must be included after defining + the compiler macros above as msvc/wx/setup.h relies on them under Windows. */ #include "wx/setup.h" @@ -275,25 +278,6 @@ # define wxCOMPILER_BROKEN_CONCAT_OPER #endif /* __BORLANDC__ */ -/* - Define Watcom-specific macros. -*/ -#ifndef __WATCOMC__ -# define wxWATCOM_VERSION(major,minor) 0 -# define wxCHECK_WATCOM_VERSION(major,minor) 0 -# define wxONLY_WATCOM_EARLIER_THAN(major,minor) 0 -# define WX_WATCOM_ONLY_CODE( x ) -#else -# if __WATCOMC__ < 1200 -# error "Only Open Watcom is supported in this release" -# endif - -# define wxWATCOM_VERSION(major,minor) ( major * 100 + minor * 10 + 1100 ) -# define wxCHECK_WATCOM_VERSION(major,minor) ( __WATCOMC__ >= wxWATCOM_VERSION(major,minor) ) -# define wxONLY_WATCOM_EARLIER_THAN(major,minor) ( __WATCOMC__ < wxWATCOM_VERSION(major,minor) ) -# define WX_WATCOM_ONLY_CODE( x ) x -#endif - /* OS: first of all, test for MS-DOS platform. We must do this before testing for Unix, because DJGPP compiler defines __unix__ under MS-DOS @@ -343,12 +327,6 @@ # endif # endif /* SGI */ -# if defined(__SUNPRO_CC) -# ifndef __SUNCC__ -# define __SUNCC__ __SUNPRO_CC -# endif /* Sun CC */ -# endif /* Sun CC */ - # ifdef __EMX__ # define OS2EMX_PLAIN_CHAR # endif @@ -429,46 +407,6 @@ # error "__WIN32__ should be defined for Win32 and Win64, Win16 is not supported" # endif - /* - define another standard symbol for Microsoft Visual C++: the standard - one (_MSC_VER) is also defined by some other compilers. - */ -# if defined(_MSC_VER) -# define __VISUALC__ _MSC_VER - - /* - define special symbols for different VC version instead of writing tests - for magic numbers such as 1200, 1300 &c repeatedly - */ -# if __VISUALC__ < 1100 -# error "This Visual C++ version is too old and not supported any longer." -# elif __VISUALC__ < 1200 -# define __VISUALC5__ -# elif __VISUALC__ < 1300 -# define __VISUALC6__ -# elif __VISUALC__ < 1400 -# define __VISUALC7__ -# elif __VISUALC__ < 1500 -# define __VISUALC8__ -# elif __VISUALC__ < 1600 -# define __VISUALC9__ -# elif __VISUALC__ < 1700 -# define __VISUALC10__ -# elif __VISUALC__ < 1800 -# define __VISUALC11__ -# elif __VISUALC__ < 1900 -# define __VISUALC12__ -# else -# pragma message("Please update wx/platform.h to recognize this VC++ version") -# endif - -# elif defined(__BCPLUSPLUS__) && !defined(__BORLANDC__) -# define __BORLANDC__ -# elif defined(__WATCOMC__) -# elif defined(__SC__) -# define __SYMANTECC__ -# endif /* compiler */ - /* size_t is the same as unsigned int for all Windows compilers we know, */ /* so define it if it hadn't been done by configure yet */ # if !defined(wxSIZE_T_IS_UINT) && !defined(wxSIZE_T_IS_ULONG) && !defined(__WIN64__) @@ -488,18 +426,6 @@ # define __X__ #endif -#ifdef __SC__ -# ifdef __DMC__ -# define __DIGITALMARS__ -# else -# define __SYMANTEC__ -# endif -#endif - -#ifdef __INTEL_COMPILER -# define __INTELC__ -#endif - /* We get "Large Files (ILP32) not supported in strict ANSI mode." #error from HP-UX standard headers when compiling with g++ without this: @@ -515,69 +441,10 @@ # include "wx/msw/libraries.h" #endif -/* - This macro can be used to test the gcc version and can be used like this: - -# if wxCHECK_GCC_VERSION(3, 1) - ... we have gcc 3.1 or later ... -# else - ... no gcc at all or gcc < 3.1 ... -# endif -*/ -#if defined(__GNUC__) && defined(__GNUC_MINOR__) - #define wxCHECK_GCC_VERSION( major, minor ) \ - ( ( __GNUC__ > (major) ) \ - || ( __GNUC__ == (major) && __GNUC_MINOR__ >= (minor) ) ) -#else - #define wxCHECK_GCC_VERSION( major, minor ) 0 -#endif - #if defined(__BORLANDC__) || (defined(__GNUC__) && __GNUC__ < 3) #define wxNEEDS_CHARPP #endif -/* - This macro can be used to test the Visual C++ version. -*/ -#ifndef __VISUALC__ -# define wxVISUALC_VERSION(major) 0 -# define wxCHECK_VISUALC_VERSION(major) 0 -#else -# define wxVISUALC_VERSION(major) ( (6 + major) * 100 ) -# define wxCHECK_VISUALC_VERSION(major) ( __VISUALC__ >= wxVISUALC_VERSION(major) ) -#endif - -/* - This macro can be used to check that the version of mingw32 compiler is - at least maj.min - */ -#if ( defined( __GNUWIN32__ ) || defined( __MINGW32__ ) || \ - ( defined( __CYGWIN__ ) && defined( __WINDOWS__ ) ) || \ - wxCHECK_WATCOM_VERSION(1,0) ) && \ - !defined(__DOS__) && \ - !defined(__WXPM__) && \ - !defined(__WXMOTIF__) && \ - !defined(__WXX11__) -# include "wx/msw/gccpriv.h" -#else -# undef wxCHECK_W32API_VERSION -# define wxCHECK_W32API_VERSION(maj, min) (0) -# undef wxCHECK_MINGW32_VERSION -# define wxCHECK_MINGW32_VERSION(maj, min) (0) -#endif - -/** - This is similar to wxCHECK_GCC_VERSION but for Sun CC compiler. - */ -#ifdef __SUNCC__ - /* - __SUNCC__ is 0xVRP where V is major version, R release and P patch level - */ - #define wxCHECK_SUNCC_VERSION(maj, min) (__SUNCC__ >= (((maj)<<8) | ((min)<<4))) -#else - #define wxCHECK_SUNCC_VERSION(maj, min) (0) -#endif - /* Handle Darwin gcc universal compilation. Don't do this in an Apple- specific case since no sane compiler should be defining either diff --git a/wxGTK.spec b/wxGTK.spec index eb2a1590f6..62ab3c8ef4 100644 --- a/wxGTK.spec +++ b/wxGTK.spec @@ -244,6 +244,7 @@ wx/chkconf.h wx/clntdata.h wx/cmdargs.h wx/cmdline.h +wx/compiler.h wx/confbase.h wx/config.h wx/convauto.h diff --git a/wxMotif.spec b/wxMotif.spec index 2ef607bbff..1925858f8a 100644 --- a/wxMotif.spec +++ b/wxMotif.spec @@ -109,6 +109,7 @@ wx/chkconf.h wx/clntdata.h wx/cmdargs.h wx/cmdline.h +wx/compiler.h wx/confbase.h wx/config.h wx/convauto.h diff --git a/wxX11.spec b/wxX11.spec index 012b91db5f..4e6341b5db 100644 --- a/wxX11.spec +++ b/wxX11.spec @@ -133,6 +133,7 @@ wx/chkconf.h wx/clntdata.h wx/cmdargs.h wx/cmdline.h +wx/compiler.h wx/confbase.h wx/config.h wx/convauto.h -- 2.45.2