Set BOOST_CPPFLAGS and THREADFLAGS globally

Should fix #1523
Link binaries explicitly with libpthread if needed
Merge pull request #1791 from rubenk/reduce-nr-of-boost-cppflags

Set BOOST_CPPFLAGS and THREADFLAGS globally