-
Notifications
You must be signed in to change notification settings - Fork 64
/
CMakeLists.txt
191 lines (153 loc) · 5.59 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
cmake_minimum_required(VERSION 3.15)
project(luvi C)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
if (MSVC)
cmake_policy(SET CMP0091 NEW)
# Statically build against C runtime (use the right version for Release/Debug)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif ()
if (CMAKE_COMPILER_IS_GNUCC)
add_compile_options(-Wno-unused-function)
endif ()
if (MINGW)
add_compile_options(-Wno-error=incompatible-pointer-types)
endif ()
if (UNIX)
add_compile_options(-Wall)
endif ()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION")
file (STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" LUVI_VERSION)
message("-- Found luvi version: ${LUVI_VERSION}")
else ()
execute_process(
COMMAND git describe --tags
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE LUVI_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Handle shallow clones
if (LUVI_VERSION STREQUAL "")
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE LUVI_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(LUVI_VERSION "v0.0.0-0-g${LUVI_VERSION}")
endif ()
message("-- Found luvi git version: ${LUVI_VERSION}")
endif ()
option(WithSharedLibluv "Shared or Static libluv" OFF)
option(WithOpenSSL "Include OpenSSL" OFF)
option(WithOpenSSLASM "Enable Assembly Optimizations" ON)
option(WithSharedOpenSSL "Shared or Static OpenSSL" OFF)
option(WithPCRE2 "Include PCRE2" OFF)
option(WithSharedPCRE2 "Shared or Static PCRE2" OFF)
option(WithLPEG "Include LPEG" OFF)
option(WithSharedLPEG "Shared or Static LPEG" OFF)
option(WithZLIB "Include ZLIB" OFF)
option(WithSharedZLIB "Shared or Static ZLIB" OFF)
find_package(Threads)
set (LUVI_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
# When linking against a shared libluv, we assume that luajit and libuv are also shared
# Luvi does not support linking a static libluv *and* a static lua/luajit or libuv
if (WithSharedLibluv)
find_package(Luv REQUIRED)
include_directories(${LUV_INCLUDE_DIRS})
find_package(LuaJIT REQUIRED)
include_directories(${LUAJIT_INCLUDE_DIRS})
find_package(Libuv REQUIRED)
include_directories(${LIBUV_INCLUDE_DIRS})
include(CheckCSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${LUAJIT_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${LUAJIT_LIBRARIES})
check_c_source_compiles("
#include <luajit.h>
int main() {
LUAJIT_VERSION_SYM();
return 0;
}" LUAJIT_HAS_VERSION_SYM)
if (NOT LUAJIT_HAS_VERSION_SYM)
add_compile_definitions(LUAJIT_MISSING_VERSION_SYM)
endif ()
list(APPEND LUVI_LIBRARIES ${LUV_LIBRARIES} ${LUAJIT_LIBRARIES} ${LIBUV_LIBRARIES})
else (WithSharedLibluv)
# Build luv as static library instead of as module
set(BUILD_MODULE OFF CACHE BOOL "Turn off building luv as module")
set(BUILD_STATIC_LIBS ON CACHE BOOL "Build luv as static lib")
include_directories(deps/luv/src)
include_directories(deps/luv/deps/libuv/include)
if (WITH_LUA_ENGINE STREQUAL Lua)
include_directories(deps/luv/deps/lua)
list(APPEND LUVI_LIBRARIES lualib)
else ()
include_directories(deps/luv/deps/luajit/src)
list(APPEND LUVI_LIBRARIES luajit-5.1)
set(luajit_vmdef ${CMAKE_CURRENT_BINARY_DIR}/deps/luv/vmdef.lua)
set_source_files_properties(${luajit_vmdef} PROPERTIES GENERATED TRUE)
list(APPEND LUVI_DEFINITIONS WITH_LJ_VMDEF)
endif ()
list(APPEND LUVI_LIBRARIES libluv_a uv_a)
add_subdirectory(deps/luv) # Build luv
endif (WithSharedLibluv)
set(LUA_COMPAT53_DIR "${CMAKE_CURRENT_SOURCE_DIR}/deps/luv/deps/lua-compat-5.3" CACHE PATH "Path to lua-compat-5.3")
include_directories(${LUA_COMPAT53_DIR})
include_directories(${LUA_COMPAT53_DIR}/c-api)
if (WithOpenSSL)
include(deps/lua-openssl.cmake)
endif ()
if (WithPCRE2)
include(deps/lrexlib.cmake)
endif ()
if (WithLPEG)
include(deps/lpeg.cmake)
set(lpeg_re_lua ${LPEGLIB_DIR}/re.lua)
endif ()
if (WithZLIB)
include(deps/lua-zlib.cmake)
endif ()
if (WIN32)
set(winsvc src/winsvc.h src/winsvcaux.h src/winsvc.c src/winsvcaux.c)
if (WithSharedLibluv)
add_definitions( -DLUA_BUILD_AS_DLL -DBUILDING_UV_SHARED )
endif ()
add_definitions( -DWITH_WINSVC )
add_definitions( -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS )
add_library (luvi_renamed src/luvi_renamed.c)
endif ()
if (WITH_LUA_ENGINE STREQUAL Lua)
add_definitions(-DWITH_PLAIN_LUA)
endif ()
include(LuaAddExecutable)
# TODO: define MINIZ_NO_STDIO for small size
add_subdirectory(deps/miniz miniz.dir)
set(lminiz src/lminiz.c)
include_directories(deps/miniz)
list(APPEND LUVI_LIBRARIES miniz)
lua_add_executable(luvi
${winsvc}
${lminiz}
src/main.c
src/luvi_compat.c
src/lua/init.lua
src/lua/luvipath.lua
src/lua/luvibundle.lua
${luajit_vmdef}
${lpeg_re_lua}
)
if (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-E")
endif ()
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(list APPEND LUVI_LIBRARIES rt)
endif ()
target_link_libraries(luvi ${LUVI_LIBRARIES} ${EXTRA_LIBS})
set_target_properties(luvi PROPERTIES ENABLE_EXPORTS ON)
target_compile_definitions(luvi PRIVATE LUVI_VERSION="${LUVI_VERSION}")
target_compile_definitions(luvi PRIVATE ${LUVI_DEFINITIONS}) # Add any extra definitions, like the WITH_{LIB} defines
message("Configuration Summary:")
message(" LUVI_VERSION: ${LUVI_VERSION}")
message(" LUVI_DEFINITIONS: ${LUVI_DEFINITIONS}")
message(" LUVI_LIBRARIES: ${LUVI_LIBRARIES}")
###############################################################################
## Installation Targets
###############################################################################
install(TARGETS luvi DESTINATION bin)