diff --git a/CMakeLists.txt b/CMakeLists.txt index af519c3..23897ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,9 +17,14 @@ add_executable(csnake set_target_properties(csnake PROPERTIES C_STANDARD 11) set_target_properties(csnake PROPERTIES C_EXTENSIONS FALSE) + if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") target_link_libraries(csnake pthread) +elseif(${MINGW}) + set(CMAKE_C_FLAGS "-D_UCRT") + target_link_libraries(csnake ucrt) endif() + target_include_directories(csnake PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) set(SIZE 10 CACHE STRING "Size of game field") diff --git a/Makefile b/Makefile index 67ee4cf..7932892 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,11 @@ OBJDIR = obj SRC = main.c screen.c input.c player.c sleep.c platform/getch.c platform/game.c OBJ = $(addprefix $(OBJDIR)/,$(SRC:.c=.o)) -DEFLDFLAGS = $(shell if echo "" | cc -E -dM -xc - | grep __FreeBSD__ > /dev/null 2>&1; then echo "-lpthread"; fi) +# Link pthread on FreeBSD +DEFLDFLAGS += $(shell if echo "" | cc -E -dM -xc - | grep __FreeBSD__ > /dev/null 2>&1; then echo "-lpthread"; fi) +# Use ucrt on MinGW +DEFLDFLAGS += $(shell if echo "" | cc -E -dM -xc - | grep __MINGW32__ > /dev/null 2>&1; then echo "-lucrt"; fi) +DEFCFLAGS += $(shell if echo "" | cc -E -dM -xc - | grep __MINGW32__ > /dev/null 2>&1; then echo "-D_UCRT"; fi) all: $(OUT) @@ -15,7 +19,7 @@ $(OBJDIR)/platform: mkdir -p $(OBJDIR)/platform $(OBJDIR)/%.o: $(SRCDIR)/%.c - $(CC) -c -o -std=c11 $@ $< $(CFLAGS) $(INCLUDE) + $(CC) -c -std=c11 -o $@ $< $(CFLAGS) $(DEFCFLAGS) $(INCLUDE) $(OUT): $(OBJDIR)/platform $(OBJ) $(CC) -o $@ $(OBJ) $(LDFLAGS) $(DEFLDFLAGS)