(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 # Dependency makefiles
*.d *.d
# MSVC-specific
*.lib
EmulationStation.ilk
EmulationStation.pdb
# Compiled executable # Compiled executable
emulationstation emulationstation
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 "-mwindows ${CMAKE_CXX_FLAGS}")
# set(CMAKE_CXX_FLAGS "-static-libstdc++ -static-libgcc ${CMAKE_CXX_FLAGS}") # set(CMAKE_CXX_FLAGS "-static-libstdc++ -static-libgcc ${CMAKE_CXX_FLAGS}")
endif() 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() endif()
message("-- Build type is ${CMAKE_BUILD_TYPE}")
# Set up compiler and linker flags for debug, profiling or release builds. # Set up compiler and linker flags for debug, profiling or release builds.
if(CMAKE_BUILD_TYPE MATCHES Debug) if(CMAKE_BUILD_TYPE MATCHES Debug)
# Enable the C++11 standard and disable optimizations as it's a debug build. # Enable the C++11 standard and disable optimizations as it's a debug build.
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_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O0")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O0") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O0")
endif()
# If using Clang, then add additional debug data needed by GDB. # 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 # 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 # 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() endif()
elseif(CMAKE_BUILD_TYPE MATCHES Profiling) elseif(CMAKE_BUILD_TYPE MATCHES Profiling)
# For the profiling build, we enable optimizations and supply the required profiler flags. # For the profiling build, we enable optimizations and supply the required profiler flags.
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_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -pg -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2 -pg") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2 -pg")
endif()
else() else()
# Enable the C++11 standard and enable optimizations as it's a release build. # 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. # 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_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -DNDEBUG") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -DNDEBUG")
if(APPLE) if(APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2")
else() else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2 -s") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2 -s")
endif() endif()
endif()
endif() endif()
# This removes half of the ranlib warnings on macOS regarding no symbols for files that # The following removes half of the ranlib warnings on macOS regarding no symbols for files
# are #ifdef'ed away. There must be a way to remove the other half as well? # that are #ifdef'ed away. There must be a way to remove the other half as well?
if(APPLE) if(APPLE)
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>") 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>") SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
@ -238,6 +255,19 @@ if(NOT WIN32)
${VLC_LIBRARIES} ${VLC_LIBRARIES}
nanosvg) nanosvg)
elseif(WIN32) elseif(WIN32)
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 set(COMMON_LIBRARIES
"${PROJECT_SOURCE_DIR}/FreeImage.dll" "${PROJECT_SOURCE_DIR}/FreeImage.dll"
"${PROJECT_SOURCE_DIR}/glew32.dll" "${PROJECT_SOURCE_DIR}/glew32.dll"
@ -250,6 +280,7 @@ elseif(WIN32)
"mingw32" "mingw32"
"nanosvg" "nanosvg"
"Winmm.dll") "Winmm.dll")
endif()
endif() endif()
if(APPLE) if(APPLE)

View file

@ -115,10 +115,16 @@ endif()
# Setup for installation and package generation. # Setup for installation and package generation.
if(WIN32) if(WIN32)
install(TARGETS EmulationStation RUNTIME DESTINATION .) install(TARGETS EmulationStation RUNTIME 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 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 ../libfreetype.dll ../libgcc_s_seh-1.dll ../libpugixml.dll ../libssl-1_1-x64.dll
../libstdc++-6.dll ../libvlc.dll ../libvlccore.dll ../libwinpthread-1.dll ../libstdc++-6.dll ../libvlc.dll ../libvlccore.dll ../libwinpthread-1.dll
../SDL2.dll ../vcomp140.dll DESTINATION .) ../SDL2.dll ../vcomp140.dll DESTINATION .)
endif()
install(DIRECTORY ${CMAKE_SOURCE_DIR}/plugins DESTINATION .) install(DIRECTORY ${CMAKE_SOURCE_DIR}/plugins DESTINATION .)
install(FILES ../LICENSE DESTINATION .) install(FILES ../LICENSE DESTINATION .)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/licenses DESTINATION .) install(DIRECTORY ${CMAKE_SOURCE_DIR}/licenses DESTINATION .)

View file

@ -15,6 +15,10 @@
#include "Settings.h" #include "Settings.h"
#endif #endif
#if defined(_WIN64)
#include <cmath>
#endif
// The ALSA Audio Card and Audio Device selection code is disabled at the moment. // 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 // 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?) // 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); mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
if (mixerGetControlDetails(reinterpret_cast<HMIXEROBJ>(mixerHandle), &mixerControlDetails, if (mixerGetControlDetails(reinterpret_cast<HMIXEROBJ>(mixerHandle), &mixerControlDetails,
MIXER_GETCONTROLDETAILSF_VALUE) == MMSYSERR_NOERROR) 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 else
LOG(LogError) << "VolumeControl::getVolume() - Failed to get mixer volume!"; LOG(LogError) << "VolumeControl::getVolume() - Failed to get mixer volume!";
} }
@ -326,7 +330,7 @@ int VolumeControl::getVolume() const
// Windows Vista or above. use EndpointVolume API. // Windows Vista or above. use EndpointVolume API.
float floatVolume = 0.0f; // 0-1 float floatVolume = 0.0f; // 0-1
if (endpointVolume->GetMasterVolumeLevelScalar(&floatVolume) == S_OK) { 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; LOG(LogInfo) << "System audio volume is " << volume;
} }
else { else {

View file

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

View file

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

View file

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

View file

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