(Windows) Added support for the MSVC compiler.

This commit is contained in:
Leon Styhre 2020-12-28 23:23:01 +01:00
parent 963f93e0f8
commit 9ec3f19482
8 changed files with 86 additions and 32 deletions

5
.gitignore vendored
View file

@ -18,6 +18,11 @@
# Dependency makefiles
*.d
# MSVC-specific
*.lib
EmulationStation.ilk
EmulationStation.pdb
# Compiled executable
emulationstation
EmulationStation

View file

@ -111,14 +111,23 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "-mwindows ${CMAKE_CXX_FLAGS}")
# set(CMAKE_CXX_FLAGS "-static-libstdc++ -static-libgcc ${CMAKE_CXX_FLAGS}")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
message("-- Compiler is MSVC")
# If using the MSVC compiler on Windows, disable the built-in min() and max() macros.
add_definitions(-DNOMINMAX)
endif()
message("-- Build type is ${CMAKE_BUILD_TYPE}")
# Set up compiler and linker flags for debug, profiling or release builds.
if(CMAKE_BUILD_TYPE MATCHES Debug)
# Enable the C++11 standard and disable optimizations as it's a debug build.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O0")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O0")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c11 /Od /DEBUG:FULL")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O0")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O0")
endif()
# If using Clang, then add additional debug data needed by GDB.
# Comment this out if you're using LLDB for debugging as this flag makes the binary
# much larger and the application much slower. On macoOS this setting is never enabled
@ -128,21 +137,29 @@ if(CMAKE_BUILD_TYPE MATCHES Debug)
endif()
elseif(CMAKE_BUILD_TYPE MATCHES Profiling)
# For the profiling build, we enable optimizations and supply the required profiler flags.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -pg -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2 -pg")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c11 /O2 /DEBUG:FULL")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -pg -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2 -pg")
endif()
else()
# Enable the C++11 standard and enable optimizations as it's a release build.
# This will also disable all assert() macros. Strip the binary as well.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -DNDEBUG")
if(APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2")
# This will also disable all assert() macros. Strip the binary too.
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG /std:c11 /O2 /DEBUG:NONE")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2 -s")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -DNDEBUG")
if(APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2 -s")
endif()
endif()
endif()
# This removes half of the ranlib warnings on macOS regarding no symbols for files that
# are #ifdef'ed away. There must be a way to remove the other half as well?
# The following removes half of the ranlib warnings on macOS regarding no symbols for files
# that are #ifdef'ed away. There must be a way to remove the other half as well?
if(APPLE)
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
@ -238,18 +255,32 @@ if(NOT WIN32)
${VLC_LIBRARIES}
nanosvg)
elseif(WIN32)
set(COMMON_LIBRARIES
"${PROJECT_SOURCE_DIR}/FreeImage.dll"
"${PROJECT_SOURCE_DIR}/glew32.dll"
"${PROJECT_SOURCE_DIR}/libcurl-x64.dll"
"${PROJECT_SOURCE_DIR}/libfreetype.dll"
"${PROJECT_SOURCE_DIR}/libpugixml.dll"
"${PROJECT_SOURCE_DIR}/libSDL2main.a"
"${PROJECT_SOURCE_DIR}/libvlc.dll"
"${PROJECT_SOURCE_DIR}/SDL2.dll"
"mingw32"
"nanosvg"
"Winmm.dll")
if(DEFINED MSVC)
set(COMMON_LIBRARIES
"${PROJECT_SOURCE_DIR}/FreeImage.lib"
"${PROJECT_SOURCE_DIR}/glew32.lib"
"${PROJECT_SOURCE_DIR}/libcurl-x64.lib"
"${PROJECT_SOURCE_DIR}/freetyped.lib"
"${PROJECT_SOURCE_DIR}/pugixml.lib"
"${PROJECT_SOURCE_DIR}/SDL2main.lib"
"${PROJECT_SOURCE_DIR}/libvlc.lib"
"${PROJECT_SOURCE_DIR}/SDL2.lib"
"nanosvg"
"Winmm.dll")
else()
set(COMMON_LIBRARIES
"${PROJECT_SOURCE_DIR}/FreeImage.dll"
"${PROJECT_SOURCE_DIR}/glew32.dll"
"${PROJECT_SOURCE_DIR}/libcurl-x64.dll"
"${PROJECT_SOURCE_DIR}/libfreetype.dll"
"${PROJECT_SOURCE_DIR}/libpugixml.dll"
"${PROJECT_SOURCE_DIR}/libSDL2main.a"
"${PROJECT_SOURCE_DIR}/libvlc.dll"
"${PROJECT_SOURCE_DIR}/SDL2.dll"
"mingw32"
"nanosvg"
"Winmm.dll")
endif()
endif()
if(APPLE)

View file

@ -115,10 +115,16 @@ endif()
# Setup for installation and package generation.
if(WIN32)
install(TARGETS EmulationStation RUNTIME DESTINATION .)
install(FILES ../FreeImage.dll ../glew32.dll ../libcrypto-1_1-x64.dll ../libcurl-x64.dll
../libfreetype.dll ../libgcc_s_seh-1.dll ../libpugixml.dll ../libssl-1_1-x64.dll
../libstdc++-6.dll ../libvlc.dll ../libvlccore.dll ../libwinpthread-1.dll
../SDL2.dll ../vcomp140.dll DESTINATION .)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
install(FILES ../FreeImage.dll ../glew32.dll ../libcrypto-1_1-x64.dll ../libcurl-x64.dll
../freetyped.dll ../pugixml.dll ../libssl-1_1-x64.dll ../libvlc.dll
../libvlccore.dll ../SDL2.dll DESTINATION .)
else()
install(FILES ../FreeImage.dll ../glew32.dll ../libcrypto-1_1-x64.dll ../libcurl-x64.dll
../libfreetype.dll ../libgcc_s_seh-1.dll ../libpugixml.dll ../libssl-1_1-x64.dll
../libstdc++-6.dll ../libvlc.dll ../libvlccore.dll ../libwinpthread-1.dll
../SDL2.dll ../vcomp140.dll DESTINATION .)
endif()
install(DIRECTORY ${CMAKE_SOURCE_DIR}/plugins DESTINATION .)
install(FILES ../LICENSE DESTINATION .)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/licenses DESTINATION .)

View file

@ -15,6 +15,10 @@
#include "Settings.h"
#endif
#if defined(_WIN64)
#include <cmath>
#endif
// The ALSA Audio Card and Audio Device selection code is disabled at the moment.
// As PulseAudio controls the sound devices for the desktop environment, it doesn't
// make much sense to be able to select ALSA devices directly. Normally (always?)
@ -318,7 +322,7 @@ int VolumeControl::getVolume() const
mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
if (mixerGetControlDetails(reinterpret_cast<HMIXEROBJ>(mixerHandle), &mixerControlDetails,
MIXER_GETCONTROLDETAILSF_VALUE) == MMSYSERR_NOERROR)
volume = static_cast<int>(Math::round((value.dwValue * 100) / 65535.0f));
volume = static_cast<int>(std::round((value.dwValue * 100) / 65535.0f));
else
LOG(LogError) << "VolumeControl::getVolume() - Failed to get mixer volume!";
}
@ -326,7 +330,7 @@ int VolumeControl::getVolume() const
// Windows Vista or above. use EndpointVolume API.
float floatVolume = 0.0f; // 0-1
if (endpointVolume->GetMasterVolumeLevelScalar(&floatVolume) == S_OK) {
volume = static_cast<int>(Math::round(floatVolume * 100.0f));
volume = static_cast<int>(std::round(floatVolume * 100.0f));
LOG(LogInfo) << "System audio volume is " << volume;
}
else {

View file

@ -21,7 +21,9 @@
#include <array>
#endif
#if !defined(_WIN64)
#include <unistd.h>
#endif
#include <fcntl.h>
int runRebootCommand()

View file

@ -15,6 +15,8 @@
#include "components/TextComponent.h"
#include "utils/StringUtil.h"
#include <cmath>
class ButtonComponent;
class ImageComponent;

View file

@ -12,6 +12,7 @@
#include <list>
#include <memory>
#include <string>
// The ResourceManager exists to:
// Allow loading resources embedded into the executable like an actual file.

View file

@ -26,8 +26,11 @@
#if defined(_WIN64)
#include <direct.h>
#include <Windows.h>
//#define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
//#define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
#if defined(_MSC_VER) // MSVC compiler.
#define stat64 _stat64
#define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
#define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
#endif
#else
#include <dirent.h>
#include <unistd.h>