CDCF Windows Integration - thoughtworks-hpc/cdcf GitHub Wiki
Integration Environment:
- Win10
- CLion
- conan 1.24.1
- CMake 3.18.0
- NMake (Visual Studio 2017/2019 Community)
- C++ Compiler (Visual Studio 2017/2019 Community)
Currently local compilation environment uses Visual Studio 2017, but in GitHub CI we use Visual Studio 2019. In near future, local environment should change to 2019 version.
Install CLion
Go to official website to download.
Install Conan:
Recommend to use pip to install Conan:
pip install conan
Install CMake:
Go to official website to download.
Install Visual Studio:
Visual Studio 2017 Community Download_Page .
Visual Studio 2019 Community Download_Page .
Toolchains Configuration
CLion -> preference -> Build, Execution, Deployment
note: here amd64 should be chose in order to support Conan x86_64 setting.
CMake Configuration
Create Debug and Release CMake profiles:
note: set TOOLCHAIN_FILE as conan_paths.cmake to integrate with Conan
ACTOR_SYS_ONLY = 1 means in windows we only compile and run ActorSystem without NodeKeeper
Conan Configuration
CLion Conan Plugin is required:
Go to Conan root directory(e.g. C:\Users\Alex\.conan\profiles) , create release profile:
[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.version=15
build_type=Release
[options]
[build_requires]
[env]
Create debug profile:
[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.version=15
build_type=Debug
[options]
[build_requires]
[env]
In Conan plugin, please make sure CMake profiles match the right Conan profiles, otherwise you may get a series of linking error.
#1 Ignore asio C++17 compile warning
add_definitions(-D _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS)
#2 Define Windows version
if(WIN32)
add_definitions(-D _WIN32_WINNT=0x600)
endif()
In Windows, CMakeLists should define the minimum system version required. In this case, 0x600 means Windows Vista.
#3 Add .exe suffix for grpc_cpp_plugin
if (WIN32)
set(GRPC_CPP_PLUGIN ${grpc_LIB_DIRS}/../bin/grpc_cpp_plugin.exe)
else()
set(GRPC_CPP_PLUGIN ${grpc_LIB_DIRS}/../bin/grpc_cpp_plugin)
endif()
Visual Studio has a series of strict rules for C++, some common warnings are listed below:
#1 Implicit Conversion
e.g. std::max( size_t, unsigned long )
size_t thread_num =
floor(std::thread::hardware_concurrency() * threads_proportion);
set("scheduler.max-threads", std::max(thread_num, 4ul));
Visual Studio will complain that implicit conversion may not be safe. :
size_t thread_num =
floor(std::thread::hardware_concurrency() * threads_proportion);
const size_t min_thread_num = 4;
set("scheduler.max-threads", std::max(thread_num, min_thread_num));
e.g. implicit convert const char* to char*
char argv[][64] = {"scheduler_test", "--threads_proportion=0.52"};
Recommend to write c++ style type conversion const_cast <char *>() as follows:
std::vector<char *> argv{const_cast<char *>("scheduler_test"),
const_cast<char *>("--threads_proportion=0.52")};
#2 Left Value and Right Value
e.g. std::accumulate(InputIt first, InputIt last, T init)
template<class InputIt, class T>
constexpr // since C++20
T accumulate(InputIt first, InputIt last, T init)
{
for (; first != last; ++first) {
init = std::move(init) + *first; // std::move since C++20
}
return init;
}
It returns the result of accumulating all the values in the range [first,last)
to init. When using accumulate() like this, Visual Studio will complain that 0 can not be a left value.
auto total = std::accumulate(counts.begin(), counts.end(), 0);
Possible Solution:
size_t init_sum = 0;
auto total = std::accumulate(counts.begin(), counts.end(), init_sum);
#3 (936) Character Encoding Warning
When a file contains illegal characters such as Chinese etc.