-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
300 lines (235 loc) · 9.38 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
cmake_minimum_required(VERSION 2.8)
include(CheckCSourceCompiles)
include(CheckIncludeFile)
set(PROJ gitohashi)
project (gitohashi C)
#
# You can override where gitohashi gets its dependent library and includes
# from, at the cmake commandline. For libwebsockets, eg:
#
# cmake .. -DGOH_LWS_INC_PATH=/usr/local/include \
# -DGOH_LWS_LIB_PATH=/usr/local/lib/libwebsockets.so
#
# For git2, eg
#
# cmake .. -DJG2_GIT2_INC_PATH=/usr/local/include \
# -DJG2_GIT2_LIB_PATH=/usr/local/lib/libgit2.so
#
# and for libarchive, eg
#
# cmake .. -DJG2_ARCHIVE_INC_PATH=/usr/local/include \
#
# enable this if you want to run gitohashi from another lws application via
# its protocol plugins alone
#
option(GOH_LWS_PLUGINS "Also build lws protocol plugins" OFF)
option(GOH_WITH_ASAN "Build with libasan" OFF)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Gitohashi")
set(CPACK_PACKAGE_VENDOR "Andy Green <[email protected]>")
set(CPACK_PACKAGE_DESCRIPTION "Advanced gitweb based on libwebsockets")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "2")
set(CPACK_PACKAGE_VERSION_PATCH "99")
set(GOH_DEPLIBS jsongit2)
set(JG2_DEPLIBS pthread)
if (NOT GOH_LWS_LIB_PATH)
set(GOH_DEPLIB ${GOH_DEPLIBS} websockets)
set(JG2_DEPLIBS ${JG2_DEPLIBS} websockets)
endif()
#
# libgit2 paths
#
find_path( JG2_GIT2_INC_PATH NAMES "git2.h")
find_library(JG2_GIT2_LIB_PATH NAMES "git2")
if (JG2_GIT2_INC_PATH AND JG2_GIT2_LIB_PATH)
set(JG2_DEPLIBS ${JG2_GIT2_LIB_PATH} ${JG2_DEPLIBS})
include_directories(BEFORE "${JG2_GIT2_INC_PATH}")
else()
message(FATAL_ERROR " Unable to find libgit2")
endif()
#
# libarchive paths
#
find_path( JG2_ARCHIVE_INC_PATH NAMES "archive.h")
find_library(JG2_ARCHIVE_LIB_PATH NAMES "archive")
if (JG2_ARCHIVE_INC_PATH AND JG2_ARCHIVE_LIB_PATH)
set(JG2_DEPLIBS ${JG2_ARCHIVE_LIB_PATH} ${JG2_DEPLIBS})
include_directories(BEFORE "${JG2_ARCHIVE_INC_PATH}")
set(JG2_HAVE_ARCHIVE_H "Y")
endif()
find_package(Git)
if(GIT_EXECUTABLE)
execute_process(
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND "${GIT_EXECUTABLE}" describe --tags --always
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(LWS_BUILD_HASH ${GIT_HASH})
# append the build user and hostname
if (NOT LWS_REPRODUCIBLE)
execute_process(
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND "whoami"
OUTPUT_VARIABLE GIT_USER
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND "hostname"
OUTPUT_VARIABLE GIT_HOST
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX REPLACE "([^\\])[\\]([^\\])" "\\1\\\\\\\\\\2" GIT_USER ${GIT_USER})
set(LWS_BUILD_HASH ${GIT_USER}@${GIT_HOST}-${GIT_HASH})
endif()
message("Git commit hash: ${LWS_BUILD_HASH}")
endif()
set(CPACK_PACKAGE_VERSION_PATCH "${CPACK_PACKAGE_VERSION_PATCH_NUMBER}-${LWS_BUILD_HASH}")
#
# libwebsockets paths
#
find_path( GOH_LWS_INC_PATH NAMES "libwebsockets.h")
find_library(GOH_LWS_LIB_PATH NAMES "websockets")
if (GOH_LWS_INC_PATH AND GOH_LWS_LIB_PATH)
set(GOH_DEPLIBS ${GOH_LWS_LIB_PATH} ${GOH_DEPLIBS})
include_directories(BEFORE "${GOH_LWS_INC_PATH}")
else()
message(FATAL_ERROR " Unable to find libwebsockets")
endif()
unset(ASAN_LIBS)
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
include (CheckCCompilerFlag)
if (GOH_WITH_ASAN)
set(ASAN_FLAGS "-fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=leak -fsanitize=undefined -fsanitize-address-use-after-scope -fsanitize-undefined-trap-on-error")
set(ASAN_LIBS "asan")
message("Enabling ASAN")
endif()
set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS} ${ASAN_FLAGS}" )
endif()
set(CMAKE_REQUIRED_INCLUDES "include")
CHECK_C_SOURCE_COMPILES(
"#include <git2.h>
int main(int argc, char **argv) { return GIT_BLAME_USE_MAILMAP; }
" JG2_HAVE_BLAME_MAILMAP)
set(CMAKE_REQUIRED_FLAGS "-pthread")
CHECK_C_SOURCE_COMPILES("#define _GNU_SOURCE
#include <pthread.h>
void *dummy(void *arg) { pthread_exit(NULL); return NULL; }
int main(int argc, char *argv[]) {
pthread_t th;
if (pthread_create(&th, NULL, dummy, NULL))
pthread_setname_np(th, \"test\");
return 0;
}" JG2_HAS_PTHREAD_SETNAME_NP)
set(JG2_SOURCES lib/cache.c
lib/main.c
lib/repostate.c
lib/util.c
lib/job/job.c
lib/job/reflist.c
lib/job/log.c
lib/job/commit.c
lib/job/tree.c
lib/job/plain.c
lib/job/repos.c
lib/job/blame.c
lib/job/blog.c
lib/job/search.c
lib/conf/gitolite/gitolite3.c
lib/conf/gitolite/common.c
lib/conf/scan-repos.c
lib/email/md5.c
lib/email/email.c
)
if (JG2_HAVE_ARCHIVE_H)
set(JG2_SOURCES ${JG2_SOURCES} lib/job/snapshot.c)
set(JG2_DEPLIBS ${JG2_DEPLIBS} archive)
else()
set(JG2_SOURCES ${JG2_SOURCES} lib/job/no-snapshot.c)
endif()
configure_file("cmake/config.h.in" "${PROJECT_BINARY_DIR}/jg2-config.h")
add_library(jsongit2 SHARED ${JG2_SOURCES})
set(HDR_PUBLIC "include/libjsongit2.h" "${PROJECT_BINARY_DIR}/jg2-config.h")
set_target_properties(jsongit2 PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}")
target_include_directories(jsongit2 PRIVATE "${PROJECT_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}/include")
target_link_libraries(jsongit2 ${ASAN_LIBS} ${GOH_LWS_LIB_PATH} ${JG2_DEPLIBS})
set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
set(CPACK_COMPONENT_DEV_DISPLAY_NAME "Development files")
# jsongit2 examples
add_executable(jg2-example examples/minimal/jg2-example.c)
target_link_libraries(jg2-example ${ASAN_LIBS} ${GOH_LWS_LIB_PATH} jsongit2)
target_include_directories(jg2-example PRIVATE "${PROJECT_SOURCE_DIR}/include")
add_executable(jg2-threadchurn examples/threadchurn/threadchurn.c)
target_link_libraries(jg2-threadchurn ${ASAN_LIBS} ${GOH_LWS_LIB_PATH} jsongit2 pthread)
target_include_directories(jg2-threadchurn PRIVATE "${PROJECT_SOURCE_DIR}/include")
message("----------------------------- dependent libs -----------------------------")
message(" libgit2: include: ${JG2_GIT2_INC_PATH}, lib: ${JG2_GIT2_LIB_PATH}")
message(" libgit2: has GIT_BLAME_USE_MAILMAP: ${JG2_HAVE_BLAME_MAILMAP}")
if (NOT JG2_HAVE_ARCHIVE_H)
message(" libarchive: not found")
else()
message(" libarchive: include: ${JG2_ARCHIVE_INC_PATH}, lib: ${JG2_ARCHIVE_LIB_PATH}")
endif()
message(" libwebsockets: include: ${GOH_LWS_INC_PATH}, lib: ${GOH_LWS_LIB_PATH}")
message(" lws plugins: ${GOH_LWS_PLUGINS}")
set(LIB_DIR lib CACHE PATH "Install dir for libraries")
set(BIN_DIR bin CACHE PATH "Install dir for executables")
set(INCLUDE_DIR include CACHE PATH "Install dir for header files")
set(DATA_DIR share CACHE PATH "Install dir for data files")
install(TARGETS jsongit2
jg2-example
jg2-threadchurn
LIBRARY DESTINATION "${LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
ARCHIVE DESTINATION "${LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
RUNTIME DESTINATION "${BIN_DIR}" COMPONENT libraries
PUBLIC_HEADER DESTINATION "${INCLUDE_DIR}" COMPONENT dev)
install(FILES assets/github.css
assets/logo.css
assets/gitohashi-custom.css
assets/highlight.pack.js
assets/jg2.css
assets/jg2.js
assets/favicon.ico
assets/inconsolata.ttf
assets/showdown.min.js
assets/showdown.min.js.map
DESTINATION "${DATA_DIR}/gitohashi/assets")
install(FILES example-cert/localhost-100y.cert.pem
example-cert/localhost-100y.key.pem
DESTINATION "${DATA_DIR}/gitohashi/example-cert")
install(FILES templates/gitohashi-example.html
DESTINATION "${DATA_DIR}/gitohashi/templates")
install(FILES system/gitohashi-selinux.pp
DESTINATION "${DATA_DIR}/gitohashi")
install(FILES system/gitohashi.service
DESTINATION "${LIB_DIR}/systemd/system")
add_executable(${PROJ}
src/main.c
)
target_link_libraries(${PROJ} ${ASAN_LIBS} ${GOH_LWS_LIB_PATH} jsongit2)
target_include_directories(${PROJ} PRIVATE "${PROJECT_SOURCE_DIR}/include")
install(TARGETS ${PROJ} RUNTIME DESTINATION ${BIN_DIR})
if (GOH_LWS_PLUGINS)
add_library(protocol_gitohashi SHARED src/protocol_gitohashi.c)
target_link_libraries(protocol_gitohashi ${ASAN_LIBS} websockets jsongit2)
set_property(TARGET protocol_gitohashi
PROPERTY COMPILE_DEFINITIONS
INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/plugins"
)
list(APPEND PLUGINS_LIST protocol_gitohashi)
add_library(protocol_avatar_proxy SHARED src/protocol_avatar-proxy.c)
target_link_libraries(protocol_avatar_proxy ${ASAN_LIBS} websockets jsongit2)
set_property(TARGET protocol_avatar_proxy
PROPERTY COMPILE_DEFINITIONS
INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/plugins"
)
list(APPEND PLUGINS_LIST protocol_avatar_proxy)
install(TARGETS ${PLUGINS_LIST}
PERMISSIONS OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ
DESTINATION share/libwebsockets-test-server/plugins
COMPONENT plugins)
endif()
include(CPack)