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)