Skip to content

Commit

Permalink
Add MSVC 2017 target
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed Jan 3, 2019
1 parent 85d8c1b commit f83d35f
Show file tree
Hide file tree
Showing 31 changed files with 725 additions and 430 deletions.
101 changes: 98 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,103 @@ PSS_STYLE :=2
LDFLAGS += -DLL
CFLAGS += -D_CRT_SECURE_NO_DEPRECATE

# Windows MSVC 2017 all architectures
else ifneq (,$(findstring windows_msvc2017,$(platform)))

NO_GCC := 1
CFLAGS += -DNOMINMAX
CXXFLAGS += -DNOMINMAX
WINDOWS_VERSION = 1

PlatformSuffix = $(subst windows_msvc2017_,,$(platform))
ifneq (,$(findstring desktop,$(PlatformSuffix)))
WinPartition = desktop
MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP -FS
LDFLAGS += -MANIFEST -LTCG:incremental -NXCOMPAT -DYNAMICBASE -DEBUG -OPT:REF -INCREMENTAL:NO -SUBSYSTEM:WINDOWS -MANIFESTUAC:"level='asInvoker' uiAccess='false'" -OPT:ICF -ERRORREPORT:PROMPT -NOLOGO -TLBID:1
LIBS += kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
else ifneq (,$(findstring uwp,$(PlatformSuffix)))
WinPartition = uwp
MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_APP -D_WINDLL -D_UNICODE -DUNICODE -D__WRL_NO_DEFAULT_LIB__ -EHsc -FS
LDFLAGS += -APPCONTAINER -NXCOMPAT -DYNAMICBASE -MANIFEST:NO -LTCG -OPT:REF -SUBSYSTEM:CONSOLE -MANIFESTUAC:NO -OPT:ICF -ERRORREPORT:PROMPT -NOLOGO -TLBID:1 -DEBUG:FULL -WINMD:NO
LIBS += WindowsApp.lib
endif

CFLAGS += $(MSVC2017CompileFlags)
CXXFLAGS += $(MSVC2017CompileFlags)

TargetArchMoniker = $(subst $(WinPartition)_,,$(PlatformSuffix))

CC = cl.exe
CXX = cl.exe
LD = link.exe

reg_query = $(call filter_out2,$(subst $2,,$(shell reg query "$2" -v "$1" 2>nul)))
fix_path = $(subst $(SPACE),\ ,$(subst \,/,$1))

ProgramFiles86w := $(shell cmd /c "echo %PROGRAMFILES(x86)%")
ProgramFiles86 := $(shell cygpath "$(ProgramFiles86w)")

WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir := $(WindowsSdkDir)

WindowsSDKVersion ?= $(firstword $(foreach folder,$(subst $(subst \,/,$(WindowsSdkDir)Include/),,$(wildcard $(call fix_path,$(WindowsSdkDir)Include\*))),$(if $(wildcard $(call fix_path,$(WindowsSdkDir)Include/$(folder)/um/Windows.h)),$(folder),)))$(BACKSLASH)
WindowsSDKVersion := $(WindowsSDKVersion)

VsInstallBuildTools = $(ProgramFiles86)/Microsoft Visual Studio/2017/BuildTools
VsInstallEnterprise = $(ProgramFiles86)/Microsoft Visual Studio/2017/Enterprise
VsInstallProfessional = $(ProgramFiles86)/Microsoft Visual Studio/2017/Professional
VsInstallCommunity = $(ProgramFiles86)/Microsoft Visual Studio/2017/Community

VsInstallRoot ?= $(shell if [ -d "$(VsInstallBuildTools)" ]; then echo "$(VsInstallBuildTools)"; fi)
ifeq ($(VsInstallRoot), )
VsInstallRoot = $(shell if [ -d "$(VsInstallEnterprise)" ]; then echo "$(VsInstallEnterprise)"; fi)
endif
ifeq ($(VsInstallRoot), )
VsInstallRoot = $(shell if [ -d "$(VsInstallProfessional)" ]; then echo "$(VsInstallProfessional)"; fi)
endif
ifeq ($(VsInstallRoot), )
VsInstallRoot = $(shell if [ -d "$(VsInstallCommunity)" ]; then echo "$(VsInstallCommunity)"; fi)
endif
VsInstallRoot := $(VsInstallRoot)

VcCompilerToolsVer := $(shell cat "$(VsInstallRoot)/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt" | grep -o '[0-9\.]*')
VcCompilerToolsDir := $(VsInstallRoot)/VC/Tools/MSVC/$(VcCompilerToolsVer)

WindowsSDKSharedIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\shared")
WindowsSDKUCRTIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\ucrt")
WindowsSDKUMIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\um")
WindowsSDKUCRTLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\ucrt\$(TargetArchMoniker)")
WindowsSDKUMLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\um\$(TargetArchMoniker)")

# For some reason the HostX86 compiler doesn't like compiling for x64
# ("no such file" opening a shared library), and vice-versa.
# Work around it for now by using the strictly x86 compiler for x86, and x64 for x64.
# NOTE: What about ARM?
ifneq (,$(findstring x64,$(TargetArchMoniker)))
VCCompilerToolsBinDir := $(VcCompilerToolsDir)\bin\HostX64
else
VCCompilerToolsBinDir := $(VcCompilerToolsDir)\bin\HostX86
endif

PATH := $(shell IFS=$$'\n'; cygpath "$(VCCompilerToolsBinDir)/$(TargetArchMoniker)"):$(PATH)
PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VsInstallRoot)/Common7/IDE")
INCLUDE := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/include")
LIB := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/lib/$(TargetArchMoniker)")
ifneq (,$(findstring uwp,$(PlatformSuffix)))
LIB := $(shell IFS=$$'\n'; cygpath -w "$(LIB)/store")
endif

export INCLUDE := $(INCLUDE);$(WindowsSDKSharedIncludeDir);$(WindowsSDKUCRTIncludeDir);$(WindowsSDKUMIncludeDir)
export LIB := $(LIB);$(WindowsSDKUCRTLibDir);$(WindowsSDKUMLibDir)
TARGET := $(TARGET_NAME)_libretro.dll
PSS_STYLE :=2
LDFLAGS += -DLL

USE_CODEC_FLAC=0

# Windows
else
EXT ?= dll
Expand All @@ -483,7 +580,7 @@ else
fpic :=
LD_FLAGS :=
SHARED := -shared -static-libgcc -static-libstdc++ -s
CFLAGS += -D__WIN32__ -D__WIN32_LIBRETRO__
CFLAGS += -D__WIN32__
WINSOCKS := -lws2_32
endif

Expand Down Expand Up @@ -664,15 +761,13 @@ else
all: $(TARGET)

$(TARGET): $(OBJECTS)
@echo "** BUILDING $(TARGET) FOR PLATFORM $(platform) **"
ifeq ($(platform), emscripten)
$(CXX) $(CFLAGS) $(OBJOUT)$@ $^
else ifeq ($(STATIC_LINKING), 1)
$(AR) rcs $@ $(OBJECTS)
else
$(LD) $(fpic) $(SHARED) $(LINKOUT)$@ $(OBJECTS) $(LDFLAGS) $(WINSOCKS)
endif
@echo "** BUILD SUCCESSFUL! GG NO RE **"

%.o: %.c
$(CC) $(INCFLAGS) $(CFLAGS) -c $(OBJOUT)$@ $<
Expand Down
13 changes: 7 additions & 6 deletions common/libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "libretro.h"
#include <retro_miscellaneous.h>
#include <retro_timers.h>
#include <file/file_path.h>

#if defined(_WIN32) && !defined(_XBOX)
Expand Down Expand Up @@ -173,7 +174,7 @@ gp_layout_t classic = {

gp_layout_t *gp_layoutp = NULL;

cvar_t framerate = { "framerate", "60", true };
cvar_t framerate = { "framerate", "120", true };
static bool initial_resolution_set = false;
static int invert_y_axis = 1;

Expand Down Expand Up @@ -448,7 +449,7 @@ void retro_get_system_info(struct retro_system_info *info)

void retro_get_system_av_info(struct retro_system_av_info *info)
{
info->timing.fps = framerate.value;
info->timing.fps = 120;
info->timing.sample_rate = SAMPLERATE;

info->geometry.base_width = width;
Expand Down Expand Up @@ -772,7 +773,7 @@ void retro_run(void)
if (!state_rumble)
retro_unset_rumble_strong();

Host_Frame(0.016667);
Host_Frame(0.008334);

if (shutdown_core)
return;
Expand Down Expand Up @@ -957,8 +958,8 @@ bool retro_load_game(const struct retro_game_info *info)
}

Cvar_RegisterVariable(&framerate);
Cvar_Set("framerate", "60");
Cvar_Set("sys_ticrate", "0.016667");
Cvar_Set("framerate", "120");
Cvar_Set("sys_ticrate", "0.008334");


/* Override some default binds with more modern ones if we are booting the
Expand Down Expand Up @@ -1224,7 +1225,7 @@ static void audio_process(void)
static void audio_callback(void)
{
unsigned read_first, read_second;
float samples_per_frame = (2 * SAMPLERATE) / framerate.value;
float samples_per_frame = (2 * SAMPLERATE) / 120;
unsigned read_end = audio_buffer_ptr + samples_per_frame;

if (read_end > AUDIO_BUFFER_SAMPLES)
Expand Down
2 changes: 1 addition & 1 deletion libretro-common/compat/compat_posix_string.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2010-2017 The RetroArch team
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (compat_posix_string.c).
Expand Down
37 changes: 31 additions & 6 deletions libretro-common/compat/compat_snprintf.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2010-2017 The RetroArch team
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (compat_snprintf.c).
Expand All @@ -23,26 +23,51 @@
/* THIS FILE HAS NOT BEEN VALIDATED ON PLATFORMS BESIDES MSVC */
#ifdef _MSC_VER

#include <retro_common.h>

#include <stdio.h>
#include <stdarg.h>

#if _MSC_VER < 1800
#define va_copy(dst, src) ((dst) = (src))
#endif

#if _MSC_VER < 1300
#define _vscprintf c89_vscprintf_retro__

static int c89_vscprintf_retro__(const char *format, va_list pargs)
{
int retval;
va_list argcopy;
va_copy(argcopy, pargs);
retval = vsnprintf(NULL, 0, format, argcopy);
va_end(argcopy);
return retval;
}
#endif

/* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 */

int c99_vsnprintf_retro__(char *outBuf, size_t size, const char *format, va_list ap)
{
int count = -1;

if (size != 0)
{
#if (_MSC_VER <= 1310)
count = _vsnprintf(outBuf, size, format, ap);
count = _vsnprintf(outBuf, size - 1, format, ap);
#else
count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
count = _vsnprintf_s(outBuf, size, size - 1, format, ap);
#endif
}

if (count == -1)
count = _vscprintf(format, ap);

if (count == size)
{
/* there was no room for a NULL, so truncate the last character */
outBuf[size - 1] = '\0';
}

return count;
}

Expand Down
2 changes: 1 addition & 1 deletion libretro-common/compat/compat_strcasestr.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2010-2017 The RetroArch team
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (compat_strcasestr.c).
Expand Down
14 changes: 9 additions & 5 deletions libretro-common/compat/compat_strl.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2010-2015 The RetroArch team
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (compat_strl.c).
Expand All @@ -20,12 +20,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <stdlib.h>
#include <ctype.h>

#include <compat/strl.h>
#include <compat/posix_string.h>

#include <retro_assert.h>

/* Implementation of strlcpy()/strlcat() based on OpenBSD. */

Expand Down Expand Up @@ -61,5 +59,11 @@ size_t strlcat(char *dest, const char *source, size_t size)

return len + strlcpy(dest, source, size);
}

#endif

char *strldup(const char *s, size_t n)
{
char *dst = (char*)malloc(sizeof(char) * (n + 1));
strlcpy(dst, s, n);
return dst;
}
2 changes: 1 addition & 1 deletion libretro-common/encodings/encoding_utf.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2010-2017 The RetroArch team
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (encoding_utf.c).
Expand Down
Loading

0 comments on commit f83d35f

Please sign in to comment.