-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
98 lines (76 loc) · 2.66 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
cmake_minimum_required(VERSION 3.10)
project(lua-mumble)
# Set Lua version and dependencies
set(LUAVER "luajit" CACHE STRING "Lua version to compile for (luajit, lua5.1, lua5.2)")
set(LUALIB "/usr/local/lib/lua/5.1" CACHE PATH "Directory to install the Lua module")
# Set dependencies
set(DEPENDENCIES libssl ${LUAVER} libprotobuf-c opus sndfile libuv)
# Include directories and libraries
find_package(PkgConfig REQUIRED)
find_package(Threads REQUIRED)
pkg_check_modules(PKG_DEPS REQUIRED ${DEPENDENCIES})
# Compiler flags
set(CMAKE_C_FLAGS "-fPIC -I. -Wall")
if("${LUAVER}" STREQUAL "luajit")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLUAJIT")
endif()
# Output directories
set(BUILD_DIR "${CMAKE_BINARY_DIR}/build")
set(BUILD_PROTO_DIR "${CMAKE_BINARY_DIR}/proto")
set(PROTO_PATH "${CMAKE_SOURCE_DIR}/proto")
# Ensure the proto output directory exists
file(MAKE_DIRECTORY ${BUILD_PROTO_DIR})
# Proto files
file(GLOB PROTO_SOURCES "proto/*.proto")
# Add the generated proto source files
set(PROTO_C ${PROTO_SOURCES})
set(PROTO_H ${PROTO_SOURCES})
# C files
file(GLOB SOURCES "mumble/*.c")
set(OBJECTS ${PROTO_C} ${SOURCES})
# Dependencies
include_directories(${PKG_DEPS_INCLUDE_DIRS})
link_directories(${PKG_DEPS_LIBRARY_DIRS})
add_definitions(${PKG_DEPS_CFLAGS_OTHER})
# Proto files compilation step
foreach(proto_file IN LISTS PROTO_SOURCES)
get_filename_component(proto_name ${proto_file} NAME_WE)
# Ensure the proto files are generated before compiling C files
add_custom_command(
OUTPUT "${BUILD_PROTO_DIR}/${proto_name}.pb-c.c" "${BUILD_PROTO_DIR}/${proto_name}.pb-c.h"
COMMAND protoc-c --c_out=${BUILD_PROTO_DIR} -I${PROTO_PATH} ${proto_file}
DEPENDS ${proto_file}
COMMENT "Generating C files from proto ${proto_file}"
)
list(APPEND OBJECTS "${BUILD_PROTO_DIR}/${proto_name}.pb-c.c")
endforeach()
# Set the GIT_VERSION variable using Git's current commit hash
execute_process(
COMMAND git rev-parse --short HEAD
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Generate gitversion.h from the current Git commit hash
configure_file(
${CMAKE_SOURCE_DIR}/gitversion.h.in
${CMAKE_BINARY_DIR}/gitversion.h
@ONLY
)
# Add the generated gitversion.h as a dependency for the compilation
include_directories(${CMAKE_BINARY_DIR})
# Lua modules don't need a prefix
set(CMAKE_SHARED_LIBRARY_PREFIX "")
# Create the library target
add_library(mumble SHARED ${OBJECTS})
# Libraries
target_link_libraries(mumble ${PKG_DEPS_LIBRARIES})
# Installation
install(TARGETS mumble DESTINATION ${LUALIB})
# Uninstallation
add_custom_target(uninstall
COMMAND rm -f ${LUALIB}/mumble.so
)
# Debug build
set(CMAKE_C_FLAGS_DEBUG "-DDEBUG -g")
# Optimize build
set(CMAKE_C_FLAGS_RELEASE "-O2")