remove wrong! string terminator detection
[metze/wireshark/wip.git] / CMakeLists.txt
1 # CMakeLists.txt
2 #
3 # $Id$
4 #
5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
7 # Copyright 1998 Gerald Combs
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 #
23
24
25 project(wireshark C)
26
27 cmake_minimum_required(VERSION 2.6)
28
29 subdirs(
30   wiretap
31   wsutil
32 )
33
34 #Where to find local cmake scripts
35 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
36
37 # Under linux the release mode (CMAKE_BUILD_TYPE=release) defines NDEBUG
38
39 # Disable this later. Alternative: "make VERBOSE=1"
40 set(CMAKE_VERBOSE_MAKEFILE ON)
41
42 set(BUILD_SHARED_LIBS ON)
43
44 #Defines CMAKE_INSTALL_BINDIR, CMAKE_INSTALL_DATADIR, etc ... 
45 include(CMakeInstallDirs)
46
47 include_directories(
48   ${CMAKE_BINARY_DIR}
49   ${CMAKE_SOURCE_DIR}
50   ${CMAKE_SOURCE_DIR}/include
51   ${CMAKE_SOURCE_DIR}/wiretap
52   ${CMAKE_SOURCE_DIR}/wsutil
53 )
54
55 #Where to put libraries
56 if(NOT LIBRARY_OUTPUT_PATH)
57   set(LIBRARY_OUTPUT_PATH ${wireshark_BINARY_DIR}/lib CACHE INTERNAL
58        "Single output directory for building all libraries.")
59 endif(NOT LIBRARY_OUTPUT_PATH)
60
61 option(BUILD_WIRESHARK   "Build the GUI version of Wireshark" ON)
62 option(BUILD_TSHARK      "Build tshark" ON)
63 option(BUILD_RAWSHARK    "Build rawshark" ON)
64 option(BUILD_dumpcap     "Build dumpcap" ON)
65 option(BUILD_text2pcap   "Build text2pcap" ON)
66 option(BUILD_mergecap    "Build mergecap" ON)
67 option(BUILD_editcap     "Build editcap" ON)
68 option(BUILD_capinfos    "Build capinfos" ON)
69 option(BUILD_dftest      "Build dftest" ON)
70 option(ENABLE_STATIC     "Build a static version of Wireshark" OFF)
71 option(ENABLE_ADNS       "Build with adns support" ON)
72 option(ENABLE_EXTRA_GCC_CHECKS "Do additional -W checks in GCC" OFF)
73
74 if(ENABLE_EXTRA_GCC_CHECKS)
75   set(WIRESHARK_EXTRA_GCC_FLAGS -Wcast-qual -Wcast-align -Wbad-function-cast
76       -pedantic -Wstrict-prototypes -Wmissing-declarations -Wwrite-strings)
77 endif(ENABLE_EXTRA_GCC_CHECKS)
78
79 if(CMAKE_COMPILER_IS_GNUCC)
80   add_definitions(
81     -DHAVE_CONFIG_H
82     -D_U_=__attribute__\(\(unused\)\)
83     -Wall -Wpointer-arith -W
84     ${WIRESHARK_EXTRA_GCC_FLAGS}
85   )
86 else(CMAKE_COMPILER_IS_GNUCC)
87   add_definitions(-DHAVE_CONFIG_H -D_U_=\"\")
88 endif(CMAKE_COMPILER_IS_GNUCC)
89
90 #The minimum package list
91 set(PACKAGELIST GLIB2 ZLIB PCAP LEX YACC Perl ${PACKAGELIST})
92
93 #build the gui ?
94 if(BUILD_WIRESHARK)
95   set(PACKAGELIST GTK2 ${PACKAGELIST})
96 endif(BUILD_WIRESHARK)
97
98 #Gnu asynchronous dns
99 if(ENABLE_ADNS)
100   set(PACKAGELIST ADNS ${PACKAGELIST})
101   set(HAVE_GNU_ADNS 1)
102 endif(ENABLE_ADNS)
103
104 set(PROGLIST text2pcap mergecap capinfos editcap dumpcap)
105
106 #Let's loop the package list 
107 foreach(PACKAGE ${PACKAGELIST})
108   find_package(${PACKAGE} REQUIRED)
109   message(${PACKAGE}_FOUND)
110   if (${PACKAGE}_FOUND)
111     set(HAVE_LIB${PACKAGE} "1")
112     include_directories(${${PACKAGE}_INCLUDE_DIRS})
113     message(STATUS "${PACKAGE} include ${${PACKAGE}_INCLUDE_DIRS}")
114     foreach(PROG ${PROGLIST})
115 #      set(${PROG}_LIBS ${${PROG}_LIBS} ${${PACKAGE}_LIBRARIES})
116     endforeach(PROG)
117     message(STATUS "${PACKAGE} lib ${${PACKAGE}_LIBRARIES}")
118   endif (${PACKAGE}_FOUND)
119 endforeach(PACKAGE)
120
121 #subdirs(dbus)
122
123 #packaging
124 set(CPACK_PACKAGE_NAME wireshark)
125 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "capture packet")
126 set(CPACK_PACKAGE_VENDOR "wireshark")
127 set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
128 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
129 set(CPACK_PACKAGE_VERSION_MAJOR "1")
130 set(CPACK_PACKAGE_VERSION_MINOR "3")
131 set(CPACK_PACKAGE_VERSION_PATCH "0")
132 set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
133
134 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
135 set(CPACK_PACKAGE_INSTALL_DIRECTORY "/usr")
136 set(CPACK_GENERATOR "TGZ")
137 set(CPACK_SOURCE_GENERATOR "TGZ")
138
139 #check system for includes
140 include(CheckIncludeFile)
141 check_include_file("arpa/inet.h"         HAVE_ARPA_INET_H)
142 check_include_file("arpa/nameser.h"      HAVE_ARPA_NAMESER_H)
143 check_include_file("direct.h"            HAVE_DIRECT_H)
144 check_include_file("dirent.h"            HAVE_DIRENT_H)
145 check_include_file("dlfcn.h"             HAVE_DLFCN_H)
146 check_include_file("fcntl.h"             HAVE_FCNTL_H)
147 check_include_file("getopt.h"            NEED_GETOPT_H)
148 check_include_file("grp.h"               HAVE_GRP_H)
149 check_include_file("g_ascii_strtoull.h"  NEED_G_ASCII_STRTOULL_H)
150 check_include_file("inet/aton.h"         NEED_INET_ATON_H)
151 check_include_file("inttypes.h"          HAVE_INTTYPES_H)
152 check_include_file("lauxlib.h"           HAVE_LAUXLIB_H)
153 check_include_file("memory.h"            HAVE_MEMORY_H)
154 check_include_file("netinet/in.h"        HAVE_NETINET_IN_H)
155 check_include_file("netdb.h"             HAVE_NETDB_H)
156 check_include_file("portaudio.h"         HAVE_PORTAUDIO_H)
157 check_include_file("pwd.h"               HAVE_PWD_H)
158 check_include_file("stdarg.h"            HAVE_STDARG_H)
159 check_include_file("stddef.h"            HAVE_STDDEF_H)
160 check_include_file("stdint.h"            HAVE_STDINT_H)
161 check_include_file("stdlib.h"            HAVE_STDLIB_H)
162 check_include_file("strerror.h"          NEED_STRERROR_H)
163 check_include_file("strings.h"           HAVE_STRINGS_H)
164 check_include_file("string.h"            HAVE_STRING_H)
165 check_include_file("sys/ioctl.h"         HAVE_SYS_IOCTL_H)
166 check_include_file("sys/param.h"         HAVE_SYS_PARAM_H)
167 check_include_file("sys/socket.h"        HAVE_SYS_SOCKET_H)
168 check_include_file("sys/sockio.h"        HAVE_SYS_SOCKIO_H)
169 check_include_file("sys/stat.h"          HAVE_SYS_STAT_H)
170 check_include_file("sys/time.h"          HAVE_SYS_TIME_H)
171 check_include_file("sys/types.h"         HAVE_SYS_TYPES_H)
172 check_include_file("sys/utsname.h"       HAVE_SYS_UTSNAME_H)
173 check_include_file("sys/wait.h"          HAVE_SYS_WAIT_H)
174 check_include_file("unistd.h"            HAVE_UNISTD_H)
175
176 #Functions
177 include(CheckFunctionExists)
178 check_function_exists("chown"            HAVE_CHOWN)
179 check_function_exists("gethostbyname2"   HAVE_GETHOSTBYNAME2)
180 check_function_exists("getprotobynumber" HAVE_GETPROTOBYNUMBER)
181 check_function_exists("inet_ntop"        HAVE_INET_NTOP_PROTO)
182 check_function_exists("issetugid"        HAVE_ISSETUGID) 
183 check_function_exists("mmap"             HAVE_MMAP)
184 check_function_exists("mprotect"         HAVE_MPROTECT)
185 check_function_exists("sysconf"          HAVE_SYSCONF)
186
187 #Big or little endian ?
188 include(TestBigEndian)
189 test_big_endian(WORDS_BIGENDIAN)
190
191 set(DATAFILE_DIR "${CMAKE_INSTALL_PREFIX}/share/${CPACK_PACKAGE_NAME}")
192
193 #64 Bit format
194 include(Check64BitFormat)
195
196 check_64bit_format(ll FORMAT_64BIT)
197 check_64bit_format(L FORMAT_64BIT)
198 check_64bit_format(q FORMAT_64BIT)
199 check_64bit_format(I64 FORMAT_64BIT)
200
201 if(NOT FORMAT_64BIT)
202   message(FATAL " 64 bit format missing")
203 endif(NOT FORMAT_64BIT)
204
205 set(PRIX64 "${FORMAT_64BIT}X")
206 set(PRIx64 "${FORMAT_64BIT}x")
207 set(PRId64 "${FORMAT_64BIT}d")
208 set(PRIo64 "${FORMAT_64BIT}o")
209 set(PRIu64 "${FORMAT_64BIT}u")
210
211 #Platform specific
212 if(UNIX)
213   set(WS_VAR_IMPORT "extern")
214 endif(UNIX)
215
216 if(APPLE)
217 #TODO verify that APPLE implies HAVE_OS_X_FRAMEWORKS
218   set(HAVE_OS_X_FRAMEWORKS 1)
219 endif(APPLE)
220
221 if(WIN32)
222   add_definitions(-DHAVE_WIN32_LIBWIRESHARK_LIB -D_NEED_VAR_IMPORT_)
223   set(WS_VAR_IMPORT "__declspec(dllimport) extern")
224 endif(WIN32)
225
226
227 configure_file(${CMAKE_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_BINARY_DIR}/config.h)
228
229 link_directories(
230   wiretap
231   wsutil
232 )
233
234 ADD_CUSTOM_COMMAND(
235    OUTPUT ${CMAKE_BINARY_DIR}/svnversion.h
236    COMMAND ${PERL} ${CMAKE_SOURCE_DIR}/make-version.pl
237    ARGS
238    ${CMAKE_SOURCE_DIR}
239 )
240 SET_SOURCE_FILES_PROPERTIES(${CMAKE_BINARY_DIR}/svnversion.h GENERATED)
241
242 if(UNIX)
243   set(PLATFORM_SRC 
244     capture-pcap-util-unix.c
245   )
246 endif(UNIX)
247
248 if(BUILD_WIRESHARK)
249 # todo
250 endif(BUILD_WIRESHARK)
251
252 if(BUILD_TSHARK)
253 # todo
254 endif(BUILD_TSHARK)
255
256 if(BUILD_RAWSHARK)
257 # todo
258 endif(BUILD_RAWSHARK)
259
260 if(BUILD_text2pcap)
261   set(text2pcap_LIBS
262     wiretap
263     wsutil
264     ${GLIB2_LIBRARIES}
265   )
266   set(text2pcap_FILES
267     text2pcap.c
268   )
269   add_lex_files(text2pcap_FILES
270     text2pcap-scanner.l
271   )
272   add_executable(text2pcap ${text2pcap_FILES})
273   target_link_libraries(text2pcap ${text2pcap_LIBS})
274   install(TARGETS text2pcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
275 endif(BUILD_text2pcap)
276
277 if(BUILD_mergecap)
278   set(mergecap_LIBS
279     wiretap
280     wsutil
281     ${GLIB2_LIBRARIES}
282   )
283   set(mergecap_FILES
284     mergecap.c
285     merge.c
286     svnversion.h
287   )
288   add_executable(mergecap ${mergecap_FILES})
289   target_link_libraries(mergecap ${mergecap_LIBS})
290   install(TARGETS mergecap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
291 endif(BUILD_mergecap)
292
293 if(BUILD_capinfos)
294   set(capinfos_LIBS
295     wiretap
296     wsutil
297     ${GLIB2_LIBRARIES}
298   )
299   set(capinfos_FILES
300     capinfos.c
301   )
302   add_executable(capinfos ${capinfos_FILES})
303   target_link_libraries(capinfos ${capinfos_LIBS})
304   install(TARGETS capinfos RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
305 endif(BUILD_capinfos)
306
307 if(BUILD_editcap)
308   set(editcap_LIBS
309     wiretap
310     wsutil
311     ${GLIB2_LIBRARIES}
312   )
313   set(editcap_FILES
314     editcap.c
315     epan/crypt/crypt-md5.c
316     epan/nstime.c
317   )
318   add_executable(editcap ${editcap_FILES})
319   target_link_libraries(editcap ${editcap_LIBS})
320   install(TARGETS editcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
321 endif(BUILD_editcap)
322
323 if(BUILD_RANDPKT)
324 # todo
325 endif(BUILD_RANDPKT)
326
327 if(BUILD_DFTEST)
328 # todo
329 endif(BUILD_DFTEST)
330
331 if(BUILD_dumpcap)
332   set(dumpcap_LIBS
333     wiretap
334     wsutil
335     ${GLIB2_LIBRARIES}
336     ${PCAP_LIBRARIES}
337   )
338   set(dumpcap_FILES
339         svnversion.h
340         capture_opts.c
341         capture-pcap-util.c
342         capture_stop_conditions.c
343         clopts_common.c
344         conditions.c
345         dumpcap.c
346         pcapio.c
347         ringbuffer.c
348         sync_pipe_write.c
349         tempfile.c
350         version_info.c
351         ${PLATFORM_SRC}
352   )
353   add_executable(dumpcap ${dumpcap_FILES})
354   target_link_libraries(dumpcap ${dumpcap_LIBS})
355   install(TARGETS dumpcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
356 endif(BUILD_dumpcap)