This repository was archived by the owner on Mar 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
executable file
·280 lines (220 loc) · 7.56 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
#
# Copyright 2013 Produban
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
cmake_minimum_required (VERSION 2.6)
project (log2kafka)
#
# Options
#
option (USE_LOG4CXX "Use apache log4cxx library" OFF)
option (KAFKA_LINK_STATIC "For static linking of kafka library" OFF)
option (AVRO_LINK_STATIC "For static linking of avro library" OFF)
option (BUILD_DOC "Create and install the API documentation (requires Doxygen)" OFF)
#
# Global configuration
#
set (TARGET_VERSION_MAJOR 1)
set (TARGET_VERSION_MINOR 0)
set (TARGET_VERSION "${TARGET_VERSION_MAJOR}.${TARGET_VERSION_MINOR}")
set (${CMAKE_PROJECT_NAME}_VERSION "${TARGET_VERSION}")
if (WIN32 AND NOT CYGWIN AND NOT MSYS)
add_definitions (/EHa)
add_definitions (
-DBOOST_REGEX_DYN_LINK
-DBOOST_FILESYSTEM_DYN_LINK
-DBOOST_SYSTEM_DYN_LINK
-DBOOST_PROGRAM_OPTIONS_DYN_LINK
-DBOOST_ALL_NO_LIB)
endif ()
# GCC specifics
if (CMAKE_COMPILER_IS_GNUCXX)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++0x")
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -ggdb")
set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -Os -DNDEBUG")
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O4 -DNDEBUG")
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 -g")
# Visual Studio specifics
elseif (MSVC)
# Warning Level 4 for Debug builds
list(APPEND CMAKE_CXX_FLAGS_DEBUG " /W4")
list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS_DEBUG)
endif ()
set (CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "/usr/local")
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
#
# Find Threads package
#
if (NOT WIN32 AND NOT CYGWIN AND NOT MSYS)
message ("\nLooking for thread headers and libraries")
find_package (Threads)
if (Threads_FOUND)
set (LIBS
${LIBS}
${CMAKE_THREAD_LIBS_INIT}
)
endif ()
endif ()
#
# Find Boost
#
message ("\nLooking for Boost headers and libraries")
find_package (Boost 1.40 COMPONENTS filesystem system program_options REQUIRED)
add_definitions (${Boost_LIB_DIAGNOSTIC_DEFINITIONS})
include_directories (${Boost_INCLUDE_DIRS})
message (STATUS "Include directories: ${Boost_INCLUDE_DIR}")
message (STATUS "Libraries: ${Boost_LIBRARIES}")
#
# Find ZLib
#
message ("\nLooking for ZLib codec headers and libraries")
find_package(ZLIB REQUIRED)
message (STATUS "Include directories: ${ZLIB_INCLUDE_DIRS}")
message (STATUS "Libraries: ${ZLIB_LIBRARIES}")
if (ZLIB_FOUND)
set (ZLIB_PKG zlib)
add_definitions (-DDEFLATE_CODEC)
endif ()
#
# Find Logging
#
if (USE_LOG4CXX)
add_definitions (-D_LOG2KAFKA_USE_LOG4CXX_)
find_package (ApachePortableRuntime REQUIRED)
find_package (Log4CXX REQUIRED)
include_directories (${APR_INCLUDE_DIRS} ${LOG4CXX_INCLUDE_DIRS})
endif ()
# Find Snappy
# message ("\nLooking for Snappy codec headers and libraries")
# find_package(Snappy)
# if (SNAPPY_FOUND AND ZLIB_FOUND) # Snappy borrows crc32 from zlib
# set (SNAPPY_PKG libsnappy)
# add_definitions (-DSNAPPY_CODEC)
# include_directories (${SNAPPY_INCLUDE_DIRS})
# message (STATUS "** Enabled snappy codec **")
# else ()
# set (SNAPPY_PKG "")
# set (SNAPPY_LIBRARIES "")
# message (STATUS "** Disabled snappy codec. libsnappy not found or zlib not found. **")
# endif ()
#
# Find Kafka
#
find_package (KafkaC REQUIRED)
if (KAFKA_LINK_STATIC)
message (STATUS "Forced static linking of kafka library")
add_library (kafka STATIC IMPORTED)
else ()
include_directories (${KAFKA_INCLUDE_DIRS})
add_library (kafka UNKNOWN IMPORTED)
endif ()
set_property (TARGET kafka PROPERTY IMPORTED_LOCATION ${KAFKA_LIBRARIES})
#
# Find Avro
#
find_package (AvroCPP REQUIRED)
if (AVRO_LINK_STATIC)
message (STATUS "Forced static linking of avro library")
add_library (avro STATIC IMPORTED)
else ()
include_directories (${AVRO_INCLUDE_DIRS})
add_library (avro UNKNOWN IMPORTED)
endif ()
set_property (TARGET avro PROPERTY IMPORTED_LOCATION ${AVRO_LIBRARIES})
include_directories (
${ZLIB_INCLUDE_DIRS}
${PROJECT_BINARY_DIR}
)
set (LIBS
${LIBS}
kafka
avro
${LOG4CXX_LIBRARIES}
${APR_LIBRARIES}
${Boost_LIBRARIES}
${ZLIB_LIBRARIES}
)
include (InstallRequiredSystemLibraries)
add_subdirectory (src)
# file (GLOB log4cxx-lib "${LOG4CXX_LIBRARY_DIR}/${LOG4CXX_LIBRARY_NAME}.*")
# install(
# FILES
# ${log4cxx-lib}
# DESTINATION
# ${CMAKE_PREFIX_PATH}/lib
# )
# install(
# DIRECTORY
# ${LOG4CXX_INCLUDE_DIRS}
# DESTINATION
# ${CMAKE_PREFIX_PATH}/include
# )
#
# Documentation settings
#
if (BUILD_DOC)
message ("\nConfigure documentation generation")
find_package(Doxygen)
if (NOT DOXYGEN_FOUND)
message (FATAL_ERROR "Doxygen is needed to build the documentation.")
endif ()
set (DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in )
set (DOXYFILE ${PROJECT_BINARY_DIR}/Doxyfile )
set (DOXY_HTML_INDEX_FILE ${CMAKE_CURRENT_BINARY_DIR}/doc/html/index.html)
set (DOXY_OUTPUT_ROOT ${CMAKE_CURRENT_BINARY_DIR} ) # Pasted into Doxyfile.in
set (DOXY_INPUT ${PROJECT_SOURCE_DIR}/src ) # Pasted into Doxyfile.in
set (DOXY_EXTRA_FILES ${CMAKE_CURRENT_SOURCE_DIR}/mainpage.dox ) # Pasted into Doxyfile.in
configure_file (${DOXYFILE_IN} ${DOXYFILE} @ONLY)
add_custom_command (OUTPUT ${DOXY_HTML_INDEX_FILE}
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE}
# The following should be ${DOXYFILE} only but it
# will break the dependency.
# The optimal solution would be creating a
# custom_command for ${DOXYFILE} generation
# but I still have to figure out how...
MAIN_DEPENDENCY ${DOXYFILE} ${DOXYFILE_IN}
DEPENDS ${CMAKE_PROJECT_NAME} # ${DOXY_EXTRA_FILES}
COMMENT "Generating HTML documentation")
add_custom_target (doc ALL DEPENDS ${DOXY_HTML_INDEX_FILE})
install (
DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/doc/html
DESTINATION
share/doc/${CMAKE_PROJECT_NAME}-${TARGET_VERSION}
)
endif ()
#
# Package settings
#
message ("\nConfigure packaging")
set (CPACK_SET_DESTDIR ON)
set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
#set (CPACK_PACKAGING_INSTALL_PREFIX "")
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CMAKE_PROJECT_NAME} - Log to Kafka Producer")
set (CPACK_PACKAGE_VENDOR "Produban")
set (CPACK_PACKAGE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/dist")
set (CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set (CPACK_PACKAGE_VERSION_MAJOR "1")
set (CPACK_PACKAGE_VERSION_MINOR "0")
set (CPACK_PACKAGE_VERSION_PATCH "0")
set (CPACK_PACKAGE_INSTALL_DIRECTORY "/")
set (CPACK_PACKAGE_EXECUTABLES "${CMAKE_PROJECT_NAME}" "${CMAKE_PROJECT_NAME}")
#set (CPACK_STRIP_FILES "bin/${CMAKE_PROJECT_NAME}")
#set (CPACK_SOURCE_STRIP_FILES "")
if (CYGWIN)
set (CPACK_CYGWIN_PATCH_NUMBER "0")
endif ()
include (CPack)