-
Notifications
You must be signed in to change notification settings - Fork 29
/
CMakeLists.txt
197 lines (166 loc) · 5.74 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
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(cartridge C)
set(PYTHON3_EXECUTABLE "python3")
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY TRUE)
# Find Tarantool and Lua dependencies
set(TARANTOOL_FIND_REQUIRED ON)
find_package(Tarantool)
include_directories(${TARANTOOL_INCLUDE_DIRS})
get_filename_component(WEB_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/webui" ABSOLUTE)
file(GLOB_RECURSE FRONTEND_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/webui/src/*.js"
"${CMAKE_CURRENT_SOURCE_DIR}/webui/src/*.jsx"
"${CMAKE_CURRENT_SOURCE_DIR}/webui/src/*.ts"
"${CMAKE_CURRENT_SOURCE_DIR}/webui/src/*.tsx"
"${CMAKE_CURRENT_SOURCE_DIR}/webui/src/*.svg"
"${CMAKE_CURRENT_SOURCE_DIR}/webui/src/*.css"
)
file(GLOB_RECURSE LUA_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/cartridge.lua"
"${CMAKE_CURRENT_SOURCE_DIR}/cartridge/*.lua"
)
file(GLOB_RECURSE DOC_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/rst/*"
)
## Webui ######################################################################
###############################################################################
add_custom_command(
OUTPUT "${WEB_ROOT}/build/always-run-script"
COMMAND ${CMAKE_COMMAND} -P ${WEB_ROOT}/BuildFrontend.cmake
COMMENT "Building WebUI"
)
if(DEFINED ENV{CMAKE_DUMMY_WEBUI})
set(DUMMY_WEBUI "$ENV{CMAKE_DUMMY_WEBUI}")
endif()
if(DUMMY_WEBUI)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/front-bundle.fake.lua"
"return {__data = function() return {} end}\n"
)
add_custom_target(front-bundle ALL
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_BINARY_DIR}/front-bundle.fake.lua"
"${CMAKE_CURRENT_BINARY_DIR}/front-bundle.lua"
COMMENT "Generating fake front-bundle.lua"
VERBATIM
)
else()
add_custom_target(front-bundle ALL
DEPENDS "${WEB_ROOT}/build/always-run-script"
COMMAND ${CMAKE_COMMAND} -E copy
"${WEB_ROOT}/build/bundle.lua"
"${CMAKE_CURRENT_BINARY_DIR}/front-bundle.lua"
COMMENT "Copying real front-bundle.lua"
VERBATIM
)
endif()
## API doc ####################################################################
###############################################################################
set(DOC_OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/doc)
if(DEFINED ENV{CMAKE_LDOC_FIND_REQUIRED})
set(Ldoc_FIND_REQUIRED "$ENV{CMAKE_LDOC_FIND_REQUIRED}")
endif()
find_package(Ldoc)
if(DEFINED ENV{CMAKE_SPHINX_FIND_REQUIRED})
set(Sphinx_FIND_REQUIRED "$ENV{CMAKE_SPHINX_FIND_REQUIRED}")
endif()
find_package(Sphinx)
add_custom_command(
OUTPUT ${DOC_OUTPUT}/index.html
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/rst
${CMAKE_CURRENT_BINARY_DIR}/build.rst
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/README.rst
${CMAKE_CURRENT_BINARY_DIR}/build.rst/README.rst
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/CONTRIBUTING.rst
${CMAKE_CURRENT_BINARY_DIR}/build.rst/CONTRIBUTING.rst
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.rst
${CMAKE_CURRENT_BINARY_DIR}/build.rst/CHANGELOG.rst
COMMAND ${LDOC} --all .
--ext rst
--dir "${CMAKE_CURRENT_BINARY_DIR}/build.rst/cartridge_api"
COMMAND ${SPHINX}
"${CMAKE_CURRENT_BINARY_DIR}/build.rst"
"${DOC_OUTPUT}"
-d "${CMAKE_CURRENT_BINARY_DIR}/.doctrees"
-b html
DEPENDS ${DOC_FILES} ${LUA_FILES}
COMMENT "Building API documentation"
VERBATIM
)
add_custom_target(update-pot
COMMAND "${SPHINX}"
"${CMAKE_CURRENT_BINARY_DIR}/rst"
"${CMAKE_CURRENT_BINARY_DIR}/rst/locale/en/"
-c rst/
-d "${CMAKE_CURRENT_BINARY_DIR}/.doctrees"
-b gettext
COMMENT "Generate localization templates"
)
add_custom_target(update-po
COMMAND "sphinx-intl"
update
-p "${CMAKE_CURRENT_BINARY_DIR}/rst/locale/en/"
-d "${CMAKE_CURRENT_BINARY_DIR}/rst/locale/"
-l "ru"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Regenerate localization files from templates"
)
add_custom_target(cleanup-po
COMMAND "${PYTHON3_EXECUTABLE}"
cleanup.py
po
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/rst/locale
COMMENT "Cleanup and rearrange PO files"
)
if(Ldoc_FOUND AND Sphinx_FOUND)
add_custom_target(doc ALL
DEPENDS "${DOC_OUTPUT}/index.html")
else()
add_custom_target(doc
DEPENDS "${DOC_OUTPUT}/index.html")
endif()
## GraphQL schema #############################################################
###############################################################################
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/doc/schema.graphql
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/fetch-schema.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${LUA_FILES}
COMMENT "Fetching GraphQL schema"
)
add_custom_target(schema
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/doc/schema.graphql
)
## Testing ####################################################################
###############################################################################
enable_testing()
add_test(
NAME lint
COMMAND luacheck .
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
## Install ####################################################################
###############################################################################
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}
DESTINATION ${TARANTOOL_INSTALL_LUADIR}
)
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/cartridge.lua
DESTINATION ${TARANTOOL_INSTALL_LUADIR}
)
install(
PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/stateboard.init.lua
DESTINATION ${TARANTOOL_INSTALL_BINDIR}
RENAME stateboard
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/front-bundle.lua
DESTINATION ${TARANTOOL_INSTALL_LUADIR}/${PROJECT_NAME}/
)