From d196ace8904b99a37fddc0738e8e662a56c95d55 Mon Sep 17 00:00:00 2001 From: kimsama Date: Sun, 9 Jun 2019 16:32:23 +0900 Subject: [PATCH] Add a document page to build on Windows. - modified CMakeLists.txt to resolve build errors. - excluded benchmark stuff to resolve platform issue. (I don't believe 'benchmarks' can be built on Windows because it's code uses POXIS socket library) --- CMakeLists.txt | 12 +-- WINDOWS_BUILD.md | 128 ++++++++++++++++++++++++++++++ rsocket/benchmarks/CMakeLists.txt | 2 + 3 files changed, 137 insertions(+), 5 deletions(-) create mode 100644 WINDOWS_BUILD.md diff --git a/CMakeLists.txt b/CMakeLists.txt index 31b1fd75d..17e0b239c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,11 +174,13 @@ if (NOT MSVC) set(EXTRA_CXX_FLAGS ${EXTRA_CXX_FLAGS} -Werror) endif() -if("${BUILD_TYPE_LOWER}" MATCHES "debug") - message("debug mode was set") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unreachable-code") -else() - message("release mode was set") +if (NOT MSVC) + if("${BUILD_TYPE_LOWER}" MATCHES "debug") + message("debug mode was set") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unreachable-code") + else() + message("release mode was set") + endif() endif() if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") diff --git a/WINDOWS_BUILD.md b/WINDOWS_BUILD.md new file mode 100644 index 000000000..eeb23347e --- /dev/null +++ b/WINDOWS_BUILD.md @@ -0,0 +1,128 @@ + +## Install on Windows + +This document page describes a way to build rsocket-cpp with 'Visual Studio tools for CMake' in Visual Studio 2017 on Windows. + +### Pre-Acquisition + +#### Install Vcpkg + +During the build process of rsocket-cpp, it requires [folly](https://github.com/facebook/folly) and it is available in [vcpkg](https://github.com/Microsoft/vcpkg#vcpkg). + +#### Install CMake Tools + +1. Run Visual Studio 2017. + * *it is recommended to use higher version than 15.4.5. due to the issue that 15.4 couldn't open CMake correctly.* +2. Select *Tools > Get Tools and Features...* menu. +3. Go to **Indivisual components** tab +4. See *'Compilers, build tools, and runtimes* and check **Visual C++ tools for CMake.** +5. See *'Development activities'* and check the followings: + * **Visual C++ for Linux Development.** *(Not sure though it is really necessary)* + * **Visual C++ tools for CMake and Linux.** *(Not sure though it is really necessary)* +6. Press 'Modify' button! + +### Open CMake Project + +1. Run Visual Studio 2017 +2. Select *Open > File > CMake* menu then select *'CMakeList.txt'* file under the rsocket-cpp repository directory. +3. Select *CMake > Change_CMake_Settings > CMakeList.txt* menu, and it will generate **CMakeSettings.json** file. + + +#### CMakeSettings + +The created CMakeSettings.json file will be opened automatically but it will be not, you have to do manually. + +The first thing you need to do is changing the directory path of **buildRoot** and **installRoot** to have its directory under the repository directory. + +Change +```"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",``` +as +```"buildRoot": "${projectDir}\\build\\${name}",``` + +Next, change +``` "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", ``` +as +```"installRoot": "${projectDir}\\install\\${name}",``` + +Now, all the files such as .obj, .lib, and .exe will be put under the changed directory in your repository directorys. + +You might also need to change **cmakeCommandArgs** argument to be set "-DBUILD_TESTS=OFF" which disables google test. (due to the issue #869) + +#### Install folly + +Install [folly](https://github.com/facebook/folly) thorough [vcpkg](https://github.com/Microsoft/vcpkg#vcpkg). + +Open command-line(cmd) window and move to where vcpkg.exe is and run the following: + +``` +.\vcpkg.exe install folly:x64-windows --head +``` + +After the installation, it has to be integrated to use the package in Visual Studio 2017. Run the following: +``` +.\vcpkg.exe integrate install +``` + +To make the project can refer ***folly***, the external package, it needs to change CMakeSettings.json file. Add **variables** element and get it to have 'name' and 'value' like the following. + +```json +{ + "configurations": [ + { + "name": "x64-Debug", + "generator": "Ninja", + "configurationType": "Debug", + "inheritEnvironments": [ + "msvc_x64_x64" + ], + "buildRoot": "${project`Dir}\\build\\${name}", + "installRoot": "${projectDir}\\install\\${name}", + "cmakeCommandArgs": "-DBUILD_TESTS=OFF", + "buildCommandArgs": "-v", + "ctestCommandArgs": "", + "variables": [ + { + "name": "CMAKE_TOOLCHAIN_FILE", + "value": "C:\\dev\\gRPC\\install\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake" + } + } + ] +} +``` +Save the modification and you can see CMakeCache is refreshed then it refers 'folly' package correctly. + +Now you should see *Build* and other menu items under *CMake* menu but there are still a few things to be tweaked. + + +Open 'rsocket_repository/CMakeList.txt' file and go to line 177 and add ```if (NOT MSVC)``` so the change looks like the following: +```json +if (NOT MSVC) + if("${BUILD_TYPE_LOWER}" MATCHES "debug") + message("debug mode was set") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unreachable-code") + else() + message("release mode was set") + endif() +endif() +``` +Without the above modification, it might meet the following error messasge when it built: +>`Error D8021 invalid numeric argument '/Wno-unreachable-code' + + +Open 'rsocket_repository/rsocket/benchmarks/CMakeList.txt' file. And add ```If (NOT MSVC)``` at the first line not to build entire benchmark related files. Don't forget to add ```endif()``` at the end of the line either. Now, it should look like the following: +```json +if (NOT MSVC`) + add_library(fixture Fixture.cpp Fixture.h) + target_link_libraries(fixture ReactiveSocket Folly::folly) + ... +endif() +``` +Without the above modification, it might meet the following error messasge when it built: +>Error C1083 Cannot open include file: 'arpa/inet.h': No such file or directory + + +### Build and Install + +Now, you can go build and install all the libraries and examples. + +*Note: All the above are tested on Visual Studio 2017 v15.9.11 in Windows10* diff --git a/rsocket/benchmarks/CMakeLists.txt b/rsocket/benchmarks/CMakeLists.txt index 4d0c4f51c..c34ff722a 100644 --- a/rsocket/benchmarks/CMakeLists.txt +++ b/rsocket/benchmarks/CMakeLists.txt @@ -1,3 +1,4 @@ +if (NOT MSVC) add_library(fixture Fixture.cpp Fixture.h) target_link_libraries(fixture ReactiveSocket Folly::folly) @@ -27,3 +28,4 @@ add_test(NAME FireForgetThroughputTcpTest COMMAND fire-forget-throughput-tcp --i #TODO(lehecka):enable test #add_test(NAME StreamThroughputMemoryTest COMMAND stream-throughput-mem --items 100000) +endif() \ No newline at end of file