Automatically link pthread on FreeBSD

fix-mingw
Nakidai 2023-11-25 20:55:57 +03:00
parent cf8fe181a2
commit be37715af7
2 changed files with 7 additions and 2 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
project(csnake VERSION 1.0 LANGUAGES C) project(csnake VERSION 1.1 LANGUAGES C)
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed.") message(FATAL_ERROR "In-source builds are not allowed.")
@ -16,6 +16,9 @@ add_executable(csnake
set_target_properties(csnake PROPERTIES C_STANDARD 11) set_target_properties(csnake PROPERTIES C_STANDARD 11)
set_target_properties(csnake PROPERTIES C_EXTENSIONS FALSE) set_target_properties(csnake PROPERTIES C_EXTENSIONS FALSE)
if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
target_link_libraries(csnake pthread)
endif()
target_include_directories(csnake PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) target_include_directories(csnake PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(SIZE 10 CACHE STRING "Size of game field") set(SIZE 10 CACHE STRING "Size of game field")

View File

@ -7,6 +7,8 @@ OBJDIR = obj
SRC = main.c screen.c input.c player.c platform.c sleep.c SRC = main.c screen.c input.c player.c platform.c sleep.c
OBJ = $(addprefix $(OBJDIR)/,$(SRC:.c=.o)) OBJ = $(addprefix $(OBJDIR)/,$(SRC:.c=.o))
DEFLDFLAGS = $(shell if echo "" | cc -E -dM -xc - | grep __FreeBSD__ > /dev/null 2>&1; then echo "-lpthread"; fi)
all: $(OUT) all: $(OUT)
obj: obj:
@ -16,7 +18,7 @@ $(OBJDIR)/%.o: $(SRCDIR)/%.c
$(CC) -c -o $@ $< $(CFLAGS) $(INCLUDE) $(CC) -c -o $@ $< $(CFLAGS) $(INCLUDE)
$(OUT): obj $(OBJ) $(OUT): obj $(OBJ)
$(CC) -o $@ $(OBJ) $(LDFLAGS) $(CC) -o $@ $(OBJ) $(LDFLAGS) $(DEFLDFLAGS)
clean: clean:
$(RM) $(OUT) $(OBJDIR)/* $(RM) $(OUT) $(OBJDIR)/*