From 948a080c9d1918b7044d1975048d404c4274187f Mon Sep 17 00:00:00 2001 From: Chris Dailey Date: Sat, 17 Dec 2022 17:39:46 -0500 Subject: [PATCH 1/3] chore(msvc): fix potentially uninitialized warning Fixes the msvc warning as error due to `/sdl`. --- src/inputdaemon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inputdaemon.cpp b/src/inputdaemon.cpp index 5e08f9b37..50cfeacd8 100644 --- a/src/inputdaemon.cpp +++ b/src/inputdaemon.cpp @@ -1175,7 +1175,7 @@ void InputDaemon::secondInputPass(QQueue *sdlEventQueue) if (joy != nullptr) { SetJoystick *set = joy->getActiveSetJoystick(); - JoySensor *sensor; + JoySensor *sensor = nullptr; if (event.csensor.sensor == SDL_SENSOR_ACCEL) sensor = set->getSensor(ACCELEROMETER); else if (event.csensor.sensor == SDL_SENSOR_GYRO) From 2f8ef0660b671ca8c35c3b9efc452f1dd794b46f Mon Sep 17 00:00:00 2001 From: Chris Dailey Date: Sat, 17 Dec 2022 18:00:44 -0500 Subject: [PATCH 2/3] chore(msvc): replace vla with QVarLengthArray msvc doesn't conform to c99, so it misses out on variable length arrays. Qt has the answer. style: missed clang format on the includes --- src/eventhandlers/winsendinputeventhandler.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/eventhandlers/winsendinputeventhandler.cpp b/src/eventhandlers/winsendinputeventhandler.cpp index 872114dab..e6de6fddb 100644 --- a/src/eventhandlers/winsendinputeventhandler.cpp +++ b/src/eventhandlers/winsendinputeventhandler.cpp @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +#include #include #include @@ -165,9 +166,11 @@ void WinSendInputEventHandler::sendTextEntryEvent(QString maintext) tempList.append(temp.virtualkey); - if (tempList.size() > 0) + int inputCount = tempList.size(); + + if (inputCount > 0) { - INPUT tempBuffer[tempList.size()] = {0}; + QVarLengthArray tempBuffer(inputCount); unsigned int j = 0; for (auto iter = tempList.cbegin(); iter != tempList.cend(); ++iter, ++j) @@ -186,10 +189,10 @@ void WinSendInputEventHandler::sendTextEntryEvent(QString maintext) tempBuffer[j].ki.dwFlags = tempflags; } - SendInput(j, tempBuffer, sizeof(INPUT)); + SendInput(j, tempBuffer.data(), sizeof(INPUT)); j = 0; - memset(tempBuffer, 0, sizeof(tempBuffer)); + memset(tempBuffer.data(), 0, sizeof(INPUT) * inputCount); // INPUT tempBuffer2[tempList.size()] = {0}; for (auto iter = tempList.crbegin(); iter != tempList.crend(); ++iter, ++j) { @@ -207,7 +210,7 @@ void WinSendInputEventHandler::sendTextEntryEvent(QString maintext) tempBuffer[j].ki.dwFlags = tempflags | KEYEVENTF_KEYUP; } - SendInput(j, tempBuffer, sizeof(INPUT)); + SendInput(j, tempBuffer.data(), sizeof(INPUT)); } } } From 05ba13223ac394cebb36497bd67d3a196f7e95fa Mon Sep 17 00:00:00 2001 From: Chris Dailey Date: Sat, 17 Dec 2022 18:20:19 -0500 Subject: [PATCH 3/3] chore(msvc): Add CMakeLists.txt support for msvc. Also add notes to BUILDING.md about how to build under Visual Studio. --- BUILDING.md | 13 ++++++++++++- CMakeLists.txt | 26 +++++++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index 43e92f8a2..707100694 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -5,6 +5,7 @@ Most of these packages are already built and available on [Release Page](https:/ - [Building AntiMicroX](#building-antimicrox) - [Build Dependencies](#build-dependencies) - [Basic building](#basic-building) + - [MSVC building tips](#msvc-building-tips) - [Build Options for CMake](#build-options-for-cmake) - [Universal Options](#universal-options) - [Linux Options](#linux-options) @@ -57,7 +58,7 @@ sudo apt install g++ cmake extra-cmake-modules qttools5-dev qttools5-dev-tools l Windows dependencies In case of Windows you need QT, SDL2 libraries, cmake and compiler (mingw for example). -For setting up your environment you may use `msys2`. +For setting up your environment you may use `msys2`. Alternatively, you may use `MSVC`. @@ -89,6 +90,16 @@ Run built binaries ./bin/antimicrox ``` +#### MSVC building tips + +Recent versions of Visual Studio (2017+) have support for cmake projects. Under Visual Studio 2022, building AntiMicroX is quite straight forward. +- Ensure you have compatable versions of [Qt](https://www.qt.io/download) (5.9 works as of writing,) and [SDL2-devel](https://github.com/libsdl-org/SDL/releases/) installed. +- Open antimicrox as a local folder in VS22. It should pick up the `CMakeLists.txt` and offer an option to open the CMake settings editor. If it doesn't, right click on `CMakeLists.txt` in the solution explorer and select `CMake settings for antimicrox`. +- In the `Command arguments` section, add an argument to tell CMake where to find your Qt; E.g.: `"-DCMAKE_PREFIX_PATH=C:\Qt\5.9\msvc2017_64\lib\cmake"`. As of writing, Qt's msvc2017 works properly through vs22. +- Under the `Cmake variables and cache` section, click the link labeled `Save and generate cmake cache to load variables. +- If the CMake generation fails due to SDL2, find the variables named `SDL2_PATH`, `SDL2_INCLUDE_DIR`, and `SDL2_DLL_LOCATION_DIR` in the list view, and set them properly. You may also need to move the headers in the SDL2 include dir inside a folder named `SDL2` to match their include paths on other systems. +- At this point you should be able to save your changes to regenerate the cmake cache, which will then allow you to build `antimicrox.exe` through Visual Studio. + A recommended way of installation is building package typical for for your system (or building universal one like an AppImage).
diff --git a/CMakeLists.txt b/CMakeLists.txt index b431a14ba..60cdfb879 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,11 +38,22 @@ endif(UNIX AND NOT APPLE AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) include(CheckCXXCompilerFlag) include(GNUInstallDirs) -CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) +if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND MSVC_TOOLSET_VERSION GREATER_EQUAL 140) + # MSVC tools v140 and later support c++11 ootb and has no flag to enable it. + set(COMPILER_SUPPORTS_CXX11 1) + set(COMPILER_IS_MSVC 1) +else() + CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) +endif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND MSVC_TOOLSET_VERSION GREATER_EQUAL 140) + +if(NOT COMPILER_SUPPORTS_CXX11) + message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") +endif(NOT COMPILER_SUPPORTS_CXX11) -if(COMPILER_SUPPORTS_CXX11) - message("Build type: ${CMAKE_BUILD_TYPE}") +message("Build type: ${CMAKE_BUILD_TYPE}") + +if(NOT COMPILER_IS_MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -g -O0 -fno-omit-frame-pointer") if(UNIX AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") @@ -50,8 +61,13 @@ if(COMPILER_SUPPORTS_CXX11) endif(UNIX AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wstrict-null-sentinel -Wstrict-overflow=5 -Wundef -Wno-unused -std=c++11") else() - message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") -endif(COMPILER_SUPPORTS_CXX11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /analyze- /D_CRT_SECURE_NO_WARNINGS") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W3 /GS /Od /sdl /RTC1 /Gd /Oy-") + if(MSVC_TOOLSET_VERSION GREATER_EQUAL 141) + # VS2017 (toolset v141) and later can set /permissive- to disable non-standard conforming behavior + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /permissive-") + endif(MSVC_TOOLSET_VERSION GREATER_EQUAL 141) +endif(NOT COMPILER_IS_MSVC) # The version number. set(ANTIMICROX_MAJOR_VERSION 3)