1 cmake_minimum_required(VERSION 2.8.6)
4 # Apple doesn't build with an install_name starting with @rpath, and
5 # neither do we with autotools; don't do so with CMake, either, and
6 # suppress warnings about that.
9 cmake_policy(SET CMP0042 OLD)
12 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
16 # Call the library "wpcap" on Windows, for backwards compatibility.
19 set(LIBRARY_NAME wpcap)
21 set(LIBRARY_NAME pcap)
24 ###################################################################
26 ###################################################################
28 option(INET6 "Enable IPv6" ON)
30 option(USE_STATIC_RT "Use static Runtime" ON)
32 option(BUILD_SHARED_LIBS "Build shared libraries" ON)
34 set(PACKET_DLL_DIR "" CACHE PATH "Path to directory with include and lib subdirectories for packet.dll")
38 # Default to having remote capture support on Windows and, for now, to
39 # not having it on UN*X.
42 option(HAVE_REMOTE "Enable remote capture" ON)
44 option(HAVE_REMOTE "Enable remote capture" OFF)
47 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
48 option(BUILD_WITH_LIBNL "Build with libnl" ON)
51 ######################################
53 ######################################
55 add_definitions(-DHAVE_CONFIG_H)
58 ${CMAKE_CURRENT_BINARY_DIR}
62 include(CheckFunctionExists)
68 set(HAVE_PACKET32 TRUE)
69 set(CMAKE_REQUIRED_LIBRARIES ${PACKET_LIBRARY})
70 include_directories(${PACKET_INCLUDE_DIR})
72 # Check whether we have the NPcap PacketIsLoopbackAdapter()
75 check_function_exists(PacketIsLoopbackAdapter HAVE_PACKET_IS_LOOPBACK_ADAPTER)
85 add_definitions(-DBUILDING_PCAP)
88 add_definitions(-D__STDC__)
89 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
90 add_definitions("-D_U_=")
91 elseif(CMAKE_COMPILER_IS_GNUCXX)
92 add_definitions("-D_U_=__attribute__((unused))")
94 add_definitions("-D_U_=")
99 message(STATUS "Use STATIC runtime")
101 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
102 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
103 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
104 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
105 string(REGEX REPLACE "/MD" "/MT" ${RT_FLAG} "${${RT_FLAG}}")
108 message(STATUS "Use DYNAMIC runtime")
112 ###################################################################
113 # Detect available platform features
114 ###################################################################
116 include(CheckIncludeFile)
117 include(CheckStructHasMember)
118 include(CheckTypeSize)
123 check_include_file(inttypes.h HAVE_INTTYPES_H)
124 check_include_file(stdint.h HAVE_STDINT_H)
125 check_include_file(unistd.h HAVE_UNISTD_H)
126 if(NOT HAVE_UNISTD_H)
127 add_definitions(-DYY_NO_UNISTD_H)
128 endif(NOT HAVE_UNISTD_H)
129 check_include_file(bitypes.h HAVE_SYS_BITYPES_H)
130 check_include_file(sys/ioccom.h HAVE_SYS_IOCCOM_H)
131 check_include_file(sys/sockio.h HAVE_SYS_SOCKIO_H)
132 check_include_file(sys/select.h HAVE_SYS_SELECT_H)
133 check_include_file(limits.h HAVE_LIMITS_H)
134 check_include_file(netpacket/packet.h HAVE_NETPACKET_PACKET_H)
135 check_include_file(net/pfvar.h HAVE_NET_PFVAR_H)
137 check_c_source_compiles(
138 "#include <sys/types.h>
139 #include <sys/socket.h>
141 #include <net/pfvar.h>
146 return PF_NAT+PF_NONAT+PF_BINAT+PF_NOBINAT+PF_RDR+PF_NORDR;
149 HAVE_PF_NAT_THROUGH_PF_NORDR)
151 check_include_file(netinet/if_ether.h HAVE_NETINET_IF_ETHER_H)
152 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
153 check_include_file(linux/sockios.h HAVE_LINUX_SOCKIOS_H)
154 check_include_file(linux/if_bonding.h HAVE_LINUX_IF_BONDING_H)
160 check_function_exists(strerror HAVE_STRERROR)
161 check_function_exists(strlcpy HAVE_STRLCPY)
162 check_function_exists(strlcat HAVE_STRLCAT)
163 check_function_exists(snprintf HAVE_SNPRINTF)
164 check_function_exists(vsnprintf HAVE_VSNPRINTF)
165 check_function_exists(strtok_r HAVE_STRTOK_R)
168 # Find library needed for gethostbyname.
169 # NOTE: if you hand check_library_exists as its last argument a variable
170 # that's been set, it skips the test, so we need different variables.
172 include(CheckLibraryExists)
173 check_function_exists(gethostbyname STDLIBS_HAVE_GETHOSTBYNAME)
174 if(NOT STDLIBS_HAVE_GETHOSTBYNAME)
175 check_library_exists(nsl gethostbyname "" LIBNSL_HAS_GETHOSTBYNAME)
176 if(LIBNSL_HAS_GETHOSTBYNAME)
177 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} nsl)
184 # XXX - there's no check_struct() macro that's like check_struct_has_member()
185 # except that it only checks for the existence of the structure type,
186 # so we use check_struct_has_member() and look for ss_family.
188 check_struct_has_member("struct sockaddr_storage" ss_family sys/socket.h HAVE_SOCKADDR_STORAGE)
189 set(CMAKE_EXTRA_INCLUDE_FILES unistd.h sys/socket.h)
190 check_type_size("socklen_t" SOCKLEN_T)
191 set(CMAKE_EXTRA_INCLUDE_FILES unistd.h)
196 check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_SOCKADDR_SA_LEN)
199 # You are in a twisty little maze of UN*Xes, all different.
200 # Some might not have ether_hostton().
201 # Some might have it and declare it in <net/ethernet.h>.
202 # Some might have it and declare it in <netinet/ether.h>
203 # Some might have it and declare it in <sys/ethernet.h>.
204 # Some might have it and declare it in <arpa/inet.h>.
205 # Some might have it and declare it in <netinet/if_ether.h>.
206 # Some might have it and not declare it in any header file.
208 # Before you is a C compiler.
210 include(CheckSymbolExists)
211 check_function_exists(ether_hostton HAVE_ETHER_HOSTTON)
212 if(HAVE_ETHER_HOSTTON)
214 # OK, we have ether_hostton(). Is it declared in <net/ethernet.h>?
216 # This test fails if we don't have <net/ethernet.h> or if we do
217 # but it doesn't declare ether_hostton().
219 check_symbol_exists(ether_hostton net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
220 if(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
222 # Yes - we have it declared.
224 set(HAVE_DECL_ETHER_HOSTTON TRUE)
229 if(NOT HAVE_DECL_ETHER_HOSTTON)
231 # No - how about <netinet/ether.h>, as on Linux?
233 # This test fails if we don't have <netinet/ether.h>
234 # or if we do but it doesn't declare ether_hostton().
236 check_symbol_exists(ether_hostton netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
237 if(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
239 # Yes - we have it declared.
241 set(HAVE_DECL_ETHER_HOSTTON TRUE)
247 if(NOT HAVE_DECL_ETHER_HOSTTON)
249 # No - how about <sys/ethernet.h>, as on Solaris 10 and later?
251 # This test fails if we don't have <sys/ethernet.h>
252 # or if we do but it doesn't declare ether_hostton().
254 check_symbol_exists(ether_hostton sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
255 if(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
257 # Yes - we have it declared.
259 set(HAVE_DECL_ETHER_HOSTTON TRUE)
265 if(NOT HAVE_DECL_ETHER_HOSTTON)
267 # No, how about <arpa/inet.h>, as on AIX?
269 # This test fails if we don't have <arpa/inet.h>
270 # or if we do but it doesn't declare ether_hostton().
272 check_symbol_exists(ether_hostton arpa/inet.h ARPA_INET_H_DECLARES_ETHER_HOSTTON)
273 if(ARPA_INET_H_DECLARES_ETHER_HOSTTON)
275 # Yes - we have it declared.
277 set(HAVE_DECL_ETHER_HOSTTON TRUE)
283 if(NOT HAVE_DECL_ETHER_HOSTTON)
285 # No, how about <netinet/if_ether.h>?
286 # On some platforms, it requires <net/if.h> and
287 # <netinet/in.h>, and we always include it with
288 # both of them, so test it with both of them.
290 # This test fails if we don't have <netinet/if_ether.h>
291 # and the headers we include before it, or if we do but
292 # <netinet/if_ether.h> doesn't declare ether_hostton().
294 check_symbol_exists(ether_hostton "sys/types.h;sys/socket.h;net/if.h;netinet/in.h;netinet/if_ether.h" NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
295 if(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
297 # Yes - we have it declared.
299 set(HAVE_DECL_ETHER_HOSTTON TRUE)
303 # After all that, is ether_hostton() declared?
305 if(NOT HAVE_DECL_ETHER_HOSTTON)
307 # No, we'll have to declare it ourselves.
308 # Do we have "struct ether_addr" if we include<netinet/if_ether.h>?
310 check_struct_has_member("struct ether_addr" octet "sys/types.h;sys/socket.h;net/if.h;netinet/in.h;netinet/if_ether.h" HAVE_STRUCT_ETHER_ADDR)
315 # Large file support on UN*X, a/k/a LFS.
321 # Add the required #defines.
323 add_definitions(${LFS_DEFINITIONS})
328 message(STATUS "Use IPv6")
332 add_definitions(-DHAVE_ADDRINFO)
335 ######################################
336 # External dependencies
337 ######################################
339 ######################################
341 ######################################
343 set(PROJECT_SOURCE_LIST_C
359 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/win_snprintf.c)
361 if(NOT HAVE_SNPRINTF)
362 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/snprintf.c)
363 endif(NOT HAVE_SNPRINTF)
364 if(NOT HAVE_STRTOK_R)
365 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strtok_r.c)
366 endif(NOT HAVE_STRTOK_R)
370 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C}
371 pcap-new.c pcap-rpcap.c sockutils.c)
375 # Determine the main pcap-XXX.c file to use, and the libraries with
376 # which we need to link libpcap, if any.
380 # Windows; we need to link with WinSock2.
382 set(PCAP_LINK_LIBRARIES ws2_32)
385 # Check whether we have packet.dll.
389 # We have packet.dll.
390 # Set the capture type to NPF.
395 # We don't have any capture type we know about, so just use
396 # the null capture type, and only support reading (and writing)
405 # Figure out what type of packet capture mechanism we have, and
406 # what libraries we'd need to link libpcap with, if any.
408 set(PCAP_LINK_LIBRARIES "")
411 # Check for a bunch of headers for various packet capture mechanisms.
413 include(CheckIncludeFiles)
414 check_include_files("sys/types.h;net/bpf.h" HAVE_NET_BPF_H)
415 check_include_file(net/pfilt.h HAVE_NET_PFILT_H)
416 check_include_file(net/enet.h HAVE_NET_ENET_H)
417 check_include_file(net/nit.h HAVE_NET_NIT_H)
418 check_include_file(sys/net/nit.h HAVE_SYS_NET_NIT_H)
419 check_include_file(linux/socket.h HAVE_LINUX_SOCKET_H)
420 check_include_file(net/raw.h HAVE_NET_RAW_H)
421 check_include_file(sys/dlpi.h HAVE_SYS_DLPI_H)
426 # Check this before DLPI, so that we pick BPF on
427 # Solaris 11 and later.
430 elseif(HAVE_NET_PFILT_H)
432 # DEC OSF/1, Digital UNIX, Tru64 UNIX
435 elseif(HAVE_NET_ENET_H)
437 # Stanford Enetfilter.
440 elseif(HAVE_NET_NIT_H)
442 # SunOS 4.x STREAMS NIT.
445 elseif(HAVE_SYS_NET_NIT_H)
447 # Pre-SunOS 4.x non-STREAMS NIT.
450 elseif(HAVE_LINUX_SOCKET_H)
452 # No prizes for guessing this one.
455 elseif(HAVE_NET_RAW_H)
460 elseif(HAVE_SYS_DLPI_H)
462 # DLPI on pre-Solaris 11 SunOS 5, HP-UX, possibly others.
467 # Nothing we support.
472 message(STATUS "Packet capture mechanism type: ${PCAP_TYPE}")
473 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-${PCAP_TYPE}.c)
477 # Do capture-mechanism-dependent tests.
479 if(PCAP_TYPE STREQUAL "npf")
481 # Link with packet.dll before WinSock2.
483 set(PCAP_LINK_LIBRARIES ${PACKET_LIBRARY} ${PCAP_LINK_LIBRARIES})
484 elseif(PCAP_TYPE STREQUAL "dlpi")
486 # Needed for common functions used by pcap-[dlpi,libdlpi].c
488 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} dlpisubs.c)
491 # Checks for some header files.
493 check_include_file(sys/bufmod.h HAVE_SYS_BUFMOD_H)
494 check_include_file(sys/dlpi_ext.h HAVE_SYS_DLPI_EXT_H)
497 # Checks to see if Solaris has the public libdlpi(3LIB) library.
498 # Note: The existence of /usr/include/libdlpi.h does not mean it is the
499 # public libdlpi(3LIB) version. Before libdlpi was made public, a
500 # private version also existed, which did not have the same APIs.
501 # Due to a gcc bug, the default search path for 32-bit libraries does
502 # not include /lib, we add it explicitly here.
503 # [http://bugs.opensolaris.org/view_bug.do?bug_id=6619485].
504 # Also, due to the bug above applications that link to libpcap with
505 # libdlpi will have to add "-L/lib" option to "configure".
507 cmake_push_check_state()
508 set(CMAKE_REQUIRED_FLAGS "-L/lib")
509 set(CMAKE_REQUIRED_LIBRARIES dlpi)
510 check_function_exists(dlpi_walk HAVE_LIBDLPI)
511 cmake_pop_check_state()
516 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} dlpi)
517 set(PCAP_TYPE libdlpi)
521 # This check is for Solaris with DLPI support for passive modes.
522 # See dlpi(7P) for more details.
524 # XXX - there's no check_struct() macro that's like
525 # check_struct_has_member() except that it only checks for the
526 # existence of the structure type, so we use
527 # check_struct_has_member() and look for dl_primitive.
529 check_struct_has_member("dl_passive_req_t" dl_primitive "sys/types.h;sys/dlpi.h" HAVE_DLPI_PASSIVE)
530 elseif(PCAP_TYPE STREQUAL "linux")
532 # Do we have the wireless extensions?
534 check_include_file(linux/wireless.h HAVE_LINUX_WIRELESS_H)
541 # Try libnl 3.x first.
543 cmake_push_check_state()
544 set(CMAKE_REQUIRED_LIBRARIES nl-3)
545 check_function_exists(nl_socket_alloc HAVE_LIBNL)
546 cmake_pop_check_state()
549 # Yes, we have libnl 3.x.
551 set(PCAP_LINK_LIBRARIES nl-genl-3 nl-3 ${PCAP_LINK_LIBRARIES})
552 set(HAVE_LIBNL_3_x ON)
553 set(HAVE_LIBNL_NLE ON)
554 set(HAVE_LIBNL_SOCKETS ON)
555 include_directories("/usr/include/libnl3")
560 cmake_push_check_state()
561 set(CMAKE_REQUIRED_LIBRARIES nl)
562 check_function_exists(nl_socket_alloc HAVE_LIBNL)
563 cmake_pop_check_state()
566 # Yes, we have libnl 2.x.
568 set(PCAP_LINK_LIBRARIES nl-genl nl ${PCAP_LINK_LIBRARIES})
569 set(HAVE_LIBNL_2_x ON)
570 set(HAVE_LIBNL_NLE ON)
571 set(HAVE_LIBNL_SOCKETS ON)
574 # No, we don't; do we have libnl 1.x?
576 cmake_push_check_state()
577 set(CMAKE_REQUIRED_LIBRARIES nl)
578 check_function_exists(nl_handle_alloc HAVE_LIBNL)
579 cmake_pop_check_state()
581 set(PCAP_LINK_LIBRARIES nl ${PCAP_LINK_LIBRARIES})
587 check_include_file(linux/ethtool.h HAVE_LINUX_ETHTOOL_H)
590 # Checks to see if tpacket_stats is defined in linux/if_packet.h
591 # If so then pcap-linux.c can use this to report proper statistics.
593 check_struct_has_member("struct tpacket_stats" tp_packets linux/if_packet.h HAVE_TPACKET_STATS)
595 check_struct_has_member("struct tpacket_auxdata" tp_vlan_tci linux/if_packet.h HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI)
596 if(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI)
597 set(HAVE_LINUX_TPACKET_AUXDATA tp_vlan_tci)
599 elseif(PCAP_TYPE STREQUAL "bpf")
601 # Check whether we have the *BSD-style ioctls.
603 check_include_files("sys/types.h;net/if_media.h" HAVE_NET_IF_MEDIA_H)
606 # Check whether we have struct BPF_TIMEVAL.
608 if(HAVE_SYS_IOCCOM_H)
609 check_struct_has_member("struct BPF_TIMEVAL" tv_sec "sys/types.h;sys/ioccom.h;net/bpf.h" HAVE_STRUCT_BPF_TIMEVAL)
611 check_struct_has_member("struct BPF_TIMEVAL" tv_sec "sys/types.h;net/bpf.h" HAVE_STRUCT_BPF_TIMEVAL)
616 # Now figure out how we get a list of interfaces and addresses,
617 # if we support capturing. Don't bother if we don't support
622 # UN*X - figure out what type of interface list mechanism we
625 # If the capture type is null, that means we can't capture,
626 # so we can't open any capture devices, so we won't return
629 if(NOT PCAP_TYPE STREQUAL "null")
630 check_function_exists(getifaddrs HAVE_GETIFADDRS)
631 if(NOT HAVE_GETIFADDRS)
633 # It's in libsocket on Solaris and possibly other OSes;
636 # NOTE: if you hand check_library_exists as its last
637 # argument a variable that's been set, it skips the test,
638 # so we need different variables.
640 check_library_exists(socket getifaddrs "" SOCKET_HAS_GETIFADDRS)
641 if(SOCKET_HAS_GETIFADDRS)
642 set(PCAP_LINK_LIBRARIES socket ${PCAP_LINK_LIBRARIES})
643 set(HAVE_GETIFADDRS TRUE)
648 # We have "getifaddrs()"; make sure we have <ifaddrs.h>
649 # as well, just in case some platform is really weird.
650 # It may require that sys/types.h be included first,
651 # so include it first.
653 check_include_files("sys/types.h;ifaddrs.h" HAVE_IFADDRS_H)
656 # We have the header, so we use "getifaddrs()" to
657 # get the list of interfaces.
659 set(FINDALLDEVS_TYPE getad)
662 # We don't have the header - give up.
663 # XXX - we could also fall back on some other
664 # mechanism, but, for now, this'll catch this
665 # problem so that we can at least try to figure
666 # out something to do on systems with "getifaddrs()"
667 # but without "ifaddrs.h", if there is something
668 # we can do on those systems.
670 message(FATAL_ERROR "Your system has getifaddrs() but doesn't have a usable <ifaddrs.h>.")
674 # Well, we don't have "getifaddrs()", so we have to use
675 # some other mechanism; determine what that mechanism is.
677 # The first thing we use is the type of capture mechanism,
678 # which is somewhat of a proxy for the OS we're using.
680 if(PCAP_TYPE STREQUAL "dlpi" OR PCAP_TYPE STREQUAL "libdlpi")
682 # This might be Solaris 8 or later, with
683 # SIOCGLIFCONF, or it might be some other OS
684 # or some older version of Solaris, with
687 try_compile(HAVE_SIOCGLIFCONF ${CMAKE_CURRENT_BINARY_DIR} "${pcap_SOURCE_DIR}/cmake/have_siocglifconf.c" )
688 if(HAVE_SIOCGLIFCONF)
689 set(FINDALLDEVS_TYPE glifc)
691 set(FINDALLDEVS_TYPE gifc)
695 # Assume we just have SIOCGIFCONF.
696 # (XXX - on at least later Linux kernels, there's
697 # another mechanism, and we should be using that
700 set(FINDALLDEVS_TYPE gifc)
703 message(STATUS "Find-interfaces mechanism type: ${FINDALLDEVS_TYPE}")
704 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} fad-${FINDALLDEVS_TYPE}.c)
708 file(GLOB PROJECT_SOURCE_LIST_CORE_H
712 set(PROJECT_SOURCE_LIST_H ${PROJECT_SOURCE_LIST_H} ${PROJECT_SOURCE_LIST_CORE_H})
715 file(GLOB PROJECT_SOURCE_LIST_WIN32_H
718 set(PROJECT_SOURCE_LIST_H ${PROJECT_SOURCE_LIST_H} ${PROJECT_SOURCE_LIST_WIN32_H})
722 # {Flex} and YACC/Berkeley YACC/Bison.
723 # From a mail message to the CMake mailing list by Andy Cedilnik of
728 # Try to find Flex, a Windows version of Flex, or Lex.
730 find_program(LEX_EXECUTABLE NAMES flex win_flex lex)
731 if(LEX_EXECUTABLE STREQUAL "LEX_EXECUTABLE-NOTFOUND")
732 message(FATAL_ERROR "Neither flex nor win_flex nor lex was found.")
734 message(STATUS "Lexical analyzer generator: ${LEX_EXECUTABLE}")
737 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${CMAKE_CURRENT_BINARY_DIR}/scanner.h
738 SOURCE ${pcap_SOURCE_DIR}/scanner.l
739 COMMAND ${LEX_EXECUTABLE} -P pcap_ --header-file=scanner.h --nounput -o${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${pcap_SOURCE_DIR}/scanner.l
740 DEPENDS ${pcap_SOURCE_DIR}/scanner.l
744 # Since scanner.c does not exist yet when cmake is run, mark
747 # Since scanner.c includes grammar.h, mark that as a dependency.
749 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/scanner.c PROPERTIES
751 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/scanner.h
755 # Add scanner.c to the list of sources.
757 #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/scanner.c)
760 # Try to find YACC or Bison.
762 find_program(YACC_EXECUTABLE NAMES bison win_bison byacc yacc)
763 if(YACC_EXECUTABLE STREQUAL "YACC_EXECUTABLE-NOTFOUND")
764 message(FATAL_ERROR "Neither bison nor win_bison nor byacc nor yacc was found.")
766 message(STATUS "Parser generator: ${YACC_EXECUTABLE}")
769 # Create custom command for the scanner.
770 # Find out whether it's Bison or notby looking at the last component
771 # of the path (without a .exe extension, if this is Windows).
773 get_filename_component(YACC_NAME ${YACC_EXECUTABLE} NAME_WE)
774 if("${YACC_NAME}" STREQUAL "bison" OR "${YACC_NAME}" STREQUAL "win_bison")
775 set(YACC_COMPATIBILITY_FLAG "-y")
778 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/grammar.c ${CMAKE_CURRENT_BINARY_DIR}/grammar.h
779 SOURCE ${pcap_SOURCE_DIR}/grammar.y
780 COMMAND ${YACC_EXECUTABLE} ${YACC_COMPATIBILITY_FLAG} -p pcap_ -o ${CMAKE_CURRENT_BINARY_DIR}/grammar.c -d ${pcap_SOURCE_DIR}/grammar.y
781 DEPENDS ${pcap_SOURCE_DIR}/grammar.y
785 # Since grammar.c does not exists yet when cmake is run, mark
788 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/grammar.c PROPERTIES
793 # Add grammar.c to the list of sources.
795 #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/grammar.c)
797 if(WIN32 AND NOT MSYS AND NOT ${CMAKE_CROSSCOMPILING})
799 # CMake does not love Windows. Convert its UN*X-style paths to
800 # Windows-style paths to hand to Windows programs.
802 file(TO_NATIVE_PATH "${pcap_SOURCE_DIR}/GenVersion.bat" GenVersion_path)
803 file(TO_NATIVE_PATH "${pcap_SOURCE_DIR}/VERSION" VERSION_path)
804 file(TO_NATIVE_PATH "${pcap_SOURCE_DIR}/version.c.in" version_c_in_path)
805 file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/version.c" version_c_path)
806 file(TO_NATIVE_PATH "${pcap_SOURCE_DIR}/pcap_version.h.in" pcap_version_h_in_path)
807 file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/pcap_version.h" pcap_version_h_path)
809 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.c
810 SOURCE ${pcap_SOURCE_DIR}/VERSION
811 COMMAND ${GenVersion_path} ${VERSION_path} ${version_c_in_path} ${version_c_path}
812 DEPENDS ${pcap_SOURCE_DIR}/VERSION ${pcap_SOURCE_DIR}/version.c.in
815 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pcap_version.h
816 SOURCE ${pcap_SOURCE_DIR}/VERSION ${pcap_SOURCE_DIR}/pcap_version.h.in
817 COMMAND ${GenVersion_path} ${VERSION_path} ${pcap_version_h_in_path} ${pcap_version_h_path}
818 DEPENDS ${pcap_SOURCE_DIR}/VERSION ${pcap_SOURCE_DIR}/pcap_version.h.in
820 else(WIN32 AND NOT MSYS AND NOT ${CMAKE_CROSSCOMPILING})
822 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.c
823 SOURCE ${pcap_SOURCE_DIR}/VERSION
824 COMMAND ${pcap_SOURCE_DIR}/gen_version.sh ${pcap_SOURCE_DIR}/VERSION ${pcap_SOURCE_DIR}/version.c.in ${CMAKE_CURRENT_BINARY_DIR}/version.c
825 DEPENDS ${pcap_SOURCE_DIR}/VERSION
828 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pcap_version.h
829 SOURCE ${pcap_SOURCE_DIR}/VERSION
830 COMMAND ${pcap_SOURCE_DIR}/gen_version.sh ${pcap_SOURCE_DIR}/VERSION ${pcap_SOURCE_DIR}/pcap_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/pcap_version.h
831 DEPENDS ${pcap_SOURCE_DIR}/VERSION
835 # Since version.c does not exists yet when cmake is run, mark
838 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/version.c PROPERTIES
843 # Add version.c to the list of sources.
845 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/version.c)
846 endif(WIN32 AND NOT MSYS AND NOT ${CMAKE_CROSSCOMPILING})
849 # Since pcap_version.h does not exists yet when cmake is run, mark
852 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/pcap_version.h PROPERTIES
857 # Add pcap_version.h to the list of headers.
859 set(PROJECT_SOURCE_LIST_H ${PROJECT_SOURCE_LIST_H} ${CMAKE_CURRENT_BINARY_DIR}/pcap_version.h)
861 source_group("Source Files" FILES ${PROJECT_SOURCE_LIST_C})
862 source_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H})
864 ######################################
866 ######################################
869 # Special target to serialize the building of the generated source.
873 # http://public.kitware.com/pipermail/cmake/2013-August/055510.html
875 add_custom_target(SerializeTarget
877 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
878 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
879 ${CMAKE_CURRENT_BINARY_DIR}/version.c
882 if(BUILD_SHARED_LIBS)
883 add_library(${LIBRARY_NAME} SHARED
884 ${PROJECT_SOURCE_LIST_C}
885 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
886 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
887 ${PROJECT_SOURCE_LIST_H}
889 add_dependencies(${LIBRARY_NAME} SerializeTarget)
890 endif(BUILD_SHARED_LIBS)
892 add_library(${LIBRARY_NAME}_static STATIC
893 ${PROJECT_SOURCE_LIST_C}
894 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
895 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
896 ${PROJECT_SOURCE_LIST_H}
898 add_dependencies(${LIBRARY_NAME}_static SerializeTarget)
902 CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELWITHDEBINFO
903 CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELWITHDEBINFO)
904 string(REGEX REPLACE "/Zi" "" ${DBG_FLAGS} "${${DBG_FLAGS}}")
905 endforeach(DBG_FLAGS)
907 set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_OPTIONS "/Zi")
908 set_target_properties(${LIBRARY_NAME}_static PROPERTIES OUTPUT_NAME "${LIBRARY_NAME}_static" COMPILE_OPTIONS "/Z7")
910 set_target_properties(${LIBRARY_NAME}_static PROPERTIES OUTPUT_NAME "${LIBRARY_NAME}")
913 if(BUILD_SHARED_LIBS)
914 target_link_libraries(${LIBRARY_NAME} ${PCAP_LINK_LIBRARIES})
915 endif(BUILD_SHARED_LIBS)
917 ######################################
918 # Write out the config.h file
919 ######################################
921 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
923 ######################################
924 # Install pcap library and include files
925 ######################################
927 set(LIBRARY_NAME_STATIC ${LIBRARY_NAME}_static)
929 if(NOT BUILD_SHARED_LIBS)
931 endif(NOT BUILD_SHARED_LIBS)
936 # Install 64-bit code built with MSVC in the amd64 subdirectories,
937 # as that's where it expects it to be.
939 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
940 RUNTIME DESTINATION bin/amd64
941 LIBRARY DESTINATION lib/amd64
942 ARCHIVE DESTINATION lib/amd64)
943 if(BUILD_SHARED_LIBS)
944 install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}>
945 DESTINATION bin/amd64 OPTIONAL)
946 endif(BUILD_SHARED_LIBS)
949 # Install 32-bit code, and 64-bit code not built with MSVC
950 # in the top-level directories, as those are where they
953 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
954 RUNTIME DESTINATION bin
955 LIBRARY DESTINATION lib
956 ARCHIVE DESTINATION lib)
957 if(BUILD_SHARED_LIBS)
958 install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}>
959 DESTINATION bin OPTIONAL)
960 endif(BUILD_SHARED_LIBS)
963 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC} DESTINATION lib)
966 install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pcap/ DESTINATION include/pcap)
967 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap.h DESTINATION include)