Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows compile issues #5

Merged
merged 3 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
build/
build/
.vs/
CMakeSettings.json
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ project(ets2-job-logger)

set(CMAKE_CXX_STANDARD 11)

if(MSVC)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
endif()

add_subdirectory(scs-sdk)
add_subdirectory(plugin)
add_subdirectory(gui)
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,42 @@ code is `200`.
- `openssl`
- `jsoncpp`
- `wxWidgets`

### Windows

Install `conan`. Open `PowerShell` and add remotes for `conan`:

```
conan remote add public-conan https://api.bintray.com/conan/bincrafters/public-conan
conan remote add theirix https://api.bintray.com/conan/bincrafters/theirix
```

- Open project in Visual Studio via `File -> Open -> CMake...` by choosing the
`CMakeListst.xt`.
- Edit CMake options via `CMake -> Change CMake settings -> CMakelists.txt`
- Change `generator` value to `Visual Studio 15 2017 Win64`.
- Remove `-v` from `buildCommandArgs` or specify valid verbosity level.
- CMake will produce error, note down the path from the error:
> include could not find load file:
>
> C:/Users/Test/CMakeBuilds/d76aad98-e5ad-0738-bbe9-bc20c6d93f9c/build/x64-Debug/conanbuildinfo.cmake`
- Open PowerShell in the source directory and run:
- `conan install . -s build_type=Debug -if='<PATH_FROM_PREVIOUS_STEP>'`
- `msgpack-c` version `2.3.0` has issue which needs an manual fix:
- Go to `C:\Users\<YOUR_USERNAME>\.conan\data\msgpack\3.2.0\bincrafters\stable\package`.
This directory should have two directories.
- In both directories go to `lib\cmake\msgpack`
and open `msgpack-config.cmake` file in your favorite text editor.
- Remove following lines at the bottom:
```
if(NOT OFF)
add_library(msgpackc ALIAS msgpackc-static)
endif()
```
- After installation finished go back to Visual Studio click `Generate` in the
notification.
- After CMake generation finished you're ready to build.

When you're ready to build a release just replace `Debug` with `Release` in:
- CMakeSettings.json (`CMake -> Change CMake settings -> CMakelists.txt`)
- Replace all `Debug` parts of the `conan` install command.
10 changes: 10 additions & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[requires]
msgpack/3.2.0@bincrafters/stable
zlib/1.2.11@conan/stable
websocketpp/0.8.1@bincrafters/stable
libcurl/7.66.0@bincrafters/stable
jsoncpp/1.8.4@theirix/stable
wxwidgets/3.1.2@bincrafters/stable

[generators]
cmake
41 changes: 34 additions & 7 deletions gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,24 @@ set(SOURCES
)

find_package(wxWidgets 3.0 REQUIRED)
include(${wxWidgets_USE_FILE})
if (MSVC)
find_package(PNG REQUIRED)
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost REQUIRED COMPONENTS random)
endif()
find_package(ZLIB REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(CURL REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(OpenSSL REQUIRED)
pkg_check_modules(JSONCPP jsoncpp REQUIRED)
include(${wxWidgets_USE_FILE})
if (MSVC)
find_package(jsoncpp CONFIG REQUIRED)
set(JSONCPP_LIBRARIES jsoncpp_lib_static)
set(JSONCPP_INCLUDE_DIRS jsoncpp_lib_static)
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(JSONCPP jsoncpp REQUIRED)
endif()

if (NOT WIN32)
if (PLUGIN_PATH)
Expand All @@ -48,18 +61,28 @@ configure_file(Logger/PluginInstallerDefs.h.in PluginInstallerDefs.h)

add_executable(ets2-job-logger WIN32 ${SOURCES})

if (WIN32)
if (MINGW)
set(WIN32_LIBS -lws2_32)
elseif (WIN32)
find_library(WS2_32_LIB ws2_32.lib REQUIRED)
find_library(GDI32_LIB gdi32.lib REQUIRED)
find_library(ADVAPI32_LIB advapi32.lib REQUIRED)
find_library(CRYPT32_LIB crypt32.lib REQUIRED)
find_library(USER32_LIB user32.lib REQUIRED)
set(WIN32_LIBS ${WS2_32_LIB} ${GDI32_LIB} ${ADVAPI32_LIB} ${CRYPT32_LIB} ${USER32_LIB})
endif()

target_link_libraries(ets2-job-logger
PRIVATE
ets2joblogger::plugin
${wxWidgets_LIBRARIES}
${PNG_LIBRARIES}
${Boost_LIBRARIES}
${WIN32_LIBS}
${JSONCPP_LIBRARIES}
${ZLIB_LIBRARIES}
${OPENSSL_LIBRARIES}
${CURL_LIBRARIES}
${OPENSSL_CRYPTO_LIBRARY}
${JSONCPP_LIBRARIES}
)

target_include_directories(ets2-job-logger
Expand All @@ -68,8 +91,12 @@ target_include_directories(ets2-job-logger
"${CMAKE_CURRENT_BINARY_DIR}"
"${WEBSOCKETPP_INCLUDE_DIR}"
"${wxWidgets_INCLUDE_DIRS}"
"${JSONCPP_INCLUDE_DIRS}"
"${PNG_INCLUDE_DIRS}"
"${Boost_INCLUDE_DIRS}"
"${ZLIB_INCLUDE_DIRS}"
"${OPENSSL_INCLUDE_DIRS}"
"${CURL_INCLUDE_DIRS}"
"${JSONCPP_INCLUDE_DIRS}"
)

target_compile_options(ets2-job-logger
Expand Down
12 changes: 6 additions & 6 deletions gui/Logger/PluginInstaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ wxString get_game_bin_directory(const PluginInstaller::Platform &platform,
}

wxString get_sha256(const wxString &file) {
std::ifstream f(file, std::ios::in | std::ios::binary);
if (!f.good()) {
wxFile f(file, wxFile::OpenMode::read);
if (!f.IsOpened()){
return "";
}

Expand All @@ -131,13 +131,13 @@ wxString get_sha256(const wxString &file) {
SHA256_CTX ctx;
SHA256_Init(&ctx);

while (f.good()) {
f.read(buffer, 4096);
SHA256_Update(&ctx, buffer, f.gcount());
while (!f.Eof()) {
auto read = f.Read(buffer, 4096);
SHA256_Update(&ctx, buffer, read);
}

SHA256_Final(hash, &ctx);
f.close();
f.Close();

std::stringstream ss;
ss << std::hex << std::setfill('0');
Expand Down
19 changes: 13 additions & 6 deletions plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(plugin VERSION 0.1.0)

add_library(${PROJECT_NAME}
SHARED
OBJECT
include/jobplugin/PluginDefs.h

src/Logger.cpp
Expand All @@ -13,6 +13,8 @@ add_library(${PROJECT_NAME}
configure_file(include/jobplugin/Version.h.in "include/jobplugin/Version.h")

add_library(ets2joblogger::plugin ALIAS ${PROJECT_NAME})
add_library(plugin_shared SHARED $<TARGET_OBJECTS:${PROJECT_NAME}>)
add_library(plugin_static STATIC $<TARGET_OBJECTS:${PROJECT_NAME}>)

find_package(msgpack REQUIRED)
find_package(websocketpp REQUIRED)
Expand All @@ -34,7 +36,13 @@ if(MINGW)
)
endif()

set_target_properties(${PROJECT_NAME}
set_target_properties(plugin_shared
PROPERTIES
OUTPUT_NAME "ets2-job-logger"
PREFIX ""
)

set_target_properties(plugin_static
PROPERTIES
OUTPUT_NAME "ets2-job-logger"
PREFIX ""
Expand All @@ -47,12 +55,11 @@ target_link_libraries(${PROJECT_NAME}
)

target_include_directories(${PROJECT_NAME}
INTERFACE
"${CMAKE_CURRENT_LIST_DIR}/include"
PUBLIC
"${CMAKE_CURRENT_BINARY_DIR}/include"
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/include"
"${WEBSOCKETPP_INCLUDE_DIR}"
)

Expand Down
2 changes: 1 addition & 1 deletion plugin/include/jobplugin/PluginDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#ifndef ETS2_JOB_LOGGER_PLUGINDEFS_H
#define ETS2_JOB_LOGGER_PLUGINDEFS_H

#include "jobplugin/Version.h"
#include <jobplugin/Version.h>
#include <string>
#include <msgpack.hpp>
#ifndef PLUGIN_INTERNAL
Expand Down
13 changes: 8 additions & 5 deletions plugin/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
#include "Logger.h"
#include <functional>
#include <scs/scssdk_telemetry.h>
#include <scs/common/scssdk_telemetry_common_configs.h>
#include <scs/common/scssdk_telemetry_truck_common_channels.h>
#include <scs/common/scssdk_telemetry_trailer_common_channels.h>
#include <scs/amtrucks/scssdk_ats.h>
#include <scs/eurotrucks2/scssdk_eut2.h>

#ifndef _WIN32
#define __stdcall
#endif

typedef std::function<SCSAPI_VOID(const scs_value_t *const)> callback_channel_t;
typedef std::function<SCSAPI_VOID(const void *const event_info)> callback_event_t;

Expand All @@ -46,19 +49,19 @@ callback_event_t config_cb;

namespace cb {
namespace bind {
callback_channel_t channel(void (Logger::*func)(const scs_value_t *const), Logger *obj) {
callback_channel_t channel(void (__stdcall Logger::*func)(const scs_value_t *const), Logger *obj) {
return std::bind(func, obj, std::placeholders::_1);
}

callback_event_t event(void (Logger::*func)(const scs_telemetry_frame_start_t *const), Logger *obj) {
callback_event_t event(void (__stdcall Logger::*func)(const scs_telemetry_frame_start_t *const), Logger *obj) {
return std::bind((void (Logger::*)(const void *const))(func), obj, std::placeholders::_1);
}

callback_event_t event(void (Logger::*func)(const void *const), Logger *obj) {
callback_event_t event(void (__stdcall Logger::*func)(const void *const), Logger *obj) {
return std::bind((void (Logger::*)(const void *const))(func), obj, std::placeholders::_1);
}

callback_event_t event(void (Logger::*func)(const scs_telemetry_configuration_t *), Logger *obj) {
callback_event_t event(void (__stdcall Logger::*func)(const scs_telemetry_configuration_t *), Logger *obj) {
return std::bind((void (Logger::*)(const void *const))(func), obj, std::placeholders::_1);
}
}
Expand Down