-
Notifications
You must be signed in to change notification settings - Fork 39
/
CMakeLists.txt
159 lines (145 loc) · 4.8 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
PROJECT(LuaNode C CXX)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
IF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
MESSAGE(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt. ")
ENDIF()
FIND_PACKAGE( Lua51 REQUIRED )
FIND_PACKAGE( OpenSSL REQUIRED )
FIND_PACKAGE( Threads REQUIRED )
SET( BOOST_MIN_VERSION "1.44.0" )
# We want to statically link the multithreaded versions. And we don't want Boost auto-link feature
# since it doesn't play nice with CMake
SET( Boost_USE_STATIC_LIBS ON )
SET( Boost_USE_MULTITHREADED ON )
SET( Boost_USE_STATIC_RUNTIME OFF )
ADD_DEFINITIONS( -DBOOST_ALL_NO_LIB )
# boost::thread since version 1.50 relies on boost::chrono
# So check which Boost version is available and look for the required libs
FIND_PACKAGE( Boost )
SET( local_boost_version "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}" )
IF (${local_boost_version} VERSION_GREATER "1.49")
FIND_PACKAGE( Boost ${BOOST_MIN_VERSION} COMPONENTS system date_time thread chrono REQUIRED )
ELSE()
FIND_PACKAGE( Boost ${BOOST_MIN_VERSION} COMPONENTS system date_time thread REQUIRED )
ENDIF()
FIND_PROGRAM(LUA NAMES lua-5.1 lua5.1 lua)
IF(WIN32)
# Windows specific code
ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS )
ADD_DEFINITIONS( -D_WIN32_WINNT=0x0501 )
SET(OS
src/luanode_file_win32.cpp
src/platform_windows.cpp
src/luanode_stdio_win32.cpp
src/detail/windows/input_tty.cpp
src/detail/windows/output_tty.cpp
src/detail/windows/windows_tty.cpp
)
ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "BSD")
# BSD specific code
FIND_LIBRARY(KVM_LIBRARIES NAMES kvm)
SET(OS
src/luanode_file_linux.cpp
src/platform_bsd.cpp
src/luanode_stdio_linux.cpp
src/luanode_posix_stream.cpp
src/detail/posix/tty_stream.cpp
)
ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# Mac OS X specific code
SET(OS
src/luanode_file_linux.cpp
src/platform_darwin.cpp
src/luanode_stdio_linux.cpp
src/luanode_posix_stream.cpp
src/detail/posix/tty_stream.cpp
)
ELSE()
# Linux specific code
SET(OS
src/luanode_file_linux.cpp
src/platform_linux.cpp
src/luanode_stdio_linux.cpp
src/luanode_posix_stream.cpp
src/detail/posix/tty_stream.cpp
)
ENDIF()
SET(LUAS
lib/luanode/child_process
lib/luanode/class
lib/luanode/console
lib/luanode/crypto
lib/luanode/datagram
lib/luanode/dns
lib/luanode/event_emitter
lib/luanode/free_list
lib/luanode/fs
lib/luanode/introspect
lib/luanode/http
lib/luanode/net
lib/luanode/path
lib/luanode/querystring
lib/luanode/readline
lib/luanode/repl
lib/luanode/script
lib/luanode/stream
lib/luanode/timers
lib/luanode/tty
lib/luanode/url
lib/luanode/utils
lib/luanode/__private_luastate
lib/luanode/__private_traverse
lib/luanode/__private_url
${LUA_OS}
src/node
deps/stacktraceplus/src/StackTracePlus
)
SET(SRC ${CMAKE_SOURCE_DIR})
SET(DST ${CMAKE_SOURCE_DIR}/build/temp)
# Create a temp directory to store Lua .precomp files
FILE(MAKE_DIRECTORY ${DST})
ADD_DEFINITIONS( -D_SOURCE_PATH=\"${CMAKE_SOURCE_DIR}\" )
FILE(WRITE ${DST}/${target}/build_path.precomp \"${SRC}\")
FOREACH(filename ${LUAS})
GET_FILENAME_COMPONENT(base ${filename} NAME)
SET(target "${DST}/${base}.precomp")
MESSAGE(STATUS "Precompiling ${filename} into ${target}")
EXECUTE_PROCESS(COMMAND ${LUA} ${SRC}/tools/bin2c.lua ${SRC}/${filename}.lua extension_status OUTPUT_FILE ${target} RESULT_VARIABLE res)
IF(NOT ${res} EQUAL 0)
MESSAGE(FATAL_ERROR "Error while precompiling Lua file. ${SRC}/${filename}.lua" )
ENDIF()
ENDFOREACH(filename)
SET(SOURCES
src/blogger.cpp
src/luanode.cpp
src/luanode_child_process.cpp
src/luanode_constants.cpp
src/luanode_crypto.cpp
src/luanode_dns.cpp
src/luanode_datagram_udp.cpp
src/luanode_hrtime.cpp
src/luanode_http_parser.cpp
src/luanode_module_api.cpp
src/luanode_net.cpp
src/luanode_net_acceptor.cpp
src/luanode_timer.cpp
src/luanode_os.cpp
src/lua_vm.cpp
${OS}
lib/preloader.cpp
deps/http-parser/http_parser.c
)
INCLUDE_DIRECTORIES(src ${LUA_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${DST})
ADD_EXECUTABLE(luanode ${SOURCES})
TARGET_LINK_LIBRARIES(luanode ${LUA_LIBRARIES} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
IF(WIN32)
# Windows specific code
ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "BSD")
# BSD specific code
TARGET_LINK_LIBRARIES(luanode ${KVM_LIBRARIES} rt)
ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# Mac OS X specific code
ELSE()
# Linux specific code
TARGET_LINK_LIBRARIES(luanode rt)
ENDIF()