link_wxWidgets.xcpjh


//////////////////// wxWidgets //////////////////////
/*
It is possible to use downloaded versions of the wxWidgets DLLs.  However, it is better to build 
these ourselves, so 

    -   we have the pdb files for debugging

    -   the references to the source code are correct for easy debugging

    -   support Windows XP

    -   support static libraries which static link to the CRT (to make it easier to create 
        applications that have as few dependencies on DLLs as possible).

Path if use DLLs
----------------

If DLLs are used then the following C++ setting is required or else linker errors result:

    /D "WXUSINGDLL"

It also requires both

    $\ThirdParty.Ceda\wxWidgets\wxWidgets-3.1.0\lib\vc12_x64_dll;
    $\ThirdParty.Ceda\wxWidgets\wxWidgets-3.1.0\lib\vc12_x86_dll;
    
to be added to the path.  Note that the x64 dll names have 'x64' in the filename, and therefore the
appropriate dll is loaded as required.

Configurations which are already present
----------------------------------------

Win32|Debug
Win32|Release
x64|Debug
x64|Release
    Output:                 $(wxOutDir)
    Intermediate:           $(wxIntRootDir)$(ProjectName)\
    Target Extension:       .lib
    Platform toolset:       Visual Studio 2013 (v120)
    Configuratgion type:    Static library (.lib)
    Addional includes:      $(OutDir)$(wxIncSubDir);
                            ..\..\include;
                            ..\..\src\tiff\libtiff;
                            ..\..\src\jpeg;
                            ..\..\src\png;
                            ..\..\src\zlib;
                            ..\..\src\regex;
                            ..\..\src\expat\lib;
                            %(AdditionalIncludeDirectories)
    Runtime library:        Multithreaded Debug DLL /MDd    (Debug)
                            Multithreaded DLL       /MD     (Release)

Win32|DLL Debug
Win32|DLL Release
x64|DLL Debug
x64|DLL Release
    Output:                 $(wxOutDir)
    Intermediate:           $(wxIntRootDir)$(ProjectName)\
    Target Extension:       .dll
    Platform toolset:       Visual Studio 2013 (v120)
    Configuratgion type:    Dynamic library (.dll)
    Addional includes:      $(OutDir)$(wxIncSubDir);
                            ..\..\include;
                            ..\..\src\tiff\libtiff;
                            ..\..\src\jpeg;
                            ..\..\src\png;
                            ..\..\src\zlib;
                            ..\..\src\regex;
                            ..\..\src\expat\lib;
                            %(AdditionalIncludeDirectories)
    Runtime library:        Multithreaded Debug DLL /MDd    (Debug)
                            Multithreaded DLL       /MD     (Release)

---> creates

    lib/
        vc_dll                  Win32|DLL Debug     ,    Win32|DLL Release
        vc_lib                  Win32|Debug         ,    Win32|Release
        vc_x64_dll              x64|DLL Debug       ,    x64|DLL Release
        vc_x64_lib              x64|Debug           ,    x64|Release

setup.h in project _custom_build has custom build tool with command line:
    copy "%(FullPath)" $(OutDir)$(wxIncSubDir)\wx\setup.h


To build wxWidgets (v3.1.0 released on Feb 29 2016) 
------------------

1) Download wxWidgets-3.1.0.7z from https://github.com/wxWidgets/wxWidgets/releases/tag/v3.1.0
   and unzip to $\ThirdParty.Ceda\wxWidgets\wxWidgets-3.1.0

2) Replace the files
        wx_config.props
        wx_setup.props
   in
        $\ThirdParty.Ceda\wxWidgets\wxWidgets-3.1.0\build\msw
   with the new versions checked into the CEDA repository in
        $\Ceda\_BUILD\Init

   (maybe first diff with existing wx_config.props and wx_setup.props files to verify that the changes are appropriate, 
    may not be for future versions of wxWidgets)

3) Open solution :  $\ThirdParty.Ceda\wxWidgets\wxWidgets-3.1.0\build\msw\wx_vc12.sln
   (this is for Visual Studio 2013)

4) Add "Batch Build..." menu item to the BUILD menu in VS2013 express

    Microsoft "hide" the batch build function in the express version, but it is easy to make it
    available:
    - From menu select Tools/Customise...
    - Select Commands tab
    - For Menu Bar select 'Build' in drop down combo
    - Click 'Add Command...' button
    - Select 'Batch Build' command

5) [not sure whether to do this or not, at the moment not]
   Turn off exceptions:
   Edit the file:  $\ThirdParty.Ceda\wxWidgets\wxWidgets-3.1.0\include\wx\msw\setup.h.
   (this can be found under the _custom_build project)
   Change wxUSE_EXCEPTIONS from 1 to 0:

        #define wxUSE_EXCEPTIONS    0

6) [this is a patch needed for 3.1.0 which otherwise doesn't build with VS2013 when XP toolset is used, should not be 
    needed with later versions of wxWidgets]

   To avoid this error:
        include\wx/msw/rt/utils.h(20): fatal error C1083: Cannot open include file: 'winstring.h': No such file or directory
   Make the following change in wxWidgets-3.1.0\include\wx\msw\setup.h
        #if defined(_MSC_VER) && _MSC_VER >= 1700 && !_USING_V110_SDK71_
            #define wxUSE_WINRT 1
        #else
            #define wxUSE_WINRT 0
        #endif

7) [not needed because this is taken care of in the updated wx_config.props from step 2]
   Select all projects except _custom_build, right click properties
        
       set Configuration = All Configurations
       set Platform = All Platforms
       On General tab, set Platform Toolset =  Visual Studio 2013 - Windows XP (v120_xp)

8) Select all projects including _custom_build, right click properties
   Click on "Configuration Manager..." button
   In Active solution configuration combo select "New..."
       In dialog 
          Name:                                 MT Debug
          Copy setting from:                    Debug
          Create new project configurations:    checked
   In Active solution configuration combo select "New..."
       In dialog 
          Name:                                 MT Release
          Copy setting from:                    Release
          Create new project configurations:    checked

9) Select all projects except _custom_build, right click properties
        Select configuration        : MT Debug
        Select platform             : Win32
        C/C++
            Code Generation
                Runtime Library     : /MTd  
        Click Apply

        Select configuration        : MT Release
        Select platform             : Win32
        C/C++
            Code Generation
                Runtime Library     : /MT
        Click Apply

        Select configuration        : MT Debug
        Select platform             : x64
        C/C++
            Code Generation
                Runtime Library     : /MTd  
        Click Apply

        Select configuration        : MT Release
        Select platform             : x64
        C/C++
            Code Generation
                Runtime Library     : /MT
        Click Apply

10) Select "Batch build..." under the "Build" menu, select all build configurations then click build button

11) Check that all 288 succeeded, none failed

12) Verify that the following folders are created under $\ThirdParty.Ceda\wxWidgets\wxWidgets-3.1.0\lib:
        vc12_x86_dll
        vc12_x86_lib_crtdll
        vc12_x86_lib_crtstatic
        vc12_x64_dll
        vc12_x64_lib_crtdll
        vc12_x64_lib_crtstatic

    Note that this wxWidgets.xcpp is configured to use the output of the build under this 'lib' folder directly 
    without any need to move files.

13) In a project which uses the wxWidget DLLs, the path to the wxWidget DLLs must be available when running the 
    application

    - Go to project properties (Alt+F7)

    - Under Debugging, look to the right
      There's an Environment field.
      For platform x64 add the following:
          PATH=C:\developer\_root_\ThirdParty.Ceda\wxWidgets\wxWidgets-3.1.0\lib\vc12_x64_dll;C:\msys32\mingw64\bin;%PATH%
      For platform Win32 add the following:
          PATH=C:\developer\_root_\ThirdParty.Ceda\wxWidgets\wxWidgets-3.1.0\lib\vc12_x86_dll;C:\msys32\mingw32\bin;%PATH%

    - Hit F5 (debug) it should work
*/

@if (IsWindowsPlatform)
{    
    $WXWIDGETS_VERSION_SHORT = "31"
    $WXWIDGETS_VERSION_FULL = "3.1.0"
    $WXWIDGETS = "$(PATH_TO_ROOT)/ThirdParty.Ceda/wxWidgets/wxWidgets-$(WXWIDGETS_VERSION_FULL)"

    +cpp
    {
        /D "CEDA_USING_WXWIDGETS"
        /I "$(WXWIDGETS)/include"
    }

    @if (UseStaticCRT)
    {
        $WXWIDGETS_LIB32 = "$(WXWIDGETS)/lib/$(COMPILER)_x86_lib_crtstatic"
        $WXWIDGETS_LIB64 = "$(WXWIDGETS)/lib/$(COMPILER)_x64_lib_crtstatic"
    }
    @else
    {
        $WXWIDGETS_LIB32 = "$(WXWIDGETS)/lib/$(COMPILER)_x86_dll"
        $WXWIDGETS_LIB64 = "$(WXWIDGETS)/lib/$(COMPILER)_x64_dll"
    }

    +cpp("Win32|Debug")
    {
        /I "$(WXWIDGETS_LIB32)/mswud"
    }

    +cpp("Win32|Release")
    {
        /I "$(WXWIDGETS_LIB32)/mswu"
    }

    +cpp("x64|Debug")
    {
        /I "$(WXWIDGETS_LIB64)/mswud"
    }

    +cpp("x64|Release")
    {
        /I "$(WXWIDGETS_LIB64)/mswu"
    }

    +link("Win32")
    {
        /LIBPATH:"$(WXWIDGETS_LIB32)"
    }

    +link("x64")
    {
        /LIBPATH:"$(WXWIDGETS_LIB64)"
    }

    +rc
    {
        /I "$(WXWIDGETS)/include"
    }

    +cpp
    {
        /D "__WXMSW__"
        @if (!UseStaticCRT)
        {
            /D "WXUSINGDLL"         // Without this will get linker errors
        }
    }

    +cpp( "Debug" )
    {
        /D "__WXDEBUG__"
    }

    +link( "Release" )
    {
        "wxbase$(WXWIDGETS_VERSION_SHORT)u.lib"
        "wxbase$(WXWIDGETS_VERSION_SHORT)u_net.lib"
        "wxbase$(WXWIDGETS_VERSION_SHORT)u_xml.lib"
        "wxexpat.lib"
        "wxjpeg.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)u_adv.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)u_aui.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)u_core.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)u_gl.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)u_html.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)u_media.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)u_propgrid.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)u_qa.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)u_ribbon.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)u_richtext.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)u_stc.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)u_webview.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)u_xrc.lib"
        "wxpng.lib"
        "wxregexu.lib"
        "wxscintilla.lib"
        "wxtiff.lib"
        "wxzlib.lib"
    
        "comctl32.lib"
        "rpcrt4.lib"
        "winmm.lib"
        "wsock32.lib"
    }

    +link( "Debug" )
    {
        "wxbase$(WXWIDGETS_VERSION_SHORT)ud.lib"
        "wxbase$(WXWIDGETS_VERSION_SHORT)ud_net.lib"
        "wxbase$(WXWIDGETS_VERSION_SHORT)ud_xml.lib"
        "wxexpatd.lib"
        "wxjpegd.lib"

        "wxmsw$(WXWIDGETS_VERSION_SHORT)ud_adv.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)ud_aui.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)ud_core.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)ud_gl.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)ud_html.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)ud_media.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)ud_propgrid.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)ud_qa.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)ud_ribbon.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)ud_richtext.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)ud_stc.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)ud_webview.lib"
        "wxmsw$(WXWIDGETS_VERSION_SHORT)ud_xrc.lib"

        "wxpngd.lib"
        "wxregexud.lib"
        "wxscintillad.lib"
        "wxtiffd.lib"
        "wxzlibd.lib"
    
        "comctl32.lib"
        "rpcrt4.lib"
        "winmm.lib"
        "wsock32.lib"
    }
}

/*
Using MSYS2
-----------

Find out named of the wxWidgets packages
----------------------------------------

$ pacman -Ss | grep 'wxWidgets'
$ pacman -Ss wxWidgets

    mingw32/mingw-w64-i686-wxPython 3.0.2.0-4
        A wxWidgets GUI toolkit for Python (mingw-w64)
    mingw32/mingw-w64-i686-wxWidgets 3.0.2-13
        A C++ library that lets developers create applications for Windows, Linux and UNIX (mingw-w64)
    mingw64/mingw-w64-x86_64-wxPython 3.0.2.0-4
        A wxWidgets GUI toolkit for Python (mingw-w64)
    mingw64/mingw-w64-x86_64-wxWidgets 3.0.2-13
        A C++ library that lets developers create applications for Windows, Linux and UNIX (mingw-w64)

on 22/Aug/2016 3.0.2 is indeed the latest stable release

Install wxWidgets
-----------------

$ pacman -S mingw32/mingw-w64-i686-wxWidgets
    resolving dependencies...
    looking for conflicting packages...

    Packages (2) mingw-w64-i686-cppunit-1.13.2-4  mingw-w64-i686-wxWidgets-3.0.2-13

    Total Download Size:    15.13 MiB
    Total Installed Size:  104.75 MiB

    :: Proceed with installation? [Y/n] y
    :: Retrieving packages...
     mingw-w64-i686-cppunit-1.13.2-4-any                      193.0 KiB   256K/s 00:01 [###############################################] 100%
     mingw-w64-i686-wxWidgets-3.0.2-13-any                     14.9 MiB   247K/s 01:02 [###############################################] 100%
    (2/2) checking keys in keyring                                                     [###############################################] 100%
    (2/2) checking package integrity                                                   [###############################################] 100%
    (2/2) loading package files                                                        [###############################################] 100%
    (2/2) checking for file conflicts                                                  [###############################################] 100%
    (2/2) checking available disk space                                                [###############################################] 100%
    :: Processing package changes...
    (1/2) installing mingw-w64-i686-cppunit                                            [###############################################] 100%
    (2/2) installing mingw-w64-i686-wxWidgets                                          [###############################################] 100%

$ pacman -S mingw64/mingw-w64-x86_64-wxWidgets
    resolving dependencies...
    looking for conflicting packages...

    Packages (2) mingw-w64-x86_64-cppunit-1.13.2-4  mingw-w64-x86_64-wxWidgets-3.0.2-13

    Total Download Size:    15.42 MiB
    Total Installed Size:  111.58 MiB

    :: Proceed with installation? [Y/n] y
    :: Retrieving packages...
     mingw-w64-x86_64-cppunit-1.13.2-4-any                    191.1 KiB   256K/s 00:01 [###############################################] 100%
     mingw-w64-x86_64-wxWidgets-3.0.2-13-any                   15.2 MiB   250K/s 01:02 [###############################################] 100%
    (2/2) checking keys in keyring                                                     [###############################################] 100%
    (2/2) checking package integrity                                                   [###############################################] 100%
    (2/2) loading package files                                                        [###############################################] 100%
    (2/2) checking for file conflicts                                                  [###############################################] 100%
    (2/2) checking available disk space                                                [###############################################] 100%
    :: Processing package changes...
    (1/2) installing mingw-w64-x86_64-cppunit                                          [###############################################] 100%
    (2/2) installing mingw-w64-x86_64-wxWidgets                                        [###############################################] 100%

Created libraries
-----------------

The following DLLs

       size            name
    -----------------------------------------
    2,572,955 wxbase30u_gcc_custom.dll
      329,771 wxbase30u_net_gcc_custom.dll
       66,859 wxbase30u_xml_gcc_custom.dll
    1,649,632 wxmsw30u_adv_gcc_custom.dll
      575,602 wxmsw30u_aui_gcc_custom.dll
    6,714,629 wxmsw30u_core_gcc_custom.dll
      118,109 wxmsw30u_gl_gcc_custom.dll
      868,298 wxmsw30u_html_gcc_custom.dll
      883,705 wxmsw30u_propgrid_gcc_custom.dll
      199,663 wxmsw30u_qa_gcc_custom.dll
      564,518 wxmsw30u_ribbon_gcc_custom.dll
    1,642,429 wxmsw30u_richtext_gcc_custom.dll
    2,487,995 wxmsw30u_stc_gcc_custom.dll
      165,714 wxmsw30u_webview_gcc_custom.dll
    1,423,156 wxmsw30u_xrc_gcc_custom.dll

    (total about 19MB)

are created in 
        C:\msys32\mingw32\bin
and     C:\msys32\mingw64\bin

The includes are in
        C:\msys32\mingw32\include\wx-3.0\wx
and
        C:\msys32\mingw64\include\wx-3.0\wx

Find compiler switches to be used by running wx-config
------------------------------------------------------

$ /mingw32/bin/wx-config --cppflags
    -I/mingw32/lib/wx/include/msw-unicode-3.0 -I/mingw32/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__

$ /mingw64/bin/wx-config --cppflags
    -I/mingw64/lib/wx/include/msw-unicode-3.0 -I/mingw64/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__

Find libraries to use
---------------------

$ /mingw32/bin/wx-config --libs
    -L/mingw32/lib   -pipe -Wl,--subsystem,windows -mwindows -lwx_mswu_xrc-3.0 -lwx_mswu_webview-3.0 -lwx_mswu_html-3.0 -lwx_mswu_qa-3.0 -lwx_mswu_adv-3.0 -lwx_mswu_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0

$ /mingw32/bin/wx-config --libs --gl-libs
    -lwx_mswu_gl-3.0
    -L/mingw32/lib   -pipe -Wl,--subsystem,windows -mwindows -lwx_mswu_xrc-3.0 -lwx_mswu_webview-3.0 -lwx_mswu_html-3.0 -lwx_mswu_qa-3.0 -lwx_mswu_adv-3.0 -lwx_mswu_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0

$ /mingw64/bin/wx-config --libs
    -L/mingw64/lib   -pipe -Wl,--subsystem,windows -mwindows -lwx_mswu_xrc-3.0 -lwx_mswu_webview-3.0 -lwx_mswu_html-3.0 -lwx_mswu_qa-3.0 -lwx_mswu_adv-3.0 -lwx_mswu_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0

$ /mingw64/bin/wx-config --libs --gl-libs
    -lwx_mswu_gl-3.0
    -L/mingw64/lib   -pipe -Wl,--subsystem,windows -mwindows -lwx_mswu_xrc-3.0 -lwx_mswu_webview-3.0 -lwx_mswu_html-3.0 -lwx_mswu_qa-3.0 -lwx_mswu_adv-3.0 -lwx_mswu_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0

    -lwx_mswu_gl-3.0
    -L/mingw32/lib   
    -pipe -Wl,--subsystem,windows 
    -mwindows 
    -lwx_mswu_xrc-3.0 
    -lwx_mswu_webview-3.0 
    -lwx_mswu_html-3.0 
    -lwx_mswu_qa-3.0 
    -lwx_mswu_adv-3.0 
    -lwx_mswu_core-3.0 
    -lwx_baseu_xml-3.0 
    -lwx_baseu_net-3.0 
    -lwx_baseu-3.0
*/

// problems encountered, need to revisit, for now build wxWidgets on Windows directly
@if (false)
{
@if (IsWindowsPlatform)
{    
    $WXWIDGETS_VERSION = "3.0.2"
    $WXWIDGETS = "$(PATH_TO_ROOT)/ThirdParty.Ceda/wxWidgets/wxWidgets-$(WXWIDGETS_VERSION)"

    +cpp
    {
        /D "CEDA_USING_WXWIDGETS"
        /D "__WXMSW__"
        /D "WXUSINGDLL"         // Without this will get linker errors
        /D "_FILE_OFFSET_BITS=64"
    }
    +cpp("Win32")
    {
        /I "C:/msys32/mingw32/lib/wx/include/msw-unicode-3.0"
        /I "C:/msys32/mingw32/include/wx-3.0"
    }
    +cpp("x64")
    {
        /I "C:/msys32/mingw64/lib/wx/include/msw-unicode-3.0"
        /I "C:/msys32/mingw64/include/wx-3.0"
    }

    +rc
    {
        /I "C:/msys32/mingw32/include/wx-3.0"
    }

    +link("Win32")
    {
        /LIBPATH:"C:/msys32/mingw32/lib"
    }
    +link("x64")
    {
        /LIBPATH:"C:/msys32/mingw64/lib"
    }
    +link
    {
        "wxbase30u_gcc_custom.lib"
        "wxbase30u_net_gcc_custom.lib"
        "wxbase30u_xml_gcc_custom.lib"
        "wxmsw30u_adv_gcc_custom.lib"
        "wxmsw30u_aui_gcc_custom.lib"
        "wxmsw30u_core_gcc_custom.lib"
        "wxmsw30u_gl_gcc_custom.lib"
        "wxmsw30u_html_gcc_custom.lib"
        "wxmsw30u_propgrid_gcc_custom.lib"
        "wxmsw30u_qa_gcc_custom.lib"
        "wxmsw30u_ribbon_gcc_custom.lib"
        "wxmsw30u_richtext_gcc_custom.lib"
        "wxmsw30u_stc_gcc_custom.lib"
        "wxmsw30u_webview_gcc_custom.lib"
        "wxmsw30u_xrc_gcc_custom.lib"
    }
}
} // false


@if (IsMacOSXPlatform)
{
    // installed using brew install wxwidgets
    +cpp
    {
        //-I/usr/local/lib/wx/include/osx_cocoa-unicode-3.0 -I/usr/local/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DwxDEBUG_LEVEL=0 -DWXUSINGDLL -D__WXMAC__ -D__WXOSX__ -D__WXOSX_COCOA__ 
        `wx-config --cppflags`
        -Wno-potentially-evaluated-expression
        -Wno-deprecated-declarations
        -Wno-unused-local-typedef
    }
    +link
    {
        `wx-config --libs --gl-libs` -framework OpenGL
    }

}