Skip to content

Commit

Permalink
Fix building with MSVC (#74)
Browse files Browse the repository at this point in the history
* (hopefully) fix compilation on MSVC

based on erysdren@fd118e1

* stuff i missed

* inexplicable cppcheck failure

* CMakeLists: add some comments explaining MSVC stuff

* rt_sound.c: remove unnecessary include

* Presumably this isn't needed, if this branch works
  • Loading branch information
erysdren authored Jul 12, 2024
1 parent 2ab3463 commit 94abaa1
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 101 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ target_link_libraries(${TARADINO_EXEC} PRIVATE SDL2::Main SDL2::Mixer)
target_compile_definitions(${TARADINO_EXEC} PRIVATE PACKAGE_STRING="${TARADINO_TITLE} ${CMAKE_PROJECT_VERSION}")
target_compile_definitions(${TARADINO_EXEC} PRIVATE PACKAGE_TARNAME="${CMAKE_PROJECT_NAME}")

if(MSVC)
set_property(TARGET ${TARADINO_EXEC} PROPERTY C_STANDARD 17)
# silence warnings about POSIX functions
target_compile_options(${TARADINO_EXEC} PUBLIC -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -Dstrcasecmp=_stricmp -Dalloca=_alloca)
# silence unsigned/signed and integer truncation warnings
target_compile_options(${TARADINO_EXEC} PRIVATE /wd4267 /wd4244)
endif()

if(${TARADINO_SHAREWARE})
target_compile_definitions(${TARADINO_EXEC} PRIVATE SHAREWARE=1)
endif()
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ library named SDL_mixer.

- Demos go out of sync.
- No netplay support.
- Won't build with MSVC.

## Building

Expand Down
4 changes: 3 additions & 1 deletion rott/dosutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
int _argc;
char **_argv;

#ifndef _MSC_VER
long filelength(int handle)
{
struct stat buf;
Expand All @@ -47,6 +48,7 @@ char *strlwr(char *s)

return s;
}
#endif

char *strupr(char *s)
{
Expand Down Expand Up @@ -161,7 +163,7 @@ void DisplayTextSplash(byte *text, int l)
printf ("\033[m");
}

#if !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__HAIKU__)
#if !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__HAIKU__) && !defined(_MSC_VER)
#include <execinfo.h>

void print_stack (int level)
Expand Down
4 changes: 4 additions & 0 deletions rott/m_misc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include <errno.h>
#include <sys/stat.h>

#ifdef _MSC_VER
#include <direct.h>
#endif

#include "m_misc2.h"

// Create a directory
Expand Down
4 changes: 2 additions & 2 deletions rott/modexlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ void EnableScreenStretch(void)
iGLOBAL_SCREENWIDTH, iGLOBAL_SCREENHEIGHT, 8, 0, 0, 0, 0);
}

displayofs = unstretch_sdl_surface->pixels +
displayofs = (byte *)unstretch_sdl_surface->pixels +
(displayofs - (byte *)sdl_surface->pixels);
bufferofs = unstretch_sdl_surface->pixels;
page1start = unstretch_sdl_surface->pixels;
Expand All @@ -426,7 +426,7 @@ void DisableScreenStretch(void)
{
if (iGLOBAL_SCREENWIDTH <= 320 || !StretchScreen) return;

displayofs = sdl_surface->pixels +
displayofs = (byte *)sdl_surface->pixels +
(displayofs - (byte *)unstretch_sdl_surface->pixels);
bufferofs = sdl_surface->pixels;
page1start = sdl_surface->pixels;
Expand Down
17 changes: 16 additions & 1 deletion rott/rt_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "develop.h"
#include "rt_fixed.h"

#include <unistd.h>
#include <sys/types.h>
#include <limits.h>

#ifndef _MSC_VER
#include <unistd.h>
#include <dirent.h>
#else
#include <io.h>
#define R_OK 4
#define W_OK 2
#define F_OK 0
#endif

#include <ctype.h>

#include <stdint.h>
Expand All @@ -48,6 +57,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define CURDIR "./"
#endif

#ifdef _MSC_VER
#define __attribute__(...)
#endif

#if defined(__GNUC__) || defined(__clang__)
#define PRINTF_ATTR(fmt, first) __attribute__((format(printf, fmt, first)))
#define PRINTF_ARG_ATTR(x) __attribute__((format_arg(x)))
Expand Down Expand Up @@ -123,12 +136,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#define arrlen(array) (sizeof(array) / sizeof(*array))

#ifndef _MSC_VER
char *strupr(char *);
char *itoa(int, char *, int);
char *ltoa(long, char *, int);
char *ultoa(unsigned long, char *, int);
char getch(void);
long filelength(int handle);
#endif

#define STUB_FUNCTION fprintf(stderr,"STUB: %s at " __FILE__ ", line %d, thread %d\n",__FUNCTION__,__LINE__,getpid())

Expand Down
2 changes: 1 addition & 1 deletion rott/rt_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -4450,7 +4450,7 @@ player->yzangle=0;
IN_UserInput (VBLCOUNTER*60);

MainMenu[savegame].active = 0;
MainMenu[viewscores].routine = (menuptr)CP_ViewScores;
MainMenu[viewscores].routine = (menuptr){.vv = CP_ViewScores};
MainMenu[viewscores].texture[6] = '7';
MainMenu[viewscores].texture[7] = '\0';
MainMenu[viewscores].letter = 'V';
Expand Down
5 changes: 5 additions & 0 deletions rott/rt_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "music.h"
#include "fx_man.h"

#ifdef _MSC_VER
#include <conio.h>
#include <direct.h>
#endif

#include "vgatext.h"

volatile int oldtime;
Expand Down
Loading

0 comments on commit 94abaa1

Please sign in to comment.