-
Notifications
You must be signed in to change notification settings - Fork 50
/
rct.cmake
269 lines (238 loc) · 8.74 KB
/
rct.cmake
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
cmake_minimum_required(VERSION 2.8)
project(rct)
if (POLICY CMP0022)
cmake_policy(SET CMP0022 OLD)
endif ()
if (POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/")
include(CheckSymbolExists)
include(CheckCXXSymbolExists)
include(CheckCXXSourceCompiles)
include(CheckCXXSourceRuns)
include(${CMAKE_CURRENT_LIST_DIR}/compiler.cmake)
check_cxx_symbol_exists(backtrace "execinfo.h" HAVE_BACKTRACE)
check_cxx_symbol_exists(CLOCK_MONOTONIC_RAW "time.h" HAVE_CLOCK_MONOTONIC_RAW)
check_cxx_symbol_exists(CLOCK_MONOTONIC "time.h" HAVE_CLOCK_MONOTONIC)
check_cxx_symbol_exists(mach_absolute_time "mach/mach.h;mach/mach_time.h" HAVE_MACH_ABSOLUTE_TIME)
check_cxx_symbol_exists(inotify_init "sys/inotify.h" HAVE_INOTIFY)
check_cxx_symbol_exists(kqueue "sys/types.h;sys/event.h" HAVE_KQUEUE)
check_cxx_symbol_exists(epoll_wait "sys/epoll.h" HAVE_EPOLL)
check_cxx_symbol_exists(select "sys/select.h" HAVE_SELECT)
check_cxx_symbol_exists(FD_CLOEXEC "fcntl.h" HAVE_CLOEXEC)
check_cxx_symbol_exists(SO_NOSIGPIPE "sys/types.h;sys/socket.h" HAVE_NOSIGPIPE)
check_cxx_symbol_exists(MSG_NOSIGNAL "sys/types.h;sys/socket.h" HAVE_NOSIGNAL)
check_cxx_symbol_exists(GetLogicalProcessorInformation "windows.h" HAVE_PROCESSORINFORMATION)
check_cxx_symbol_exists(SCHED_IDLE "pthread.h" HAVE_SCHEDIDLE)
check_cxx_symbol_exists(SHM_DEST "sys/types.h;sys/ipc.h;sys/shm.h" HAVE_SHMDEST)
if (CYGWIN)
message("-- Using win32 FileSystemWatcher")
set(HAVE_CHANGENOTIFICATION 1)
set(HAVE_CYGWIN 1)
endif ()
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
exec_program(sw_vers ARGS -productVersion OUTPUT_VARIABLE OSX_VERSION)
message("OS X version ${OSX_VERSION}")
string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\..*$" "\\1" OSX_MAJOR ${OSX_VERSION})
string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\..*$" "\\1" OSX_MINOR ${OSX_VERSION})
if (${OSX_MAJOR} EQUAL 10 AND ${OSX_MINOR} GREATER 6)
set(HAVE_FSEVENTS 1)
message("-- Using FSEvents")
elseif (${OSX_MAJOR} GREATER 10)
set(HAVE_FSEVENTS 1)
message("-- Using FSEvents")
else ()
message("-- Using kqueue")
endif ()
endif ()
check_cxx_source_compiles("
#include <sys/types.h>
#include <sys/stat.h>
int main(int, char**) {
struct stat st;
return st.st_mtim.tv_sec;
}" HAVE_STATMTIM)
if (NOT DEFINED RCT_INCLUDE_DIR)
set(RCT_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/include/rct")
endif ()
set(RCT_DEFINITIONS "")
find_package(ZLIB)
if (ZLIB_FOUND)
set(RCT_DEFINITIONS ${RCT_DEFINITIONS} -DRCT_HAVE_ZLIB)
else ()
message("ZLIB Can't be found. Rct configured without zlib support")
endif ()
find_package(OpenSSL REQUIRED)
include_directories(${CMAKE_CURRENT_LIST_DIR} ${RCT_INCLUDE_DIR} ${RCT_INCLUDE_DIR}/.. ${ZLIB_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR})
set(RCT_SOURCES
${RCT_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/rct/AES256CBC.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/Buffer.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/Config.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/Connection.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/CpuUsage.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/EventLoop.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/FileSystemWatcher.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/Log.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/MemoryMonitor.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/Message.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/MessageQueue.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/Path.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/Plugin.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/Process.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/Rct.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/ReadWriteLock.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/SHA256.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/Semaphore.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/SharedMemory.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/SocketClient.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/SocketServer.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/String.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/Thread.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/ThreadPool.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/Timer.cpp
${CMAKE_CURRENT_LIST_DIR}/rct/Value.cpp
${CMAKE_CURRENT_LIST_DIR}/cJSON/cJSON.c)
if (HAVE_INOTIFY EQUAL 1)
list(APPEND RCT_SOURCES ${CMAKE_CURRENT_LIST_DIR}/rct/FileSystemWatcher_inotify.cpp)
elseif (HAVE_FSEVENTS EQUAL 1)
list(APPEND RCT_SOURCES ${CMAKE_CURRENT_LIST_DIR}/rct/FileSystemWatcher_fsevents.cpp)
elseif (HAVE_KQUEUE EQUAL 1)
list(APPEND RCT_SOURCES ${CMAKE_CURRENT_LIST_DIR}/rct/FileSystemWatcher_kqueue.cpp)
elseif (HAVE_CHANGENOTIFICATION EQUAL 1)
list(APPEND RCT_SOURCES ${CMAKE_CURRENT_LIST_DIR}/rct/FileSystemWatcher_win32.cpp)
endif ()
if (RCT_BUILD_SCRIPTENGINE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/")
find_package(V8)
if (V8_FOUND STREQUAL "YES")
set(HAVE_SCRIPTENGINE 1)
message("Building ScriptEngine")
set(RCT_SOURCES ${RCT_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/rct/ScriptEngine.cpp)
include_directories(${V8_INCLUDE_DIR})
endif ()
endif ()
configure_file(${CMAKE_CURRENT_LIST_DIR}/rct/rct-config.h.in ${RCT_INCLUDE_DIR}/rct-config.h.gen)
if (EXISTS "${RCT_INCLUDE_DIR}/rct-config.h")
file(READ "${RCT_INCLUDE_DIR}/rct-config.h" cfif_output)
else()
set(cfif_output "")
endif ()
file(READ "${RCT_INCLUDE_DIR}/rct-config.h.gen" cfif_output_gen)
if (NOT "${cfif_output}" STREQUAL "${cfif_output_gen}")
file (WRITE "${RCT_INCLUDE_DIR}/rct-config.h" "${cfif_output_gen}")
endif ()
file(REMOVE "${RCT_INCLUDE_DIR}/rct-config.h.gen")
set(RCT_DEFINITIONS ${RCT_DEFINITIONS} -DOS_${CMAKE_SYSTEM_NAME})
if (RCT_SERIALIZER_VERIFY_PRIMITIVE_SIZE)
set(RCT_DEFINITIONS ${RCT_DEFINITIONS} -DRCT_SERIALIZER_VERIFY_PRIMITIVE_SIZE=1)
endif ()
add_definitions(${RCT_DEFINITIONS})
if (RCT_STATIC)
add_library(rct ${RCT_SOURCES})
else()
add_library(rct SHARED ${RCT_SOURCES})
endif ()
if (RCT_EVENTLOOP_CALLBACK_TIME_THRESHOLD)
set(RCT_DEFINITIONS ${RCT_DEFINITIONS} "-DRCT_EVENTLOOP_CALLBACK_TIME_THRESHOLD=${RCT_EVENTLOOP_CALLBACK_TIME_THRESHOLD}")
endif ()
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
find_library(CORESERVICES_LIBRARY CoreServices)
find_path(CORESERVICES_INCLUDE "CoreServices/CoreServices.h")
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
find_path(COREFOUNDATION_INCLUDE "CoreFoundation/CoreFoundation.h")
endif ()
set(RCT_LIBRARIES pthread ${ZLIB_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARY})
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
list(APPEND RCT_LIBRARIES dl rt)
endif ()
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
list(APPEND RCT_LIBRARIES ${CORESERVICES_LIBRARY} ${COREFOUNDATION_LIBRARY})
endif ()
target_link_libraries(rct ${RCT_LIBRARIES} ${V8_LIBRARIES})
set_target_properties(rct PROPERTIES INTERFACE_LINK_LIBRARIES ${RCT_LIBRARIES})
set_target_properties(rct PROPERTIES LINK_INTERFACE_LIBRARIES ${RCT_LIBRARIES})
if (NOT RCT_NO_INSTALL)
install(CODE "message(\"Installing rct...\")")
install(TARGETS rct DESTINATION lib COMPONENT rct EXPORT rct)
endif ()
set(CMAKE_REQUIRED_FLAGS "-std=c++11")
if (RCT_USE_LIBCXX)
set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_EXE_LINKER_FLAGS}")
endif ()
check_cxx_source_compiles("
#include <memory>
#include <mutex>
#include <tuple>
#include <string>
#include <${CMAKE_CURRENT_LIST_DIR}/rct/Apply.h>
void callTest(int, std::string) { }
int main(int, char**) {
std::shared_ptr<int> ptr;
std::mutex mtx;
std::unique_lock<std::mutex> lock(mtx);
std::tuple<int, std::string> tpl(5, std::string(\"foo\"));
applyMove(std::bind(callTest, std::placeholders::_1, std::placeholders::_2), tpl);
return 0;
}" HAVE_CXX11)
if (NOT HAVE_CXX11)
message(FATAL_ERROR "C++11 support not detected. rct requires a modern compiler, GCC >= 4.8 or Clang >= 3.2 should suffice")
endif ()
check_cxx_source_runs("
#include <unordered_map>
int main(int, char **)
{
std::unordered_map<int, int> a;
a.emplace(1, 1);
std::unordered_map<int, int> b = std::move(a);
a.emplace(1, 1);
return 0;
}" HAVE_UNORDERDED_MAP_WORKING_MOVE_CONSTRUCTOR)
unset(CMAKE_REQUIRED_FLAGS)
unset(CMAKE_REQUIRED_LIBRARIES)
if (NOT RCT_NO_INSTALL)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/include/rct/rct-config.h
rct/AES256CBC.h
rct/Apply.h
rct/Buffer.h
rct/Config.h
rct/Connection.h
rct/EventLoop.h
rct/FileSystemWatcher.h
rct/List.h
rct/Log.h
rct/Map.h
rct/MemoryMonitor.h
rct/Message.h
rct/MessageQueue.h
rct/Path.h
rct/Plugin.h
rct/Point.h
rct/Process.h
rct/Rct.h
rct/ReadLocker.h
rct/ReadWriteLock.h
rct/Rect.h
rct/ResponseMessage.h
rct/SHA256.h
rct/Semaphore.h
rct/Serializer.h
rct/Set.h
rct/SharedMemory.h
rct/SignalSlot.h
rct/Size.h
rct/SocketClient.h
rct/SocketServer.h
rct/StopWatch.h
rct/String.h
rct/Thread.h
rct/ThreadLocal.h
rct/ThreadPool.h
rct/Timer.h
rct/Value.h
rct/WriteLocker.h
DESTINATION include/rct)
install(EXPORT "rct" DESTINATION lib/cmake)
endif ()