dxli/LibreCAD — pull request #7 by tin-pot (2012-01-06 08:55:27+00:00)
Title: Using the boost libraries with MSVC

Hi Dongxu,

regarding your question:

> somewhat related, can you get boost support in windows? currently, boost
> support is only enabled for linux in the project file src.pro:
> DEFINES += HAS_BOOST=1

It turns out to be pretty easy on Windows!

## Using boost on Windows

BoostPro Consulting has [binary installers][1] up to boost v1.47, these are all claimed to be usable for Visual Studio .NET 2003 and onwards. This is not bad, as the very latest version of Boost is 1.48.

The Boost website provides a nice [introductory description][2] on how to install and use boost on Windows with MS compilers.

With that --- using boost version 1.47 --- it is trivial to build LibreCAD with boost. The two affected files are again `common.pro` and `src/src.pro`, no source code changes are needed.

*Note:* I think boost support would be best switched on by adding a flag `boost` to qmake's `CONFIG` variable (I have made this the default for the `win32-msvc2003` makespec); and then set the defines, include dirs, lib dirs etc in platform-specific qmake scopes. I do this (see commit tin-pot@7792531) currently in `common.pro` like so:

win32 {
boost {
# See my comments in common.pro ...
BOOST_LIBS =
DEFINES += HAS_BOOST
INCLUDEPATH += $${BOOST_DIR}
LIBS += -L$${BOOST_DIR}/lib $${BOOST_LIBS}
}
}

I have not put this in win32-msvc2003 scope because there seems nothing MSVC specific about it, but other compilers possibly have no "auto-linking" mechanism and would have to provide the (non-*header-only*) boost libraries in `BOOST_LIBS` explicitly --- and the `BOOST_LIBS =` line could simply be omitted.

(By the way, when building LibreCAD on Windows with QtCreator --- that would mkspec `win32-g++`, not `cygwin-g++` or even something else, right? Just to know who would be affected by changes in `win32` ...)

All this could surely be unified with the *ix platforms.

## C99 support in boost

Maybe of interest regarding boost is that they have some implementations of/replacements
for [C99 (and TR1 C++) functions][3].

Supported and probably useful (for LibreCAD) functions are:

- round() (*used in LibreCAD*)
- lround()
- fmin(), fmax()
- copysign()
- nextafter()
- nexttoward()

Not supported (in neither double, float, long double variants) are:

- remainder() (*used in LibreCAD*)
- rint()
- llrint()
- scalbn()
- nan()
- logb()

I have not tried this boost/C99 stuff out yet. To quote from their documentation:

> Pros:
>
> - The header to include is lightweight (i.e. fast to compile).
> - The functions have extern "C" linkage, and so are usable from other languages
> (not just C and C++).
> - C99 and C++ TR1 Standard compatibility.
>
> Cons:
>
> - You will need to compile and link to the external Boost.Math libraries.
> - Limited to support for the types, float, double and long double.
> - Error handling is handled via setting ::errno and returning NaN's and infinities:
> this may be less flexible than an C++ exception based approach.

Greetings,
Martin

[1]: http://www.boostpro.com/download/ (BoostPro downloads)

[2]: http://www.boost.org/doc/libs/1_47_0/more/getting_started/windows.html (Boost: Getting started on Windows)

[3]: http://www.boost.org/doc/libs/1_47_0/libs/math/doc/sf_and_dist/html/math_toolkit/extern_c/tr1.html (Boost C99/TR1 C functions)