aboutsummaryrefslogtreecommitdiff
blob: 1f76a9015ab407b43583b5b6937012466b93b9f1 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
# 3.0 introduces line continuation.

project("relabsd")

include(FindPkgConfig)

# ${SRC_FILES} is recursively defined in the subdirectories.
# Each subdirectory adds only the source files that are present at its level.
file(GLOB_RECURSE SRC_FILES src/ true src/*.c)
add_executable(relabsd ${SRC_FILES})

include_directories(include/)

# Language parameters.
enable_language(C)
target_compile_features(relabsd PUBLIC c_variadic_macros)

# We require libevdev.
pkg_search_module(LIBEVDEV REQUIRED libevdev)
include_directories(${LIBEVDEV_INCLUDE_DIRS})
target_link_libraries(relabsd ${LIBEVDEV_LIBRARIES})

# We use pthreads.
find_package(Threads)
target_link_libraries(relabsd ${CMAKE_THREAD_LIBS_INIT})

# Be loud about dubious code.
if (CMAKE_COMPILER_IS_GNUCC)
   message(STATUS "CMake is using GNUCC. Verbose flags are activated.")
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic -Werror -Wextra")
endif (CMAKE_COMPILER_IS_GNUCC)

option(
   RELABSD_DEBUG_PROGRAM_FLOW
   "Adds debug messages to display the program's flow."
   OFF
)
if (RELABSD_DEBUG_PROGRAM_FLOW)
   target_compile_definitions(
      relabsd
      PUBLIC
      "-DRELABSD_DEBUG_PROGRAM_FLOW=1"
   )
   message(STATUS "[OPTION] Debug messages for the program's flow.")
endif (RELABSD_DEBUG_PROGRAM_FLOW)

option(
   RELABSD_DEBUG_CONFIG
   "Adds debug messages to check the program's configuration."
   OFF
)
if (RELABSD_DEBUG_CONFIG)
   target_compile_definitions(
      relabsd
      PUBLIC
      "-DRELABSD_DEBUG_CONFIG=1"
   )
   message(STATUS "[OPTION] Debug messages for the program's configuration.")
endif (RELABSD_DEBUG_CONFIG)

option(
   RELABSD_DEBUG_REAL_EVENTS
   "Adds debug messages to check the real device's events."
   OFF
)
if (RELABSD_DEBUG_REAL_EVENTS)
   target_compile_definitions(
      relabsd
      PUBLIC
      "-DRELABSD_DEBUG_REAL_EVENTS=1"
   )
   message(STATUS "[OPTION] Debug messages for the real device's events.")
endif (RELABSD_DEBUG_REAL_EVENTS)

option(
   RELABSD_DEBUG_VIRTUAL_EVENTS
   "Adds debug messages to check the virtual device's events."
   OFF
)
if (RELABSD_DEBUG_VIRTUAL_EVENTS)
   target_compile_definitions(
      relabsd
      PUBLIC
      "-DRELABSD_DEBUG_VIRTUAL_EVENTS=1"
   )
   message(STATUS "[OPTION] Debug messages for the virtual device's events.")
endif (RELABSD_DEBUG_VIRTUAL_EVENTS)

option(
   RELABSD_ENABLE_ERROR_LOCATION
   "Debug/error messages contain source file and line information."
   OFF
)
if (RELABSD_ENABLE_ERROR_LOCATION)
   target_compile_definitions(relabsd PUBLIC RELABSD_ENABLE_ERROR_LOCATION)
   message(STATUS "[OPTION] Debug/error messages display source file and line.")
else ()
   message(
      STATUS
      "[OPTION] Debug/error messages do not display source file and line."
   )
endif (RELABSD_ENABLE_ERROR_LOCATION)


set(
   RELABSD_OPTION_MAX_SIZE
   "64"
   CACHE
   INTEGER
   "Maximum number of characters in an axis option (name + params)."
)
target_compile_definitions(
   relabsd
   PUBLIC
   "-DRELABSD_OPTION_MAX_SIZE=${RELABSD_OPTION_MAX_SIZE}"
)
message(
   STATUS
   "[OPTION] Axis options can contain up to ${RELABSD_OPTION_MAX_SIZE}\
 characters (name + params)."
)

set(
   RELABSD_DEVICE_PREFIX
   "relabsd:"
   CACHE
   STRING
   "String prefixing the name of the virtual device."
)
target_compile_definitions(
   relabsd
   PUBLIC
   "-DRELABSD_DEVICE_PREFIX=\"${RELABSD_DEVICE_PREFIX}\""
)
message(
   STATUS
   "[OPTION] Virtual devices' names are prefixed by '${RELABSD_DEVICE_PREFIX}'."
)