-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
250 lines (231 loc) · 5.73 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
cmake_minimum_required(VERSION 3.8)
project(ofs-bin LANGUAGES C CXX)
set(OFS_BIN_SOURCES_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
add_executable(${PROJECT_NAME}
${OFS_BIN_SOURCES_DIR}/conflictmanager.cpp
${OFS_BIN_SOURCES_DIR}/filestatusmanager.cpp
${OFS_BIN_SOURCES_DIR}/offlinerecognizer.cpp
${OFS_BIN_SOURCES_DIR}/ofsexception.cpp
${OFS_BIN_SOURCES_DIR}/synchronizationmanager.cpp
${OFS_BIN_SOURCES_DIR}/syncronisationmanager.cpp
${OFS_BIN_SOURCES_DIR}/backingtree.cpp
${OFS_BIN_SOURCES_DIR}/backingtreemanager.cpp
${OFS_BIN_SOURCES_DIR}/backingtreepersistence.cpp
${OFS_BIN_SOURCES_DIR}/conflictpersistence.cpp
${OFS_BIN_SOURCES_DIR}/file_sync.cpp
${OFS_BIN_SOURCES_DIR}/file.cpp
${OFS_BIN_SOURCES_DIR}/filesystemstatusmanager.cpp
${OFS_BIN_SOURCES_DIR}/lazywrite.cpp
${OFS_BIN_SOURCES_DIR}/logger.cpp
${OFS_BIN_SOURCES_DIR}/ofs_fuse.cpp
${OFS_BIN_SOURCES_DIR}/ofs.cpp
${OFS_BIN_SOURCES_DIR}/ofsbroadcast.cpp
${OFS_BIN_SOURCES_DIR}/ofsenvironment.cpp
${OFS_BIN_SOURCES_DIR}/ofsfile.cpp
${OFS_BIN_SOURCES_DIR}/ofslog.cpp
${OFS_BIN_SOURCES_DIR}/persistable.cpp
${OFS_BIN_SOURCES_DIR}/persistencemanager.cpp
${OFS_BIN_SOURCES_DIR}/synchronizationpersistence.cpp
${OFS_BIN_SOURCES_DIR}/synclogentry.cpp
${OFS_BIN_SOURCES_DIR}/synclogger.cpp
)
set_target_properties(ofs-bin
PROPERTIES
CXX_STANDARD 11
OUTPUT_NAME ofs
)
target_compile_definitions(${PROJECT_NAME}
PUBLIC
OFS_STATE_DIR="${CMAKE_INSTALL_PREFIX}/var/ofs"
)
target_include_directories(${PROJECT_NAME}
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/src
)
################
# dependencies #
################
find_package(DBus1 REQUIRED)
find_package(PkgConfig)
pkg_check_modules(FUSE REQUIRED fuse)
pkg_check_modules(CONFUSE REQUIRED libconfuse)
add_subdirectory(libraries/libofs)
add_subdirectory(libraries/libofsconf)
add_subdirectory(libraries/libofshash)
target_compile_options(${PROJECT_NAME}
PUBLIC
${FUSE_CFLAGS}
${CONFUSE_CFLAGS}
)
target_link_directories(${PROJECT_NAME}
PUBLIC
${FUSE_LIBRARY_DIRS}
${CONFUSE_LIBRARY_DIRS}
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
dbus-1
${FUSE_LIBRARIES}
${CONFUSE_LIBRARIES}
ofs
ofsconf
ofshash
)
##########
# checks #
##########
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckFunctionExists)
unset(HAVE_REQUIRED_HEADERS CACHE)
check_include_files(
"arpa/inet.h;fcntl.h;netdb.h;stdlib.h;string.h;sys/file.h;sys/mount.h;sys/socket.h;sys/time.h;syslog.h;unistd.h;utime.h"
HAVE_REQUIRED_HEADERS
)
unset(HAVE_REQUIRED_FUNCTIONS CACHE)
check_function_exists(
"ftruncate;gethostbyname;lchown;memset;mkdir;mkfifo;rmdir;select;socket;strchr;strerror;strstr;utime;setxattr"
HAVE_REQUIRED_FUNCTIONS
)
if(NOT HAVE_REQUIRED_FUNCTIONS OR NOT HAVE_REQUIRED_FUNCTIONS)
message(FATAL_ERROR "Not all required headers or functions are available.")
endif()
check_include_file(
"sys/mount.h"
HAVE_SYS_MOUNT_H
)
if(HAVE_SYS_MOUNT_H)
target_compile_definitions(${PROJECT_NAME}
PUBLIC
HAVE_SYS_MOUNT_H
)
endif()
check_function_exists(
"umount2"
HAVE_UMOUNT2
)
if(HAVE_UMOUNT2)
target_compile_definitions(${PROJECT_NAME}
PUBLIC
HAVE_UMOUNT2
)
endif()
check_function_exists(
"fdatasync"
HAVE_FDATASYNC
)
if(HAVE_FDATASYNC)
target_compile_definitions(${PROJECT_NAME}
PUBLIC
HAVE_FDATASYNC
)
endif()
################
# xattr checks #
################
pkg_check_modules(ATTR libattr)
check_include_file(
"attr/xattr.h"
HAVE_ATTR_XATTR_H
)
if(HAVE_ATTR_XATTR_H)
target_compile_definitions(${PROJECT_NAME}
PUBLIC
HAVE_ATTR_XATTR_H
)
endif()
check_include_file(
"sys/xattr.h"
HAVE_SYS_XATTR_H
)
if(HAVE_SYS_XATTR_H)
target_compile_definitions(${PROJECT_NAME}
PUBLIC
HAVE_SYS_XATTR_H
)
endif()
check_function_exists(
"setxattr"
HAVE_SETXATTR
)
if(HAVE_SETXATTR)
target_compile_definitions(${PROJECT_NAME}
PUBLIC
HAVE_SETXATTR
)
endif()
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.19.0")
# CheckSourceCompiles was added in CMake 3.19
include(CheckSourceCompiles)
check_source_compiles(
C
"
#include <sys/types.h>
#if HAVE_ATTR_XATTR_H
#include <attr/xattr.h>
#elif HAVE_SYS_XATTR_H
#include <sys/xattr.h>
#endif
getxattr(0, 0, 0, 0, 0, 0);
"
COMPILES_XATTR_ADD_OPT
)
if (COMPILES_XATTR_ADD_OPT)
message("xattr functions have additional options")
target_compile_definitions(${PROJECT_NAME}
PUBLIC
XATTR_ADD_OPT=1
)
endif()
check_source_compiles(
C
"
#define FUSE_USE_VERSION 26
#include <fuse.h>
struct fuse_operations f;
(f.getxattr)(0, 0, 0, 0, 0);
"
COMPILES_FUSE_CV_XATTR_ADD_OPT
)
if (COMPILES_FUSE_CV_XATTR_ADD_OPT)
message("FUSE xattr functions have additional options")
target_compile_definitions(${PROJECT_NAME}
PUBLIC
FUSE_XATTR_ADD_OPT=1
)
endif()
else()
message("Please consider to switch to CMake 3.19.0")
endif()
###########
# install #
###########
set(CMAKE_INSTALL_BINDIR sbin)
install(TARGETS ${PROJECT_NAME})
if(UNIX)
if(APPLE)
set(MOUNT_HELPER_PROG "mount_ofs")
else() # Linux
set(MOUNT_HELPER_PROG "mount.ofs")
endif()
else()
message(FATAL_ERROR "FUSE is only available on UNIX.")
endif()
case "${target_os}" in
linux*)
MOUNT_HELPER_PROG="mount.ofs"
;;
darwin*|freebsd*)
MOUNT_HELPER_PROG="mount_ofs"
;;
esac
install(DIRECTORY DESTINATION /sbin)
install(CODE "execute_process( \
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/ofs \
/sbin/${MOUNT_HELPER_PROG} \
)"
)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/man8 TYPE MAN)
install(DIRECTORY DESTINATION ${CMAKE_INSTALL_PREFIX}/var/ofs/remote)
install(DIRECTORY DESTINATION ${CMAKE_INSTALL_PREFIX}/var/ofs/backing)