Probably fix #3

fix-mingw
Nakidai 2024-02-23 17:11:50 +03:00 committed by Nakidai
parent 71229a9205
commit 1c7a0ef6b2
Signed by: nakidai
GPG Key ID: 18AD605FDA13FE5A
2 changed files with 11 additions and 2 deletions

View File

@ -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")

View File

@ -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)