-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
220 lines (179 loc) · 6.01 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
project(nginx)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_VERBOSE_MAKEFILE true)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} $ENV{EXTRA_CMAKE_MODULES_DIRS})
set(JOBS 2 CACHE STRING "Set the make -j argument")
message(STATUS "number of jobs: " ${JOBS})
# dependencies
find_package(Perl)
if (NOT PERL_FOUND)
message(FATAL "Perl not found.")
else()
find_program(PROVE_EXECUTABLE NAMES prove DOC "Perl test runner")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Prove DEFAULT_MSG PROVE_EXECUTABLE)
endif()
find_package(izenelib REQUIRED COMPONENTS sf1r)
if (NOT izenelib_FOUND)
message(FATAL "izenelib not found.")
else()
foreach(include ${izenelib_INCLUDE_DIRS})
list(APPEND SF1R_INCLUDES ${include})
endforeach()
string(REPLACE "/libsf1r.so" " " lib ${izenelib_sf1r_LIBRARY})
list(APPEND SF1R_LIBRARIES "-L${lib} -lsf1r")
endif()
set(Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0")
find_package(Boost 1.47.0 REQUIRED COMPONENTS system thread)
if(NOT Boost_FOUND)
message(FATAL "Boost.system not found.")
else()
foreach(include ${Boost_INCLUDE_DIRS})
list(APPEND SF1R_INCLUDES ${include})
endforeach()
foreach(library ${Boost_LIBRARIES})
list(APPEND SF1R_LIBRARIES ${library})
endforeach()
endif()
find_package(Glog)
if(NOT Glog_FOUND)
message(FATAL "Boost.system not found.")
else()
foreach(include ${Glog_INCLUDE_DIRS})
list(APPEND SF1R_INCLUDES ${include})
endforeach()
list(APPEND SF1R_LIBRARIES ${Glog_LIBRARIES})
endif()
list(REMOVE_DUPLICATES SF1R_INCLUDES)
# nginx source dir
set(NGINX_SRC tengine)
# Test::Nginx path
set(TEST_NGINX_PATH ${nginx_SOURCE_DIR}/test-nginx)
# out of source build
set(BUILD_DIR ${nginx_BINARY_DIR}/${NGINX_SRC})
list(APPEND CONFIGURE_ARGS "--builddir=${BUILD_DIR}")
# syslog
option(WITH_SYSLOG "enable logging via syslog and pipe" true)
if(WITH_SYSLOG)
list(APPEND CONFIGURE_ARGS "--with-syslog")
endif()
# debugging log
option(WITH_NGINX_DEBUG "enable the debug logging" false)
if(WITH_NGINX_DEBUG)
list(APPEND CONFIGURE_ARGS "--with-debug")
endif()
option(WITH_DEBUG "enable the debug logging" false)
if(WITH_DEBUG)
list(APPEND CONFIGURE_ARGS "--with-cc-opt=-DSDEBUG")
endif()
# nginx configuration options
option(WITH_STATUS "enable the http_stub_status_module" false)
if(WITH_STATUS)
list(APPEND CONFIGURE_ARGS "--with-http_stub_status_module")
endif()
# extra modules source dirs
set(ECHO_MODULE agentzh-echo-nginx-module-df58882)
set(HEADERS_MORE_MODULE agentzh-headers-more-nginx-module-de77fd2)
set(HELLO_MODULE nginx-hello-module)
set(SF1R_MODULE sf1r-module)
set(FLUENTD_MODULE nginx-fluentd-module)
set(TFS_MODULE ngx_http_tfs_module)
list(APPEND MODULE_DIRS
${ECHO_MODULE}
${HEADERS_MORE_MODULE}
${HELLO_MODULE}
${SF1R_MODULE}
${FLUENTD_MODULE}
)
# TFS module requires tfsclient
find_package(tfsclient)
if(tfsclient_FOUND)
message("===========TFS client found ==============")
find_package(ImageMagick COMPONENTS Magick++ REQUIRED)
if(NOT ImageMagick_FOUND)
message(FATAL "ImageMagick not found")
else()
foreach(include ${ImageMagick_INCLUDE_DIRS})
list(APPEND SF1R_INCLUDES ${include})
endforeach()
foreach(library ${ImageMagick_LIBRARIES})
list(APPEND SF1R_LIBRARIES ${library})
endforeach()
endif()
list(APPEND MODULE_DIRS ${TFS_MODULE})
endif(tfsclient_FOUND)
# sf1r config
foreach(include ${SF1R_INCLUDES})
set(sf1r_INCS "${sf1r_INCS} ${include}")
endforeach()
message(STATUS "include dirs: ${sf1r_INCS}")
foreach(lib ${SF1R_LIBRARIES})
set(sf1r_LIBS "${sf1r_LIBS} ${lib}")
endforeach()
message(STATUS "libraries: ${sf1r_LIBS}")
configure_file(${nginx_SOURCE_DIR}/${SF1R_MODULE}/config.in
${nginx_SOURCE_DIR}/${SF1R_MODULE}/config)
# modules summary
if (MODULE_DIRS)
message(STATUS "added modules:")
foreach(module ${MODULE_DIRS})
set(module_dir ${nginx_SOURCE_DIR}/${module})
set(module_conf ${module_dir}/config)
list(APPEND CONFIGURE_ARGS "--add-module=${module_dir}")
list(APPEND CONFIGURE_DEPS ${module_conf})
message("\t${module}")
endforeach()
endif()
# config summary
message(STATUS "configure arguments: ")
foreach(arg ${CONFIGURE_ARGS})
message("\t${arg}")
endforeach()
# configure script
add_custom_command(
OUTPUT ${BUILD_DIR}/Makefile
DEPENDS ${CONFIGURE_DEPS}
COMMAND ./configure ARGS ${CONFIGURE_ARGS}
WORKING_DIRECTORY ${nginx_SOURCE_DIR}/${NGINX_SRC}
COMMENT "configure nginx"
VERBATIM)
# make target
add_custom_target(nginx ALL
COMMAND make -j ${JOBS}
DEPENDS ${BUILD_DIR}/Makefile
WORKING_DIRECTORY ${nginx_SOURCE_DIR}/${NGINX_SRC}
COMMENT "build nginx"
VERBATIM)
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${BUILD_DIR})
# tests
enable_testing()
set(MODULE_TEST ${HELLO_MODULE} ${SF1R_MODULE} syslog)
if (MODULE_TEST)
add_custom_target(test)
message(STATUS "adding tests for modules:")
foreach(module ${MODULE_TEST})
set(module_dir ${nginx_SOURCE_DIR}/${module})
file(GLOB test_files RELATIVE ${module_dir}/t/ ${module_dir}/t/*.t)
list(LENGTH test_files count)
message("\t${module} (${count} tests found)")
foreach(test_file ${test_files})
#message("\t* found test: ${module}/${test_file}")
add_test(NAME ${module}/${test_file}
COMMAND ${CMAKE_COMMAND}
-DNAME=${module}
-DPROVE=${PROVE_EXECUTABLE}
-DDIR=${module_dir}
-DLIB=${TEST_NGINX_PATH}/lib
-DINC=${TEST_NGINX_PATH}/inc
-DNGINX=${BUILD_DIR}/nginx
-DFILE=t/${test_file}
-P ${nginx_SOURCE_DIR}/test.cmake)
endforeach()
endforeach()
endif()
# install target
add_custom_target(install
make install
WORKING_DIRECTORY ${nginx_SOURCE_DIR}/${NGINX_SRC}
COMMENT "installing nginx")
add_dependencies(install nginx)