forked from congdpt/watchman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
471 lines (429 loc) · 13.1 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# This is an experimental cmakefile and doesn't offer all of the options
# available in the configure script! At this time you should prefer to
# use the configure script to build and install watchman!
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
enable_testing()
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(PACKAGE_VERSION "4.9.4")
set(WATCHMAN_VERSION_OVERRIDE "" CACHE STRING "Use this version code for \
Watchman instead of the default (${PACKAGE_VERSION})")
if (WATCHMAN_VERSION_OVERRIDE)
set(PACKAGE_VERSION "${WATCHMAN_VERSION_OVERRIDE}")
endif ()
set(PACKAGE_NAME "watchman")
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "https://github.com/facebook/watchman/issues")
project(${PACKAGE_NAME} CXX C)
include(CheckFunctionExists)
include(CheckIncludeFiles)
include(CheckStructHasMember)
include(CheckSymbolExists)
# configure_file wants us to define a separate file. I'd rather not
# have boilerplate for the same thing in two difference files, so we
# roll the checks in together with writing out the features to config.h
# ourselves here.
function(config_h LINE)
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/config.h.new" "${LINE}\n")
endfunction()
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/config.h.new" "#pragma once\n")
config_h("// Generated by cmake")
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
config_h("#define WATCHMAN_CONFIG_FILE \
\"C:/ProgramData/facebook/watchman.json\"")
else()
config_h("#define WATCHMAN_CONFIG_FILE \"/etc/watchman.json\"")
set(WATCHMAN_STATE_DIR "/var/run/watchman")
config_h("#define WATCHMAN_STATE_DIR \"${WATCHMAN_STATE_DIR}\"")
endif()
config_h("#define PACKAGE_VERSION \"${PACKAGE_VERSION}\"")
# While most of these tests are not strictly needed on windows, it is vital
# that we probe for and find strtoll in order for the jansson build to use
# a 64-bit integer type, otherwise the mtime_us field renders as garbage
# in the integration tests.
foreach(wat_func
FSEventStreamSetExclusionPaths
accept4
backtrace
backtrace_symbols
backtrace_symbols_fd
fdopendir
getattrlistbulk
inotify_init
inotify_init1
kqueue
localeconv
memmem
mkostemp
openat
pipe2
port_create
statfs
strtoll
sys_siglist
)
CHECK_FUNCTION_EXISTS(${wat_func} have_${wat_func})
if (have_${wat_func})
string(TOUPPER have_${wat_func} sym)
config_h("#define ${sym} 1")
endif()
endforeach(wat_func)
foreach(wat_header
CoreServices/CoreServices.h
execinfo.h
fcntl.h
inttypes.h
locale.h
port.h
sys/event.h
sys/inotify.h
sys/mount.h
sys/param.h
sys/resource.h
sys/socket.h
sys/statfs.h
sys/statvfs.h
sys/types.h
sys/ucred.h
sys/vfs.h
valgrind/valgrind.h
unistd.h
)
CHECK_INCLUDE_FILES(${wat_header} have_${wat_header})
if (have_${wat_header})
string(TOUPPER have_${wat_header} sym)
string(REGEX REPLACE [./] _ sym ${sym})
config_h("#define ${sym} 1")
endif()
endforeach(wat_header)
CHECK_STRUCT_HAS_MEMBER(statvfs f_fstypename sys/statvfs.h
HAVE_STRUCT_STATVFS_F_FSTYPENAME)
if (HAVE_STRUCT_STATVFS_F_BASETYPE)
config_h("define HAVE_STRUCT_STATVFS_F_FSTYPENAME 1")
endif()
CHECK_STRUCT_HAS_MEMBER(statvfs f_basetype sys/statvfs.h
HAVE_STRUCT_STATVFS_F_BASETYPE)
if (HAVE_STRUCT_STATVFS_F_BASETYPE)
config_h("define HAVE_STRUCT_STATVFS_F_BASETYPE 1")
endif()
if(have_fcntl.h)
CHECK_SYMBOL_EXISTS(O_SYMLINK fcntl.h HAVE_DECL_O_SYMLINK)
if(HAVE_DECL_O_SYMLINK)
config_h("#define HAVE_DECL_O_SYMLINK 1")
endif()
endif()
# Now close out config.h. We only want to touch the file if the contents are
# different, so do a little dance to figure that out.
if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/config.h")
file(MD5 "${CMAKE_CURRENT_BINARY_DIR}/config.h" orig_hash)
file(MD5 "${CMAKE_CURRENT_BINARY_DIR}/config.h.new" this_hash)
if(NOT orig_hash STREQUAL this_hash)
file(RENAME "${CMAKE_CURRENT_BINARY_DIR}/config.h.new"
"${CMAKE_CURRENT_BINARY_DIR}/config.h")
endif()
else()
file(RENAME "${CMAKE_CURRENT_BINARY_DIR}/config.h.new"
"${CMAKE_CURRENT_BINARY_DIR}/config.h")
endif()
configure_file(
thirdparty/jansson/jansson_config.h.in
thirdparty/jansson/jansson_config.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/thirdparty/jansson)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# This block is for cmake 3.0 which doesn't define the Threads::Threads
# interface section. Test for that and define it for ourselves.
if(THREADS_FOUND AND NOT TARGET Threads::Threads)
add_library(Threads::Threads INTERFACE IMPORTED)
if(THREADS_HAVE_PTHREAD_ARG)
set_property(TARGET Threads::Threads PROPERTY
INTERFACE_COMPILE_OPTIONS "-pthread")
endif()
if(CMAKE_THREAD_LIBS_INIT)
set_property(TARGET Threads::Threads PROPERTY
INTERFACE_LINK_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
endif()
endif()
find_package(OpenSSL)
# This block is for cmake 3.0 which doesn't define the OpenSSL::Crypto
# interface section. Test for that and define it for ourselves.
if(OPENSSL_FOUND AND NOT TARGET OpenSSL::Crypto)
add_library(OpenSSL::Crypto UNKNOWN IMPORTED)
set_target_properties(OpenSSL::Crypto PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}")
if(EXISTS "${OPENSSL_CRYPTO_LIBRARY}")
set_target_properties(OpenSSL::Crypto PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${OPENSSL_CRYPTO_LIBRARY}")
endif()
endif()
find_package(PythonInterp REQUIRED)
if(PYTHONINTERP_FOUND)
set(PYOUT "${CMAKE_CURRENT_BINARY_DIR}/build/pytimestamp")
set(PYSETUP "${CMAKE_CURRENT_SOURCE_DIR}/python/setup.py")
add_custom_command(
OUTPUT ${PYOUT}
# DEPENDS "python/pywatchman/*.py"
COMMAND ${PYTHON_EXECUTABLE} ${PYSETUP} clean
build_py -c -d ${CMAKE_CURRENT_BINARY_DIR}/python
build_ext -b ${CMAKE_CURRENT_BINARY_DIR}/python
-t ${CMAKE_CURRENT_BINARY_DIR}/python/build/temp
)
add_custom_target(pybuild ALL DEPENDS ${PYOUT})
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} \
${PYSETUP} install --root ${CMAKE_INSTALL_PREFIX})")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
# Check target architecture
if (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
message(FATAL_ERROR "watchman requires a 64bit target architecture.")
endif()
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/winbuild)
set(CMAKE_CXX_FLAGS "/Zi /Zo /MP /MT /Oi /EHsc /GL-")
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} /DEBUG /MT /OPT:NOREF")
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} /DEBUG /OPT:NOREF")
set(CMAKE_MODULE_LINKER_FLAGS
"${CMAKE_MODULE_LINKER_FLAGS} /DEBUG /MT /OPT:NOREF")
set(CMAKE_STATIC_LIBRARY_FLAGS
"${CMAKE_STATIC_LIBRARY_FLAGS} /DEBUG /MT /OPT:NOREF")
else()
set(CMAKE_CXX_FLAGS_COMMON "-g -Wall -Wextra -std=gnu++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_COMMON}") # for cmake 3.0
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_COMMON}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_COMMON} -O3")
endif()
add_library(wildmatch STATIC
thirdparty/wildmatch/wildmatch.c
thirdparty/wildmatch/wildmatch.h
)
add_library(tap STATIC thirdparty/tap.cpp thirdparty/tap.h)
add_library(log STATIC PubSub.cpp log.cpp)
add_library(hash STATIC hash.cpp)
add_library(err STATIC root/poison.cpp root/warnerr.cpp)
add_library(jansson_utf STATIC thirdparty/jansson/utf.cpp)
add_library(string STATIC string.cpp)
target_link_libraries(string jansson_utf hash)
add_library(jansson STATIC
thirdparty/jansson/dump.cpp
thirdparty/jansson/error.cpp
thirdparty/jansson/load.cpp
thirdparty/jansson/memory.cpp
thirdparty/jansson/pack_unpack.cpp
thirdparty/jansson/strbuffer.cpp
thirdparty/jansson/strconv.cpp
thirdparty/jansson/value.cpp
)
target_link_libraries(jansson string)
list(APPEND testsupport_sources
ChildProcess.cpp
FileDescriptor.cpp
FileInformation.cpp
Pipe.cpp
ThreadPool.cpp
bser.cpp
cfg.cpp
expflags.cpp
ignore.cpp
opendir.cpp
pending.cpp
time.cpp
stream.cpp
)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
list(APPEND testsupport_sources
winbuild/asprintf.cpp
winbuild/time.cpp
winbuild/backtrace.cpp
winbuild/errmap.cpp
winbuild/pathmap.cpp
winbuild/posix_spawn.cpp
stream_win.cpp
)
endif()
add_library(testsupport STATIC ${testsupport_sources})
target_link_libraries(testsupport log string jansson)
list(APPEND watchman_sources
ChildProcess.cpp
ContentHash.cpp
CookieSync.cpp
FileDescriptor.cpp
FileInformation.cpp
InMemoryView.cpp
LocalFileResult.cpp
Pipe.cpp
# PubSub.cpp (in liblog)
QueryableView.cpp
SymlinkTargets.cpp
ThreadPool.cpp
bser.cpp
cfg.cpp
checksock.cpp
clientmode.cpp
clockspec.cpp
error_category.cpp
expflags.cpp
fstype.cpp
groups.cpp
# hash.cpp (in libhash)
ignore.cpp
ioprio.cpp
json.cpp
launchd.cpp
listener-user.cpp
listener.cpp
main.cpp
opendir.cpp
opt.cpp
pending.cpp
perf.cpp
sockname.cpp
spawn.cpp
state.cpp
stream.cpp
stream_stdout.cpp
# string.cpp (in libstring)
time.cpp
timedlock.cpp
tmp.cpp
query/base.cpp
query/dirname.cpp
query/empty.cpp
query/eval.cpp
query/fieldlist.cpp
query/glob.cpp
query/intcompare.cpp
query/match.cpp
query/name.cpp
query/parse.cpp
# query/pcre.cpp
query/since.cpp
query/suffix.cpp
query/type.cpp
cmds/debug.cpp
cmds/find.cpp
# cmds/heapprof.cpp
cmds/info.cpp
cmds/log.cpp
cmds/query.cpp
cmds/reg.cpp
cmds/since.cpp
cmds/state.cpp
cmds/subscribe.cpp
cmds/trigger.cpp
cmds/watch.cpp
root/ageout.cpp
root/crawler.cpp
root/dir.cpp
root/file.cpp
root/init.cpp
root/iothread.cpp
root/notifythread.cpp
# root/poison.cpp (in liberr)
root/reap.cpp
root/resolve.cpp
root/stat.cpp
root/symlink.cpp
root/sync.cpp
root/threading.cpp
root/vcs.cpp
# root/warnerr.cpp (in liberr)
root/watchlist.cpp
saved_state/LocalSavedStateInterface.cpp
saved_state/SavedStateInterface.cpp
scm/Mercurial.cpp
scm/SCM.cpp
watcher/auto.cpp
# watcher/eden.cpp
watcher/fsevents.cpp
watcher/inotify.cpp
watcher/kqueue.cpp
watcher/portfs.cpp
)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
list(APPEND watchman_sources
stream_win.cpp
watcher/win32.cpp
winbuild/errmap.cpp
winbuild/pathmap.cpp
winbuild/mkdir.cpp
winbuild/dir.cpp
winbuild/asprintf.cpp
winbuild/hostname.cpp
winbuild/time.cpp
winbuild/backtrace.cpp
winbuild/getopt_long.cpp
winbuild/posix_spawn.cpp
)
else()
list(APPEND watchman_sources
stream_unix.cpp
)
endif()
add_executable(watchman ${watchman_sources})
target_link_libraries(watchman log hash string err jansson wildmatch)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_link_libraries(watchman "-framework CoreServices")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(watchman shlwapi.lib advapi32.lib dbghelp.lib)
endif()
target_link_libraries(watchman Threads::Threads)
if(TARGET OpenSSL::Crypto)
target_link_libraries(watchman OpenSSL::Crypto)
endif()
install(TARGETS watchman RUNTIME DESTINATION bin)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(DEST_STATE_DIR "${CMAKE_INSTALL_PREFIX}${WATCHMAN_STATE_DIR}")
install(DIRECTORY DESTINATION ${DEST_STATE_DIR} DIRECTORY_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE
GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE SETGID)
endif()
set(tests)
# Helper function to define a unit test executable
function(t_test NAME)
add_executable(${NAME}.t ${ARGN})
target_link_libraries(${NAME}.t testsupport tap Threads::Threads wildmatch)
if(TARGET OpenSSL::Crypto)
target_link_libraries(${NAME}.t OpenSSL::Crypto)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(${NAME}.t shlwapi.lib advapi32.lib dbghelp.lib)
endif()
target_compile_definitions(${NAME}.t
PUBLIC WATCHMAN_TEST_SRC_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\")
add_test(NAME ${NAME} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.t)
list(APPEND tests ${NAME}.t)
endfunction()
# The `check` target runs the unit tests
add_custom_target(check
DEPENDS ${tests}
COMMAND ${CMAKE_CTEST_COMMAND})
if(PYTHONINTERP_FOUND)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_executable(susres winbuild/susres.cpp)
add_custom_target(make_susres ALL DEPENDS susres)
endif()
# The `integration` target runs the unit tests and integration tests
add_custom_target(integration
DEPENDS pybuild check
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/runtests.py
--watchman-path ${CMAKE_CURRENT_BINARY_DIR}/watchman
--pybuild-dir ${CMAKE_CURRENT_BINARY_DIR}/python
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
t_test(art tests/art_test.cpp tests/log_stub.cpp)
t_test(ignore tests/ignore_test.cpp tests/log_stub.cpp)
t_test(pending tests/pending_test.cpp tests/log_stub.cpp)
t_test(string tests/string_test.cpp tests/log_stub.cpp)
t_test(log tests/log.cpp)
t_test(bser tests/bser.cpp tests/log_stub.cpp)
t_test(wildmatch tests/wildmatch_test.cpp tests/log_stub.cpp)
t_test(childproc tests/childproc.cpp tests/log_stub.cpp)
t_test(result tests/ResultTest.cpp tests/log_stub.cpp)
t_test(optional tests/OptionalTest.cpp tests/log_stub.cpp)
t_test(future tests/FutureTest.cpp tests/log_stub.cpp)
t_test(cache tests/CacheTest.cpp tests/log_stub.cpp)
t_test(MapUtilTest tests/MapUtilTest.cpp tests/log_stub.cpp)