Permalink
Fetching contributors…
Cannot retrieve contributors at this time
237 lines (192 sloc) 10.9 KB

Asio samples

Release License

Branch Linux Windows Coverage Coverity Scan
master Travis CI build status AppVeyor CI build status Linux code coverage status Coverity Scan status
develop Travis CI build status AppVeyor CI build status Linux code coverage status

Examples (code samples) describing the construction of active objects on the top of Boost.Asio.

A code-based guide for client/server creation with usage of active object pattern by means of Boost C++ Libraries.

Building

Below examples assume:

  • Windows Command Prompt with Windows SDK environment set up (for example, VS2015 x64 Native Tools Command Prompt Windows main menu link for Visual Studio 2015 x64) is used on Windows.

  • Current directory is asio_sample_build_dir.

  • This repository is cloned into asio_samples_home_dir directory.

  • ICU library is located at icu_home_dir directory.

  • Header files of Boost C++ Libraries are located at boost_headers_dir directory.

  • Binary files of Boost C++ Libraries are located at boost_libs_dir directory.

  • Qt 5.x is located at qt5_home_dir directory.

  • Qt 4.x is located at qt4_home_dir directory.

  • Google Test libraries are located at gtest_home_dir directory.

  • project_build_configuration is configuration to build, i.e. one of:

    • DEBUG
    • RELEASE
    • RELWITHDEBINFO
    • MINSIZEREL

Building of CMake project is usually performed in 2 phases:

  1. Generation of project for particular build system.
  2. Building using generated project and particular build system.

Generation of project for building

Use ma_build_tests to exclude tests from build (tests are included by default):

cmake -D ma_build_tests=OFF ...

CMake project uses:

To build with static C/C++ runtime it is required:

  • Use CMAKE_USER_MAKE_RULES_OVERRIDE CMake parameter pointing to static_c_runtime_overrides.cmake
  • Use CMAKE_USER_MAKE_RULES_OVERRIDE_CXX CMake parameter pointing to static_cxx_runtime_overrides.cmake
  • Static build of Qt
  • Use ICU_ROOT CMake parameter pointing to root of ICU library (static build, required for Qt).

Note that on Windows cmake-qt searches for some system libraries (OpenGL) therefore to work correctly CMake should be executed after Windows SDK environment was set up (even if Visual Studio generator is used).

Example of generation of Visual Studio 2013 project (static C/C++ runtime, static Boost and static Qt 5, x64):

cmake ^
-D CMAKE_USER_MAKE_RULES_OVERRIDE=asio_samples_home_dir/cmake/static_c_runtime_overrides.cmake ^
-D CMAKE_USER_MAKE_RULES_OVERRIDE_CXX=asio_samples_home_dir/cmake/static_cxx_runtime_overrides.cmake ^
-D ICU_ROOT=icu_home_dir ^
-D BOOST_INCLUDEDIR=boost_headers_dir ^
-D BOOST_LIBRARYDIR=boost_libs_dir ^
-D Boost_NO_SYSTEM_PATHS=ON ^
-D Boost_USE_STATIC_LIBS=ON ^
-D Qt5Core_DIR=qt5_home_dir/lib/cmake/Qt5Core ^
-D Qt5Gui_DIR=qt5_home_dir/lib/cmake/Qt5Gui ^
-D Qt5Widgets_DIR=qt5_home_dir/lib/cmake/Qt5Widgets ^
-D GTEST_ROOT=gtest_home_dir ^
-G "Visual Studio 12 2013 Win64" ^
asio_samples_home_dir

Example of generation of Visual Studio 2015 project (shared C/C++ runtime, static Boost and shared Qt 5, x64):

cmake ^
-D BOOST_INCLUDEDIR=boost_headers_dir ^
-D BOOST_LIBRARYDIR=boost_libs_dir ^
-D Boost_NO_SYSTEM_PATHS=ON ^
-D Boost_USE_STATIC_LIBS=ON ^
-D Qt5Core_DIR=qt5_home_dir/lib/cmake/Qt5Core ^
-D Qt5Gui_DIR=qt5_home_dir/lib/cmake/Qt5Gui ^
-D Qt5Widgets_DIR=qt5_home_dir/lib/cmake/Qt5Widgets ^
-D GTEST_ROOT=gtest_home_dir ^
G "Visual Studio 14 2015 Win64" ^
asio_samples_home_dir

Example of generation of Visual Studio 2015 project (shared C/C++ runtime, shared Boost and shared Qt 5, x64):

cmake ^
-D BOOST_INCLUDEDIR=boost_headers_dir ^ 
-D BOOST_LIBRARYDIR=boost_libs_dir ^
-D Boost_NO_SYSTEM_PATHS=ON ^
-D Boost_USE_STATIC_LIBS=OFF ^
-D Qt5Core_DIR=qt5_home_dir/lib/cmake/Qt5Core ^
-D Qt5Gui_DIR=qt5_home_dir/lib/cmake/Qt5Gui ^
-D Qt5Widgets_DIR=qt5_home_dir/lib/cmake/Qt5Widgets ^
-D GTEST_ROOT=gtest_home_dir ^
-G "Visual Studio 14 2015 Win64" ^
asio_samples_home_dir

Boost_USE_STATIC_LIBS is turned OFF by default according to FindBoost documentation, so -D Boost_USE_STATIC_LIBS=OFF can be omitted.

Example of generation of Visual Studio 2013 project (static C/C++ runtime, static Boost and static Qt 5, x64) for usage with Intel C++ Compiler XE 2015:

cmake ^
-D CMAKE_USER_MAKE_RULES_OVERRIDE=asio_samples_home_dir/cmake/static_c_runtime_overrides.cmake ^
-D CMAKE_USER_MAKE_RULES_OVERRIDE_CXX=asio_samples_home_dir/cmake/static_cxx_runtime_overrides.cmake ^
-D ICU_ROOT=icu_home_dir ^
-D BOOST_INCLUDEDIR=boost_headers_dir ^
-D BOOST_LIBRARYDIR=boost_libs_dir ^
-D Boost_NO_SYSTEM_PATHS=ON ^
-D Boost_USE_STATIC_LIBS=ON ^
-D Qt5Core_DIR=qt5_home_dir/lib/cmake/Qt5Core ^
-D Qt5Gui_DIR=qt5_home_dir/lib/cmake/Qt5Gui ^
-D Qt5Widgets_DIR=qt5_home_dir/lib/cmake/Qt5Widgets ^
-D GTEST_ROOT=gtest_home_dir ^
-D CMAKE_C_COMPILER=icl ^
-D CMAKE_CXX_COMPILER=icl ^
-T "Intel C++ Compiler XE 15.0" ^
-G "Visual Studio 12 2013 Win64" ^
asio_samples_home_dir

Example of generation of Visual Studio 2015 project (shared C/C++ runtime, static Boost and shared Qt 5, x64) for usage with Intel C++ Compiler 2016:

cmake ^
-D ICU_ROOT=icu_home_dir ^
-D BOOST_INCLUDEDIR=boost_headers_dir ^
-D BOOST_LIBRARYDIR=boost_libs_dir ^
-D Boost_NO_SYSTEM_PATHS=ON ^
-D Qt5Core_DIR=qt5_home_dir/lib/cmake/Qt5Core ^
-D Qt5Gui_DIR=qt5_home_dir/lib/cmake/Qt5Gui ^
-D Qt5Widgets_DIR=qt5_home_dir/lib/cmake/Qt5Widgets ^
-D GTEST_ROOT=gtest_home_dir ^
-D CMAKE_C_COMPILER=icl ^
-D CMAKE_CXX_COMPILER=icl ^
-T "Intel C++ Compiler 16.0" ^
-G "Visual Studio 14 2015 Win64" ^
asio_samples_home_dir

Remarks: use this fix when using Intel C++ Compiler 16.0 with Visual Studio 2015 Update 1.

Example of generation of Visual Studio 2015 project (static C/C++ runtime, static Boost and no Qt, x64) for usage with Intel Parallel Studio XE 2017:

cmake ^
-D CMAKE_USER_MAKE_RULES_OVERRIDE=asio_samples_home_dir/cmake/static_c_runtime_overrides.cmake ^
-D CMAKE_USER_MAKE_RULES_OVERRIDE_CXX=asio_samples_home_dir/cmake/static_cxx_runtime_overrides.cmake ^
-D BOOST_INCLUDEDIR=boost_headers_dir ^
-D BOOST_LIBRARYDIR=boost_libs_dir ^
-D Boost_NO_SYSTEM_PATHS=ON ^
-D Boost_USE_STATIC_LIBS=ON ^
-D ma_qt=OFF ^
-D CMAKE_C_COMPILER=icl ^
-D CMAKE_CXX_COMPILER=icl ^
-T "Intel C++ Compiler 17.0" ^
-G "Visual Studio 14 2015 Win64" ^
asio_samples_home_dir

Example of generation of Visual Studio 2010 project (shared C/C++ runtime, static Boost and shared Qt 4):

cmake ^
-D BOOST_INCLUDEDIR=boost_headers_dir ^
-D BOOST_LIBRARYDIR=boost_libs_dir ^
-D Boost_NO_SYSTEM_PATHS=ON ^
-D Boost_USE_STATIC_LIBS=ON ^
-D QT_QMAKE_EXECUTABLE=qt4_home_dir/bin/qmake.exe ^
-D GTEST_ROOT=gtest_home_dir ^
-G "Visual Studio 10 2010" ^
asio_samples_home_dir

Example of generation of Visual Studio 2008 project (static C/C++ runtime, static Boost and static Qt 4):

cmake ^
-D CMAKE_USER_MAKE_RULES_OVERRIDE=asio_samples_home_dir/cmake/static_c_runtime_overrides.cmake ^
-D CMAKE_USER_MAKE_RULES_OVERRIDE_CXX=asio_samples_home_dir/cmake/static_cxx_runtime_overrides.cmake ^
-D BOOST_INCLUDEDIR=boost_headers_dir ^
-D BOOST_LIBRARYDIR=boost_libs_dir ^
-D Boost_NO_SYSTEM_PATHS=ON ^
-D QT_QMAKE_EXECUTABLE=qt4_home_dir/bin/qmake.exe ^
-D GTEST_ROOT=gtest_home_dir ^
-G "Visual Studio 9 2008" ^
asio_samples_home_dir

Example of generation of NMake makefile project (shared C/C++ runtime, static Boost and shared Qt 5):

cmake ^
-D BOOST_INCLUDEDIR=boost_headers_dir ^
-D BOOST_LIBRARYDIR=boost_libs_dir ^
-D Boost_NO_SYSTEM_PATHS=ON ^
-D Boost_USE_STATIC_LIBS=ON ^
-D Qt5Core_DIR=qt5_home_dir/lib/cmake/Qt5Core ^
-D Qt5Gui_DIR=qt5_home_dir/lib/cmake/Qt5Gui ^
-D Qt5Widgets_DIR=qt5_home_dir/lib/cmake/Qt5Widgets ^
-D GTEST_ROOT=gtest_home_dir ^
-G "NMake Makefiles" ^
-D CMAKE_BUILD_TYPE=project_build_configuration ^
asio_samples_home_dir

Note that if Google Test was built with CMake and MS Visual Studio then you have to "install" it somehow - just copying results of build (add "d" postfix into the name of debug artifacts) into Google Test root directory (or into "lib" sub-directory) would be enough for FindGTest.

There is a copy of Google Test shipped as part of CMake project (refer to 3rdparty/gtest directory). It will be used in case FindGTest fails to find Google Test (so GTEST_ROOT is optional). Note that -D gtest_force_shared_crt=ON command line parameter is required in case shared C/C++ runtime is planned to be used with Google Test.

Building generated project

Building of generated project can be done using chosen (during generation of project) build system or using CMake.

CMake command to build generated project:

cmake --build asio_sample_build_dir --config project_build_configuration