Got working cmake. C libraries be weird man.
This commit is contained in:
parent
68ebcdd39e
commit
0b937b1d6a
8 changed files with 93 additions and 60 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -6,9 +6,11 @@ cmake_install.cmake
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
.dir-locals.el
|
.dir-locals.el
|
||||||
Makefile
|
Makefile
|
||||||
urchin-*
|
urchin-server
|
||||||
|
urchin-client
|
||||||
lib*.a
|
lib*.a
|
||||||
lib*.so
|
lib*.so
|
||||||
|
|
||||||
#Generated code
|
#Generated code
|
||||||
src/protobuf_gen
|
src/protobuf_gen
|
||||||
|
urchin-util/src/protobuf_gen
|
||||||
|
|
|
||||||
|
|
@ -9,49 +9,8 @@ set(CMAKE_C_STANDARD 90)
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
set(CMAKE_C_CLANG_TIDY)
|
set(CMAKE_C_CLANG_TIDY)
|
||||||
|
|
||||||
# Get protobuf to serialize data between the server and client
|
include(CheckIncludeFile)
|
||||||
# cmake config not packaged with the lib. resort to pkg config
|
add_subdirectory(${CMAKE_SOURCE_DIR}/urchin-util)
|
||||||
include(FindPkgConfig)
|
|
||||||
pkg_check_modules(protobuf-c REQUIRED libprotobuf-c>=1.4.1)
|
|
||||||
|
|
||||||
# Compile Shared Library
|
|
||||||
file(GLOB_RECURSE LIBRARY_SOURCE_FILES
|
|
||||||
${CMAKE_SOURCE_DIR}/src/shared_lib/*.c)
|
|
||||||
|
|
||||||
file(GLOB_RECURSE LIBRARY_HEADER_FILES
|
|
||||||
${CMAKE_SOURCE_DIR}/src/shared_lib/*.h)
|
|
||||||
|
|
||||||
# Generate Protobuf code
|
|
||||||
find_program(protoc-c_EXECUTABLE NAMES protoc-c REQUIRED)
|
|
||||||
find_package_handle_standard_args(protoc-c REQUIRED_VARS protoc-c_EXECUTABLE)
|
|
||||||
file(GLOB_RECURSE PROTOBUF_PROTO_FILES
|
|
||||||
${CMAKE_SOURCE_DIR}/protobuf/*.proto)
|
|
||||||
add_custom_target(GenerateProtobuf)
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT GenerateProtobuf
|
|
||||||
DEPENDS ${protoc-c_EXECUTABLE}
|
|
||||||
COMMAND ${protoc-c_EXECUTABLE} --c_out=${CMAKE_SOURCE_DIR}/src/protobuf_gen/ --proto_path=${CMAKE_SOURCE_DIR}/protobuf/ ${PROTOBUF_PROTO_FILES}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Include protobuf generated message formats
|
|
||||||
file(GLOB_RECURSE PROTOBUF_SOURCE_FILES
|
|
||||||
${CMAKE_SOURCE_DIR}/src/protobuf_gen/*.c)
|
|
||||||
|
|
||||||
file(GLOB_RECURSE PROTOBUF_HEADER_FILES
|
|
||||||
${CMAKE_SOURCE_DIR}/src/protobuf_gen/*.h)
|
|
||||||
set_source_files_properties(${PROTOBUF_HEADER_FILES} ${PROTOBUF_SOURCE_FILES} PROPERTIES GENERATED TRUE)
|
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} STATIC
|
|
||||||
GenerateProtobuf
|
|
||||||
${LIBRARY_HEADER_FILES}
|
|
||||||
${PROTOBUF_HEADER_FILES}
|
|
||||||
${LIBRARY_SOURCE_FILES}
|
|
||||||
${PROTOBUF_SOURCE_FILES}
|
|
||||||
)
|
|
||||||
add_dependencies(${PROJECT_NAME} GenerateProtobuf)
|
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC protobuf-c)
|
|
||||||
|
|
||||||
|
|
||||||
# Compile Server
|
# Compile Server
|
||||||
file(GLOB_RECURSE SERVER_SOURCE_FILES
|
file(GLOB_RECURSE SERVER_SOURCE_FILES
|
||||||
|
|
@ -61,7 +20,7 @@ file(GLOB_RECURSE SERVER_HEADER_FILES
|
||||||
${CMAKE_SOURCE_DIR}/src/server/*.h)
|
${CMAKE_SOURCE_DIR}/src/server/*.h)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}-server ${SERVER_HEADER_FILES} ${SERVER_SOURCE_FILES})
|
add_executable(${PROJECT_NAME}-server ${SERVER_HEADER_FILES} ${SERVER_SOURCE_FILES})
|
||||||
target_link_libraries(${PROJECT_NAME}-server PUBLIC ${PROJECT_NAME})
|
target_link_libraries(${PROJECT_NAME}-server PUBLIC urchin-util)
|
||||||
|
|
||||||
# Compile Client
|
# Compile Client
|
||||||
file(GLOB_RECURSE CLIENT_SOURCE_FILES
|
file(GLOB_RECURSE CLIENT_SOURCE_FILES
|
||||||
|
|
@ -71,4 +30,4 @@ file(GLOB_RECURSE CLIENT_HEADER_FILES
|
||||||
${CMAKE_SOURCE_DIR}/src/client/*.h)
|
${CMAKE_SOURCE_DIR}/src/client/*.h)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}-client ${CLIENT_HEADER_FILES} ${CLIENT_SOURCE_FILES})
|
add_executable(${PROJECT_NAME}-client ${CLIENT_HEADER_FILES} ${CLIENT_SOURCE_FILES})
|
||||||
target_link_libraries(${PROJECT_NAME}-client PUBLIC ${PROJECT_NAME})
|
target_link_libraries(${PROJECT_NAME}-client PUBLIC urchin-util)
|
||||||
|
|
|
||||||
59
urchin-util/CMakeLists.txt
Normal file
59
urchin-util/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
project(urchin-util
|
||||||
|
VERSION 0
|
||||||
|
DESCRIPTION "Simple Mud Experiment in C"
|
||||||
|
HOMEPAGE_URL "https://git.warwick-new.co.uk/"
|
||||||
|
LANGUAGES C)
|
||||||
|
|
||||||
|
set(CMAKE_C_STANDARD 90)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
set(CMAKE_C_CLANG_TIDY)
|
||||||
|
|
||||||
|
# Get protobuf to serialize data between the server and client
|
||||||
|
# cmake config not packaged with the lib. resort to pkg config
|
||||||
|
include(FindPkgConfig)
|
||||||
|
pkg_check_modules(protobuf-c REQUIRED libprotobuf-c>=1.4.1)
|
||||||
|
|
||||||
|
# Compile Shared Library
|
||||||
|
file(GLOB LIBRARY_SOURCE_FILES
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)
|
||||||
|
|
||||||
|
file(GLOB LIBRARY_HEADER_FILES
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/*.h)
|
||||||
|
|
||||||
|
# Generate Protobuf code
|
||||||
|
find_program(protoc-c_EXECUTABLE NAMES protoc-c REQUIRED)
|
||||||
|
find_package_handle_standard_args(protoc-c REQUIRED_VARS protoc-c_EXECUTABLE)
|
||||||
|
file(GLOB_RECURSE PROTOBUF_PROTO_FILES
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/protobuf/*.proto)
|
||||||
|
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf_gen/)
|
||||||
|
add_custom_target(GenerateProtobuf)
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT GenerateProtobuf
|
||||||
|
DEPENDS ${protoc-c_EXECUTABLE}
|
||||||
|
COMMAND ${protoc-c_EXECUTABLE} --c_out=${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf_gen/ --proto_path=${CMAKE_CURRENT_SOURCE_DIR}/protobuf/ ${PROTOBUF_PROTO_FILES}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Include protobuf generated message formats
|
||||||
|
file(GLOB_RECURSE PROTOBUF_SOURCE_FILES
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf_gen/*.c)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE PROTOBUF_HEADER_FILES
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf_gen/*.h)
|
||||||
|
set_source_files_properties(${PROTOBUF_HEADER_FILES} ${PROTOBUF_SOURCE_FILES} PROPERTIES GENERATED TRUE)
|
||||||
|
|
||||||
|
add_library(${PROJECT_NAME} SHARED
|
||||||
|
GenerateProtobuf
|
||||||
|
${LIBRARY_HEADER_FILES}
|
||||||
|
${PROTOBUF_HEADER_FILES}
|
||||||
|
${LIBRARY_SOURCE_FILES}
|
||||||
|
${PROTOBUF_SOURCE_FILES}
|
||||||
|
)
|
||||||
|
target_link_libraries(${PROJECT_NAME} PUBLIC protobuf-c)
|
||||||
|
target_include_directories(${PROJECT_NAME} PUBLIC include)
|
||||||
|
|
||||||
|
install(
|
||||||
|
TARGETS ${PROJECT_NAME}
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
)
|
||||||
|
|
@ -9,5 +9,3 @@ void error_crash(const char *msg);
|
||||||
void error_warn(const char *msg);
|
void error_warn(const char *msg);
|
||||||
|
|
||||||
void error_log(const char *msg);
|
void error_log(const char *msg);
|
||||||
|
|
||||||
void msg_amsg_test(int a);
|
|
||||||
8
urchin-util/include/message.h
Normal file
8
urchin-util/include/message.h
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "error.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void msg_amsg_test(int a);
|
||||||
4
urchin-util/protobuf/amessage.proto
Normal file
4
urchin-util/protobuf/amessage.proto
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
message AMessage {
|
||||||
|
required int32 a=1;
|
||||||
|
optional int32 b=2;
|
||||||
|
}
|
||||||
13
urchin-util/src/error.c
Normal file
13
urchin-util/src/error.c
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
#include "error.h"
|
||||||
|
#include "protobuf_gen/amessage.pb-c.h"
|
||||||
|
#define MAX_MSG_SIZE 1024
|
||||||
|
|
||||||
|
void error_crash(const char *msg) {
|
||||||
|
fprintf(stderr, "error crash: %s\n", msg);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void error_warn(const char *msg) { fprintf(stderr, "warning: %s\n", msg); }
|
||||||
|
|
||||||
|
// TODO: Save the logs somewhere
|
||||||
|
void error_log(const char *msg) { fprintf(stderr, "log: %s\n", msg); }
|
||||||
|
|
@ -1,16 +1,6 @@
|
||||||
#include "error.h"
|
#include "message.h"
|
||||||
#include "../protobuf_gen/amessage.pb-c.h"
|
|
||||||
#define MAX_MSG_SIZE 1024
|
#define MAX_MSG_SIZE 1024
|
||||||
|
#include "protobuf_gen/amessage.pb-c.h"
|
||||||
void error_crash(const char *msg) {
|
|
||||||
fprintf(stderr, "error crash: %s\n", msg);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void error_warn(const char *msg) { fprintf(stderr, "warning: %s\n", msg); }
|
|
||||||
|
|
||||||
// TODO: Save the logs somewhere
|
|
||||||
void error_log(const char *msg) { fprintf(stderr, "log: %s\n", msg); }
|
|
||||||
|
|
||||||
void msg_amsg_test(int a) {
|
void msg_amsg_test(int a) {
|
||||||
AMessage msg = AMESSAGE__INIT; // The massage format
|
AMessage msg = AMESSAGE__INIT; // The massage format
|
||||||
Loading…
Reference in a new issue