CMake integration

This commit is contained in:
2026-02-10 14:42:45 +02:00
parent bc42f3a72f
commit 21b9f46f77
10 changed files with 106 additions and 54 deletions
+11
View File
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.23)
project(ZBBSServer
VERSION 1.0.0
)
add_subdirectory(src)
install(
TARGETS zbbs-server
)
+25
View File
@@ -0,0 +1,25 @@
{
"version": 4,
"configurePresets": [
{
"name": "debug",
"displayName": "Debug",
"description": "Debug build",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"ZBBS_DEBUG": "ON",
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"displayName": "Release",
"description": "Release build",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"ZBBS_DEBUG": "OFF",
"CMAKE_BUILD_TYPE":"Release"
}
}
]
}
-35
View File
@@ -1,35 +0,0 @@
CFLAGS := -ggdb -Wextra -pedantic -std=c23 -lpq -lcrypto
SRC_DIR := src
OBJ_DIR := src/obj
BIN_DIR := bin
SRCS := $(wildcard $(SRC_DIR)/*.c)
OBJS := $(SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
OBJS += murmur3.o
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(SRC_DIR)/%.h
$(CC) $(CFLAGS) -c $< -o $@
bbs-server: $(OBJS)
$(CC) $(CFLAGS) $^ -o $(BIN_DIR)/$@
murmur3.o: $(SRC_DIR)/libs/murmur3/murmur3.c $(SRC_DIR)/libs/murmur3/murmur3.h
$(CC) $(CFLAGS) -c $< -o $@
ifneq (clean, $(MAKECMDGOALS))
-include deps.mk
endif
deps.mk: $(SRCS)
$(CC) -MM $^ > $(SRC_DIR)/$@
clean:
rm -f $(OBJ_DIR)/*.o $(BIN_DIR)/bbs-server
run:
$(BIN_DIR)/bbs-server wdir
valgrind:
valgrind --tool=memcheck $(BIN_DIR)/bbs-server wdir
-7
View File
@@ -1,7 +0,0 @@
client.o: src/client.c src/client.h src/main.h src/file_p.h src/session.h
file_p.o: src/file_p.c src/file_p.h src/main.h src/session.h
main.o: src/main.c src/main.h src/file_p.h src/server.h
server.o: src/server.c src/main.h src/session.h src/user.h
session.o: src/session.c src/session.h src/main.h src/client.h \
src/file_p.h src/user.h
user.o: src/user.c src/main.h src/session.h
-1
View File
@@ -1,6 +1,5 @@
#!/bin/sh #!/bin/sh
mkdir bin
mkdir wdir mkdir wdir
mkdir wdir/storage mkdir wdir/storage
touch wdir/file_descriptions touch wdir/file_descriptions
+55
View File
@@ -0,0 +1,55 @@
add_executable(zbbs-server)
set_property(TARGET zbbs-server PROPERTY C_STANDARD 23)
find_package(PostgreSQL REQUIRED)
if(NOT PostgreSQL_FOUND)
message(FATAL_ERROR "PostgreSQL not found. Please install libpq-dev or set PostgreSQL_ROOT.")
endif()
find_package(OpenSSL REQUIRED)
if(NOT OpenSSL_FOUND)
message(FATAL_ERROR "OpenSSL not found. Please install libcrypto or set OpenSSL_ROOT.")
endif()
file(GLOB M_HEADERS "*.h")
file(GLOB M_SOURCES "*.c")
target_sources(zbbs-server
PRIVATE
${M_SOURCES}
PUBLIC
FILE_SET HEADERS
FILES
${M_HEADERS}
"types.h"
)
add_subdirectory(libs)
target_link_libraries(zbbs-server
PRIVATE
murmur3
PostgreSQL::PostgreSQL
OpenSSL::Crypto
)
if (ZBBS_DEBUG)
if(
(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") OR
(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
)
target_compile_options(zbbs-server PRIVATE /W3)
message("Include debug info (Microsoft)")
elseif(
(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR
(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
)
target_compile_options(zbbs-server PRIVATE -Wall -ggdb -pedantic)
message("Include debug info (GNU/Clang)")
endif()
endif()
-10
View File
@@ -1,10 +0,0 @@
client.o: src/client.c src/client.h src/main.h src/types.h src/file_p.h \
src/session.h
db.o: src/db.c src/db.h src/main.h src/types.h
file_p.o: src/file_p.c src/file_p.h src/main.h src/types.h src/db.h \
src/libs/murmur3/murmur3.h src/session.h
main.o: src/main.c src/main.h src/types.h src/server.h src/db.h
server.o: src/server.c src/main.h src/types.h src/session.h src/user.h
session.o: src/session.c src/session.h src/main.h src/types.h \
src/client.h src/db.h src/file_p.h src/user.h
user.o: src/user.c src/db.h src/main.h src/types.h src/session.h
+1 -1
View File
@@ -1,6 +1,6 @@
#include "file_p.h" #include "file_p.h"
#include "db.h" #include "db.h"
#include "libs/murmur3/murmur3.h" #include <murmur3.h>
#include "main.h" #include "main.h"
#include "session.h" #include "session.h"
#include <arpa/inet.h> #include <arpa/inet.h>
+1
View File
@@ -0,0 +1 @@
add_subdirectory(murmur3)
+13
View File
@@ -0,0 +1,13 @@
add_library(murmur3 STATIC)
file(GLOB M_HEADERS "*.h")
file(GLOB M_SOURCES "*.c")
target_sources(murmur3
PRIVATE
${M_SOURCES}
PUBLIC
FILE_SET HEADERS
FILES
${M_HEADERS}
)