CMakeLists.txt 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296
  1. cmake_minimum_required(VERSION 2.8.6)
  2. #
  3. # Apple doesn't build with an install_name starting with @rpath, and
  4. # neither do we with autotools; don't do so with CMake, either, and
  5. # suppress warnings about that.
  6. #
  7. if(POLICY CMP0042)
  8. cmake_policy(SET CMP0042 OLD)
  9. endif()
  10. set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
  11. project(pcap)
  12. #
  13. # Try to enable as many C99 features as we can.
  14. # At minimum, we want C++/C99-style // comments.
  15. #
  16. # Newer versions of compilers might default to supporting C99, but older
  17. # versions may require a special flag.
  18. #
  19. # Prior to CMake 3.1, setting CMAKE_C_STANDARD will not have any effect,
  20. # so, unless and until we require CMake 3.1 or later, we have to do it
  21. # ourselves on pre-3.1 CMake, so we just do it ourselves on all versions
  22. # of CMake.
  23. #
  24. # Note: with CMake 3.1 through 3.5, the only compilers for which CMake
  25. # handles CMAKE_C_STANDARD are GCC and Clang. 3.6 adds support only
  26. # for Intel C; 3.9 adds support for PGI C, Sun C, and IBM XL C, and
  27. # 3.10 adds support for Cray C and IAR C, but no version of CMake has
  28. # support for HP C. Therefore, even if we use CMAKE_C_STANDARD with
  29. # compilers for which CMake supports it, we may still have to do it
  30. # ourselves on other compilers.
  31. #
  32. # See the CMake documentation for the CMAKE_<LANG>_COMPILER_ID variables
  33. # for a list of compiler IDs.
  34. #
  35. # We don't worry about MSVC; it doesn't have such a flag - either it
  36. # doesn't support the C99 features we need at all, or it supports them
  37. # regardless of the compiler flag.
  38. #
  39. # XXX - this just tests whether the option works and adds it if it does.
  40. # We don't test whether it's necessary in order to get the C99 features
  41. # that we use; if we ever have a user who tries to compile with a compiler
  42. # that can't be made to support those features, we can add a test to make
  43. # sure we actually *have* C99 support.
  44. #
  45. include(CheckCCompilerFlag)
  46. macro(check_and_add_compiler_option _option)
  47. message(STATUS "Checking C compiler flag ${_option}")
  48. string(REPLACE "=" "-" _temp_option_variable ${_option})
  49. string(REGEX REPLACE "^-" "" _option_variable ${_temp_option_variable})
  50. check_c_compiler_flag("${_option}" ${_option_variable})
  51. if(${${_option_variable}})
  52. set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} ${_option}")
  53. endif()
  54. endmacro()
  55. set(C_ADDITIONAL_FLAGS "")
  56. if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR
  57. CMAKE_C_COMPILER_ID MATCHES "Clang")
  58. check_and_add_compiler_option("-std=gnu99")
  59. elseif(CMAKE_C_COMPILER_ID MATCHES "XL")
  60. #
  61. # We want support for extensions picked up for GNU C compatibility,
  62. # so we use -qlanglvl=extc99.
  63. #
  64. check_and_add_compiler_option("-qlanglvl=extc99")
  65. elseif(CMAKE_C_COMPILER_ID MATCHES "HP")
  66. check_and_add_compiler_option("-AC99")
  67. elseif(CMAKE_C_COMPILER_ID MATCHES "Sun")
  68. check_and_add_compiler_option("-xc99")
  69. elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
  70. check_and_add_compiler_option("-c99")
  71. endif()
  72. #
  73. # Build all runtimes in the top-level binary directory; that way,
  74. # on Windows, the executables will be in the same directory as
  75. # the DLLs, so the system will find pcap.dll when any of the
  76. # executables are run.
  77. #
  78. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run)
  79. ###################################################################
  80. # Parameters
  81. ###################################################################
  82. if(WIN32)
  83. #
  84. # On Windows, allow the library name to be overridden, for the
  85. # benefit of projects that combine libpcap with their own
  86. # kernel-mode code to support capturing.
  87. #
  88. set(LIBRARY_NAME pcap CACHE STRING "Library name")
  89. else()
  90. #
  91. # On UN*X, it's always been libpcap.
  92. #
  93. set(LIBRARY_NAME pcap)
  94. endif()
  95. option(INET6 "Enable IPv6" ON)
  96. if(WIN32)
  97. option(USE_STATIC_RT "Use static Runtime" ON)
  98. endif(WIN32)
  99. option(BUILD_SHARED_LIBS "Build shared libraries" ON)
  100. if(WIN32)
  101. set(PACKET_DLL_DIR "" CACHE PATH "Path to directory with include and lib subdirectories for packet.dll")
  102. endif(WIN32)
  103. # To pacify those who hate the protochain instruction
  104. option(NO_PROTOCHAIN "Disable protochain instruction" OFF)
  105. #
  106. # Start out with the capture mechanism type unspecified; the user
  107. # can explicitly specify it and, if they don't, we'll pick an
  108. # appropriate one.
  109. #
  110. set(PCAP_TYPE "" CACHE STRING "Packet capture type")
  111. #
  112. # Default to having remote capture support on Windows and, for now, to
  113. # not having it on UN*X.
  114. #
  115. if(WIN32)
  116. option(ENABLE_REMOTE "Enable remote capture" ON)
  117. else()
  118. option(ENABLE_REMOTE "Enable remote capture" OFF)
  119. endif(WIN32)
  120. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  121. option(PCAP_SUPPORT_PACKET_RING "Enable Linux packet ring support" ON)
  122. option(BUILD_WITH_LIBNL "Build with libnl" ON)
  123. endif()
  124. #
  125. # By default, build universal with the appropriate set of architectures
  126. # for the OS on which we're doing the build.
  127. #
  128. if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
  129. #
  130. # Get the major version of Darwin.
  131. #
  132. string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}")
  133. if(SYSTEM_VERSION_MAJOR LESS 8)
  134. #
  135. # Pre-Tiger. Build only for 32-bit PowerPC.
  136. #
  137. set(CMAKE_OSX_ARCHITECTURES "ppc")
  138. elseif(SYSTEM_VERSION_MAJOR EQUAL 8)
  139. #
  140. # Tiger. Is this prior to, or with, Intel support?
  141. #
  142. # Get the minor version of Darwin.
  143. #
  144. string(REPLACE "${SYSTEM_VERSION_MAJOR}." "" SYSTEM_MINOR_AND_PATCH_VERSION ${CMAKE_SYSTEM_VERSION})
  145. string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MINOR "${SYSTEM_MINOR_AND_PATCH_VERSION}")
  146. if(SYSTEM_VERSION_MINOR LESS 4)
  147. #
  148. # Prior to Intel support. Build for 32-bit
  149. # PowerPC and 64-bit PowerPC, with 32-bit PowerPC
  150. # first. (I'm guessing that's what Apple does.)
  151. #
  152. set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64")
  153. elseif(SYSTEM_VERSION_MINOR LESS 7)
  154. #
  155. # With Intel support but prior to x86-64 support.
  156. # Build for 32-bit PowerPC, 64-bit PowerPC, and x86,
  157. # with 32-bit PowerPC first.
  158. # (I'm guessing that's what Apple does.)
  159. #
  160. set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386")
  161. else()
  162. #
  163. # With Intel support including x86-64 support.
  164. # Build for 32-bit PowerPC, 64-bit PowerPC, x86,
  165. # and x86-64, with 32-bit PowerPC first.
  166. # (I'm guessing that's what Apple does.)
  167. #
  168. set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386;x86_64")
  169. endif()
  170. elseif(SYSTEM_VERSION_MAJOR EQUAL 9)
  171. #
  172. # Leopard. Build for 32-bit PowerPC, 64-bit
  173. # PowerPC, x86, and x86-64, with 32-bit PowerPC
  174. # first. (That's what Apple does.)
  175. #
  176. set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386;x86_64")
  177. elseif(SYSTEM_VERSION_MAJOR EQUAL 10)
  178. #
  179. # Snow Leopard. Build for x86-64, x86, and
  180. # 32-bit PowerPC, with x86-64 first. (That's
  181. # what Apple does, even though Snow Leopard
  182. # doesn't run on PPC, so PPC libpcap runs under
  183. # Rosetta, and Rosetta doesn't support BPF
  184. # ioctls, so PPC programs can't do live
  185. # captures.)
  186. #
  187. set(CMAKE_OSX_ARCHITECTURES "x86_64;i386;ppc")
  188. else()
  189. #
  190. # Post-Snow Leopard. Build for x86-64 and
  191. # x86, with x86-64 first. (That's probably what
  192. # Apple does, given that Rosetta is gone.)
  193. # XXX - update if and when Apple drops support
  194. # for 32-bit x86 code.
  195. #
  196. set(CMAKE_OSX_ARCHITECTURES "x86_64;i386")
  197. endif()
  198. endif()
  199. #
  200. # Additional capture modules.
  201. #
  202. option(DISABLE_USB "Disable USB sniffing support" OFF)
  203. option(DISABLE_BLUETOOTH "Disable Bluetooth sniffing support" OFF)
  204. option(DISABLE_NETMAP "Disable netmap support" OFF)
  205. #
  206. # We don't support D-Bus sniffing on macOS; see
  207. #
  208. # https://bugs.freedesktop.org/show_bug.cgi?id=74029
  209. #
  210. if(APPLE)
  211. option(DISABLE_DBUS "Disable D-Bus sniffing support" ON)
  212. else(APPLE)
  213. option(DISABLE_DBUS "Disable D-Bus sniffing support" OFF)
  214. endif(APPLE)
  215. option(DISABLE_RDMA "Disable RDMA sniffing support" OFF)
  216. option(DISABLE_DAG "Disable Endace DAG card support" OFF)
  217. option(DISABLE_SEPTEL "Disable Septel card support" OFF)
  218. set(SEPTEL_ROOT "${CMAKE_SOURCE_DIR}/../septel" CACHE PATH "Path to directory with include and lib subdirectories for Septel API")
  219. option(DISABLE_SNF "Disable Myricom SNF support" OFF)
  220. option(DISABLE_TC "Disable Riverbed TurboCap support" OFF)
  221. #
  222. # Debugging options.
  223. #
  224. option(BDEBUG "Build optimizer debugging code" OFF)
  225. option(YYDEBUG "Build parser debugging code" OFF)
  226. ###################################################################
  227. # Versioning
  228. ###################################################################
  229. # Get, parse, format and set pcap's version string from [pcap_root]/VERSION
  230. # for later use.
  231. # Get MAJOR, MINOR, PATCH & SUFFIX
  232. file(STRINGS ${pcap_SOURCE_DIR}/VERSION
  233. PACKAGE_VERSION
  234. LIMIT_COUNT 1 # Read only the first line
  235. )
  236. # Get "just" MAJOR
  237. string(REGEX MATCH "^([0-9]+)" PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION}")
  238. # Get MAJOR, MINOR & PATCH
  239. string(REGEX MATCH "^([0-9]+.)?([0-9]+.)?([0-9]+)" PACKAGE_VERSION_NOSUFFIX "${PACKAGE_VERSION}")
  240. if(WIN32)
  241. # Convert PCAP_VERSION_NOSUFFIX to Windows preferred version format
  242. string(REPLACE "." "," PACKAGE_VERSION_PREDLL ${PACKAGE_VERSION_NOSUFFIX})
  243. # Append NANO (used for Windows internal versioning) to PCAP_VERSION_PREDLL
  244. # 0 means unused.
  245. set(PACKAGE_VERSION_DLL ${PACKAGE_VERSION_PREDLL},0)
  246. endif(WIN32)
  247. set(PACKAGE_NAME "${LIBRARY_NAME}")
  248. set(PACKAGE_STRING "${LIBRARY_NAME} ${PACKAGE_VERSION}")
  249. ######################################
  250. # Project settings
  251. ######################################
  252. add_definitions(-DHAVE_CONFIG_H)
  253. include_directories(
  254. ${CMAKE_CURRENT_BINARY_DIR}
  255. ${pcap_SOURCE_DIR}
  256. )
  257. include(CheckFunctionExists)
  258. include(CMakePushCheckState)
  259. if(WIN32)
  260. if(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
  261. include_directories(${CMAKE_HOME_DIRECTORY}/../../Common)
  262. endif(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
  263. find_package(Packet)
  264. if(PACKET_FOUND)
  265. set(HAVE_PACKET32 TRUE)
  266. include_directories(${PACKET_INCLUDE_DIRS})
  267. #
  268. # Check whether we have the NPcap PacketIsLoopbackAdapter()
  269. # function.
  270. #
  271. cmake_push_check_state()
  272. set(CMAKE_REQUIRED_LIBRARIES ${PACKET_LIBRARIES})
  273. check_function_exists(PacketIsLoopbackAdapter HAVE_PACKET_IS_LOOPBACK_ADAPTER)
  274. cmake_pop_check_state()
  275. endif(PACKET_FOUND)
  276. endif(WIN32)
  277. if(MSVC)
  278. add_definitions(-D__STDC__)
  279. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  280. endif(MSVC)
  281. if(USE_STATIC_RT)
  282. message(STATUS "Use STATIC runtime")
  283. if(MSVC)
  284. foreach(RT_FLAG
  285. CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  286. CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
  287. CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
  288. CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
  289. string(REGEX REPLACE "/MD" "/MT" ${RT_FLAG} "${${RT_FLAG}}")
  290. endforeach(RT_FLAG)
  291. elseif(MINGW)
  292. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
  293. endif()
  294. else (USE_STATIC_RT)
  295. message(STATUS "Use DYNAMIC runtime")
  296. endif(USE_STATIC_RT)
  297. ###################################################################
  298. # Detect available platform features
  299. ###################################################################
  300. include(CheckIncludeFile)
  301. include(CheckIncludeFiles)
  302. include(CheckStructHasMember)
  303. include(CheckTypeSize)
  304. #
  305. # Header files.
  306. #
  307. check_include_file(inttypes.h HAVE_INTTYPES_H)
  308. check_include_file(stdint.h HAVE_STDINT_H)
  309. check_include_file(unistd.h HAVE_UNISTD_H)
  310. if(NOT HAVE_UNISTD_H)
  311. add_definitions(-DYY_NO_UNISTD_H)
  312. endif(NOT HAVE_UNISTD_H)
  313. check_include_file(bitypes.h HAVE_SYS_BITYPES_H)
  314. if(NOT WIN32)
  315. check_include_file(sys/ioccom.h HAVE_SYS_IOCCOM_H)
  316. check_include_file(sys/sockio.h HAVE_SYS_SOCKIO_H)
  317. check_include_file(sys/select.h HAVE_SYS_SELECT_H)
  318. endif(NOT WIN32)
  319. check_include_file(limits.h HAVE_LIMITS_H)
  320. if(NOT WIN32)
  321. check_include_file(netpacket/packet.h HAVE_NETPACKET_PACKET_H)
  322. check_include_files("sys/types.h;sys/socket.h;net/if.h;net/pfvar.h" HAVE_NET_PFVAR_H)
  323. if(HAVE_NET_PFVAR_H)
  324. #
  325. # Check for various PF actions.
  326. #
  327. check_c_source_compiles(
  328. "#include <sys/types.h>
  329. #include <sys/socket.h>
  330. #include <net/if.h>
  331. #include <net/pfvar.h>
  332. int
  333. main(void)
  334. {
  335. return PF_NAT+PF_NONAT+PF_BINAT+PF_NOBINAT+PF_RDR+PF_NORDR;
  336. }
  337. "
  338. HAVE_PF_NAT_THROUGH_PF_NORDR)
  339. endif(HAVE_NET_PFVAR_H)
  340. check_include_file(netinet/if_ether.h HAVE_NETINET_IF_ETHER_H)
  341. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  342. check_include_file(linux/sockios.h HAVE_LINUX_SOCKIOS_H)
  343. #
  344. # linux/if_bonding.h requires sys/socket.h.
  345. #
  346. check_include_files("sys/socket.h;linux/if_bonding.h" HAVE_LINUX_IF_BONDING_H)
  347. endif()
  348. endif(NOT WIN32)
  349. #
  350. # Functions.
  351. #
  352. check_function_exists(strerror HAVE_STRERROR)
  353. check_function_exists(strerror_r HAVE_STRERROR_R)
  354. check_function_exists(strerror_s HAVE_STRERROR_S)
  355. check_function_exists(strlcpy HAVE_STRLCPY)
  356. check_function_exists(strlcat HAVE_STRLCAT)
  357. check_function_exists(snprintf HAVE_SNPRINTF)
  358. check_function_exists(vsnprintf HAVE_VSNPRINTF)
  359. check_function_exists(strtok_r HAVE_STRTOK_R)
  360. #
  361. # These tests are for network applications that need socket functions
  362. # and getaddrinfo()/getnameinfo()-ish functions. We now require
  363. # getaddrinfo() and getnameinfo(). On UN*X systems, we also prefer
  364. # versions of recvmsg() that conform to the Single UNIX Specification,
  365. # so that we can check whether a datagram received with recvmsg() was
  366. # truncated when received due to the buffer being too small.
  367. #
  368. # On Windows, getaddrinfo() is in the ws2_32 library.
  369. # On most UN*X systems, they're available in the system library.
  370. #
  371. # Under Solaris, we need to link with libsocket and libnsl to get
  372. # getaddrinfo() and getnameinfo() and, if we have libxnet, we need to
  373. # link with libxnet before libsocket to get a version of recvmsg()
  374. # that conforms to the Single UNIX Specification.
  375. #
  376. # We use getaddrinfo() because we want a portable thread-safe way
  377. # of getting information for a host name or port; there exist _r
  378. # versions of gethostbyname() and getservbyname() on some platforms,
  379. # but not on all platforms.
  380. #
  381. # NOTE: if you hand check_library_exists as its last argument a variable
  382. # that's been set, it skips the test, so we need different variables.
  383. #
  384. set(PCAP_LINK_LIBRARIES "")
  385. include(CheckLibraryExists)
  386. include(CheckSymbolExists)
  387. if(WIN32)
  388. #
  389. # We need winsock2.h and ws2tcpip.h.
  390. #
  391. cmake_push_check_state()
  392. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  393. check_symbol_exists(getaddrinfo "winsock2.h;ws2tcpip.h" LIBWS2_32_HAS_GETADDRINFO)
  394. cmake_pop_check_state()
  395. if(LIBWS2_32_HAS_GETADDRINFO)
  396. set(PCAP_LINK_LIBRARIES ws2_32 ${PCAP_LINK_LIBRARIES})
  397. else(LIBWS2_32_HAS_GETADDRINFO)
  398. message(FATAL_ERROR "getaddrinfo is required, but wasn't found")
  399. endif(LIBWS2_32_HAS_GETADDRINFO)
  400. else(WIN32)
  401. #
  402. # UN*X. First try the system libraries, then try the libraries
  403. # for Solaris and possibly other systems that picked up the
  404. # System V library split.
  405. #
  406. check_function_exists(getaddrinfo STDLIBS_HAVE_GETADDRINFO)
  407. if(NOT STDLIBS_HAVE_GETADDRINFO)
  408. #
  409. # Not found in the standard system libraries.
  410. # Try libsocket, which requires libnsl.
  411. #
  412. cmake_push_check_state()
  413. set(CMAKE_REQUIRED_LIBRARIES nsl)
  414. check_library_exists(socket getaddrinfo "" LIBSOCKET_HAS_GETADDRINFO)
  415. cmake_pop_check_state()
  416. if(LIBSOCKET_HAS_GETADDRINFO)
  417. #
  418. # OK, we found it in libsocket.
  419. #
  420. set(PCAP_LINK_LIBRARIES socket nsl ${PCAP_LINK_LIBRARIES})
  421. else(LIBSOCKET_HAS_GETADDRINFO)
  422. #
  423. # We didn't find it.
  424. #
  425. message(FATAL_ERROR "getaddrinfo is required, but wasn't found")
  426. endif(LIBSOCKET_HAS_GETADDRINFO)
  427. #
  428. # OK, do we have recvmsg() in libxnet?
  429. # We also link with libsocket and libnsl.
  430. #
  431. cmake_push_check_state()
  432. set(CMAKE_REQUIRED_LIBRARIES socket nsl)
  433. check_library_exists(xnet recvmsg "" LIBXNET_HAS_RECVMSG)
  434. cmake_pop_check_state()
  435. if(LIBXNET_HAS_RECVMSG)
  436. #
  437. # Yes - link with it as well.
  438. #
  439. set(PCAP_LINK_LIBRARIES xnet ${PCAP_LINK_LIBRARIES})
  440. endif(LIBXNET_HAS_RECVMSG)
  441. endif(NOT STDLIBS_HAVE_GETADDRINFO)
  442. # DLPI needs putmsg under HPUX so test for -lstr while we're at it
  443. check_function_exists(putmsg STDLIBS_HAVE_PUTMSG)
  444. if(NOT STDLIBS_HAVE_PUTMSG)
  445. check_library_exists(str putmsg "" LIBSTR_HAS_PUTMSG)
  446. if(LIBSTR_HAS_PUTMSG)
  447. set(PCAP_LINK_LIBRARIES str ${PCAP_LINK_LIBRARIES})
  448. endif(LIBSTR_HAS_PUTMSG)
  449. endif(NOT STDLIBS_HAVE_PUTMSG)
  450. endif(WIN32)
  451. #
  452. # Check for reentrant versions of getnetbyname_r(), as provided by
  453. # Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
  454. # If we don't find one, we just use getnetbyname(), which uses
  455. # thread-specific data on many platforms, but doesn't use it on
  456. # NetBSD or OpenBSD, and may not use it on older versions of other
  457. # platforms.
  458. #
  459. # Only do the check if we have a declaration of getnetbyname_r();
  460. # without it, we can't check which API it has. (We assume that
  461. # if there's a declaration, it has a prototype, so that the API
  462. # can be checked.)
  463. #
  464. cmake_push_check_state()
  465. set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
  466. check_symbol_exists(getnetbyname_r netdb.h NETDB_H_DECLARES_GETNETBYNAME_R)
  467. if(NETDB_H_DECLARES_GETNETBYNAME_R)
  468. check_c_source_compiles(
  469. "#include <netdb.h>
  470. int
  471. main(void)
  472. {
  473. struct netent netent_buf;
  474. char buf[1024];
  475. struct netent *resultp;
  476. int h_errnoval;
  477. return getnetbyname_r((const char *)0, &netent_buf, buf, sizeof buf, &resultp, &h_errnoval);
  478. }
  479. "
  480. HAVE_LINUX_GETNETBYNAME_R)
  481. if(NOT HAVE_LINUX_GETNETBYNAME_R)
  482. check_c_source_compiles(
  483. "#include <netdb.h>
  484. int
  485. main(void)
  486. {
  487. struct netent netent_buf;
  488. char buf[1024];
  489. return getnetbyname_r((const char *)0, &netent_buf, buf, (int)sizeof buf) != NULL;
  490. }
  491. "
  492. HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
  493. if(NOT HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
  494. check_c_source_compiles(
  495. "#include <netdb.h>
  496. int
  497. main(void)
  498. {
  499. struct netent netent_buf;
  500. struct netent_data net_data;
  501. return getnetbyname_r((const char *)0, &netent_buf, &net_data);
  502. }
  503. "
  504. HAVE_AIX_GETNETBYNAME_R)
  505. endif(NOT HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
  506. endif(NOT HAVE_LINUX_GETNETBYNAME_R)
  507. endif(NETDB_H_DECLARES_GETNETBYNAME_R)
  508. cmake_pop_check_state()
  509. #
  510. # Check for reentrant versions of getprotobyname_r(), as provided by
  511. # Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
  512. # If we don't find one, we just use getprotobyname(), which uses
  513. # thread-specific data on many platforms, but doesn't use it on
  514. # NetBSD or OpenBSD, and may not use it on older versions of other
  515. # platforms.
  516. #
  517. # Only do the check if we have a declaration of getprotobyname_r();
  518. # without it, we can't check which API it has. (We assume that
  519. # if there's a declaration, it has a prototype, so that the API
  520. # can be checked.)
  521. #
  522. cmake_push_check_state()
  523. set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
  524. check_symbol_exists(getprotobyname_r netdb.h NETDB_H_DECLARES_GETPROTOBYNAME_R)
  525. if(NETDB_H_DECLARES_GETPROTOBYNAME_R)
  526. check_c_source_compiles(
  527. "#include <netdb.h>
  528. int
  529. main(void)
  530. {
  531. struct protoent protoent_buf;
  532. char buf[1024];
  533. struct protoent *resultp;
  534. return getprotobyname_r((const char *)0, &protoent_buf, buf, sizeof buf, &resultp);
  535. }
  536. "
  537. HAVE_LINUX_GETPROTOBYNAME_R)
  538. if(NOT HAVE_LINUX_GETPROTOBYNAME_R)
  539. check_c_source_compiles(
  540. "#include <netdb.h>
  541. int
  542. main(void)
  543. {
  544. struct protoent protoent_buf;
  545. char buf[1024];
  546. return getprotobyname_r((const char *)0, &protoent_buf, buf, (int)sizeof buf) != NULL;
  547. }
  548. "
  549. HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
  550. if(NOT HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
  551. check_c_source_compiles(
  552. "#include <netdb.h>
  553. int
  554. main(void)
  555. {
  556. struct protoent protoent_buf;
  557. struct protoent_data proto_data;
  558. return getprotobyname_r((const char *)0, &protoent_buf, &proto_data);
  559. }
  560. "
  561. HAVE_AIX_GETPROTOBYNAME_R)
  562. endif(NOT HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
  563. endif(NOT HAVE_LINUX_GETPROTOBYNAME_R)
  564. endif(NETDB_H_DECLARES_GETPROTOBYNAME_R)
  565. cmake_pop_check_state()
  566. #
  567. # Data types.
  568. #
  569. # XXX - there's no check_type() macro that's like check_type_size()
  570. # except that it only checks for the existence of the structure type,
  571. # so we use check_type_size() and ignore the size.
  572. #
  573. cmake_push_check_state()
  574. if(WIN32)
  575. set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
  576. else(WIN32)
  577. set(CMAKE_EXTRA_INCLUDE_FILES unistd.h sys/socket.h)
  578. endif(WIN32)
  579. check_type_size("struct sockaddr_storage" STRUCT_SOCKADDR_STORAGE)
  580. check_type_size("socklen_t" SOCKLEN_T)
  581. cmake_pop_check_state()
  582. #
  583. # Structure fields.
  584. #
  585. if(WIN32)
  586. check_struct_has_member("struct sockaddr" sa_len winsock2.h HAVE_STRUCT_SOCKADDR_SA_LEN)
  587. else(WIN32)
  588. check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_STRUCT_SOCKADDR_SA_LEN)
  589. endif(WIN32)
  590. #
  591. # Do we have ffs(), and is it declared in <strings.h>?
  592. #
  593. check_function_exists(ffs HAVE_FFS)
  594. if(HAVE_FFS)
  595. #
  596. # OK, we have ffs(). Is it declared in <strings.h>?
  597. #
  598. # This test fails if we don't have <strings.h> or if we do
  599. # but it doesn't declare ffs().
  600. #
  601. check_symbol_exists(ffs strings.h STRINGS_H_DECLARES_FFS)
  602. endif()
  603. #
  604. # This requires the libraries that we require, as ether_hostton might be
  605. # in one of those libraries. That means we have to do this after
  606. # we check for those libraries.
  607. #
  608. # You are in a twisty little maze of UN*Xes, all different.
  609. # Some might not have ether_hostton().
  610. # Some might have it and declare it in <net/ethernet.h>.
  611. # Some might have it and declare it in <netinet/ether.h>
  612. # Some might have it and declare it in <sys/ethernet.h>.
  613. # Some might have it and declare it in <arpa/inet.h>.
  614. # Some might have it and declare it in <netinet/if_ether.h>.
  615. # Some might have it and not declare it in any header file.
  616. #
  617. # Before you is a C compiler.
  618. #
  619. cmake_push_check_state()
  620. set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
  621. check_function_exists(ether_hostton HAVE_ETHER_HOSTTON)
  622. if(HAVE_ETHER_HOSTTON)
  623. #
  624. # OK, we have ether_hostton(). Is it declared in <net/ethernet.h>?
  625. #
  626. # This test fails if we don't have <net/ethernet.h> or if we do
  627. # but it doesn't declare ether_hostton().
  628. #
  629. check_symbol_exists(ether_hostton net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
  630. if(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
  631. #
  632. # Yes - we have it declared.
  633. #
  634. set(HAVE_DECL_ETHER_HOSTTON TRUE)
  635. endif()
  636. #
  637. # Did that succeed?
  638. #
  639. if(NOT HAVE_DECL_ETHER_HOSTTON)
  640. #
  641. # No - how about <netinet/ether.h>, as on Linux?
  642. #
  643. # This test fails if we don't have <netinet/ether.h>
  644. # or if we do but it doesn't declare ether_hostton().
  645. #
  646. check_symbol_exists(ether_hostton netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
  647. if(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
  648. #
  649. # Yes - we have it declared.
  650. #
  651. set(HAVE_DECL_ETHER_HOSTTON TRUE)
  652. endif()
  653. endif()
  654. #
  655. # Did that succeed?
  656. #
  657. if(NOT HAVE_DECL_ETHER_HOSTTON)
  658. #
  659. # No - how about <sys/ethernet.h>, as on Solaris 10 and later?
  660. #
  661. # This test fails if we don't have <sys/ethernet.h>
  662. # or if we do but it doesn't declare ether_hostton().
  663. #
  664. check_symbol_exists(ether_hostton sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
  665. if(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
  666. #
  667. # Yes - we have it declared.
  668. #
  669. set(HAVE_DECL_ETHER_HOSTTON TRUE)
  670. endif()
  671. endif()
  672. #
  673. # Did that succeed?
  674. #
  675. if(NOT HAVE_DECL_ETHER_HOSTTON)
  676. #
  677. # No, how about <arpa/inet.h>, as on AIX?
  678. #
  679. # This test fails if we don't have <arpa/inet.h>
  680. # or if we do but it doesn't declare ether_hostton().
  681. #
  682. check_symbol_exists(ether_hostton arpa/inet.h ARPA_INET_H_DECLARES_ETHER_HOSTTON)
  683. if(ARPA_INET_H_DECLARES_ETHER_HOSTTON)
  684. #
  685. # Yes - we have it declared.
  686. #
  687. set(HAVE_DECL_ETHER_HOSTTON TRUE)
  688. endif()
  689. endif()
  690. #
  691. # Did that succeed?
  692. #
  693. if(NOT HAVE_DECL_ETHER_HOSTTON)
  694. #
  695. # No, how about <netinet/if_ether.h>?
  696. # On some platforms, it requires <net/if.h> and
  697. # <netinet/in.h>, and we always include it with
  698. # both of them, so test it with both of them.
  699. #
  700. # This test fails if we don't have <netinet/if_ether.h>
  701. # and the headers we include before it, or if we do but
  702. # <netinet/if_ether.h> doesn't declare ether_hostton().
  703. #
  704. 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)
  705. if(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
  706. #
  707. # Yes - we have it declared.
  708. #
  709. set(HAVE_DECL_ETHER_HOSTTON TRUE)
  710. endif()
  711. endif()
  712. #
  713. # After all that, is ether_hostton() declared?
  714. #
  715. if(NOT HAVE_DECL_ETHER_HOSTTON)
  716. #
  717. # No, we'll have to declare it ourselves.
  718. # Do we have "struct ether_addr" if we include <netinet/if_ether.h>?
  719. #
  720. # XXX - there's no check_type() macro that's like check_type_size()
  721. # except that it only checks for the existence of the structure type,
  722. # so we use check_type_size() and ignore the size.
  723. #
  724. cmake_push_check_state()
  725. set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/socket.h net/if.h netinet/in.h netinet/if_ether.h)
  726. check_type_size("struct ether_addr" STRUCT_ETHER_ADDR)
  727. cmake_pop_check_state()
  728. endif()
  729. endif()
  730. cmake_pop_check_state()
  731. #
  732. # Large file support on UN*X, a/k/a LFS.
  733. #
  734. if(NOT WIN32)
  735. include(FindLFS)
  736. if(LFS_FOUND)
  737. #
  738. # Add the required #defines.
  739. #
  740. add_definitions(${LFS_DEFINITIONS})
  741. endif()
  742. #
  743. # Check for fseeko as well.
  744. #
  745. include(FindFseeko)
  746. if(FSEEKO_FOUND)
  747. set(HAVE_FSEEKO ON)
  748. #
  749. # Add the required #defines.
  750. #
  751. add_definitions(${FSEEKO_DEFINITIONS})
  752. endif()
  753. endif()
  754. if(INET6)
  755. message(STATUS "Support IPv6")
  756. endif(INET6)
  757. #
  758. # Pthreads.
  759. # We might need them, because some libraries we use might use them,
  760. # but we don't necessarily need them.
  761. # That's only on UN*X; on Windows, if they use threads, we assume
  762. # they're native Windows threads.
  763. #
  764. if(NOT WIN32)
  765. set(CMAKE_THREAD_PREFER_PTHREAD ON)
  766. find_package(Threads)
  767. if(NOT CMAKE_USE_PTHREADS_INIT)
  768. #
  769. # If it's not pthreads, we won't use it; we use it for libraries
  770. # that require it.
  771. #
  772. set(CMAKE_THREAD_LIBS_INIT "")
  773. endif(NOT CMAKE_USE_PTHREADS_INIT)
  774. endif(NOT WIN32)
  775. ######################################
  776. # Input files
  777. ######################################
  778. set(PROJECT_SOURCE_LIST_C
  779. bpf_dump.c
  780. bpf_filter.c
  781. bpf_image.c
  782. etherent.c
  783. fmtutils.c
  784. gencode.c
  785. nametoaddr.c
  786. optimize.c
  787. pcap-common.c
  788. pcap.c
  789. savefile.c
  790. sf-pcapng.c
  791. sf-pcap.c
  792. )
  793. if(WIN32)
  794. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/win_snprintf.c)
  795. else()
  796. if(NOT HAVE_SNPRINTF)
  797. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/snprintf.c)
  798. endif(NOT HAVE_SNPRINTF)
  799. if(NOT HAVE_STRTOK_R)
  800. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strtok_r.c)
  801. endif(NOT HAVE_STRTOK_R)
  802. endif(WIN32)
  803. #
  804. # Determine the main pcap-XXX.c file to use, and the libraries with
  805. # which we need to link libpcap, if any.
  806. #
  807. if(WIN32)
  808. #
  809. # Windows.
  810. #
  811. # Has the user explicitly specified a capture type?
  812. #
  813. if(PCAP_TYPE STREQUAL "")
  814. #
  815. # The user didn't explicitly specify a capture mechanism.
  816. # Check whether we have packet.dll.
  817. #
  818. if(HAVE_PACKET32)
  819. #
  820. # We have packet.dll.
  821. # Set the capture type to NPF.
  822. #
  823. set(PCAP_TYPE npf)
  824. else()
  825. #
  826. # We don't have any capture type we know about, so just use
  827. # the null capture type, and only support reading (and writing)
  828. # capture files.
  829. #
  830. set(PCAP_TYPE null)
  831. endif()
  832. endif()
  833. else()
  834. #
  835. # UN*X.
  836. #
  837. # Figure out what type of packet capture mechanism we have, and
  838. # what libraries we'd need to link libpcap with, if any.
  839. #
  840. #
  841. # Has the user explicitly specified a capture type?
  842. #
  843. if(PCAP_TYPE STREQUAL "")
  844. #
  845. # Check for a bunch of headers for various packet capture mechanisms.
  846. #
  847. check_include_files("sys/types.h;net/bpf.h" HAVE_NET_BPF_H)
  848. if(HAVE_NET_BPF_H)
  849. #
  850. # Does it define BIOCSETIF?
  851. # I.e., is it a header for an LBL/BSD-style capture
  852. # mechanism, or is it just a header for a BPF filter
  853. # engine? Some versions of Arch Linux, for example,
  854. # have a net/bpf.h that doesn't define BIOCSETIF;
  855. # as it's a Linux, it should use packet sockets,
  856. # instead.
  857. #
  858. #
  859. # We need:
  860. #
  861. # sys/types.h, because FreeBSD 10's net/bpf.h
  862. # requires that various BSD-style integer types
  863. # be defined;
  864. #
  865. # sys/ioctl.h and, if we have it, sys/ioccom.h,
  866. # because net/bpf.h defines ioctls;
  867. #
  868. # net/if.h, because it defines some structures
  869. # used in ioctls defined by net/bpf.h;
  870. #
  871. # sys/socket.h, because OpenBSD 5.9's net/bpf.h
  872. # defines some structure fields as being
  873. # struct sockaddrs;
  874. #
  875. # and net/bpf.h doesn't necessarily include all
  876. # of those headers itself.
  877. #
  878. if(HAVE_SYS_IOCCOM_H)
  879. check_symbol_exists(BIOCSETIF "sys/types.h;sys/ioctl.h;sys/socket.h;sys/ioccom.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF)
  880. else(HAVE_SYS_IOCCOM_H)
  881. check_symbol_exists(BIOCSETIF "sys/types.h;sys/ioctl.h;sys/socket.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF)
  882. endif(HAVE_SYS_IOCCOM_H)
  883. endif(HAVE_NET_BPF_H)
  884. check_include_file(net/pfilt.h HAVE_NET_PFILT_H)
  885. check_include_file(net/enet.h HAVE_NET_ENET_H)
  886. check_include_file(net/nit.h HAVE_NET_NIT_H)
  887. check_include_file(sys/net/nit.h HAVE_SYS_NET_NIT_H)
  888. check_include_file(linux/socket.h HAVE_LINUX_SOCKET_H)
  889. check_include_file(net/raw.h HAVE_NET_RAW_H)
  890. check_include_file(sys/dlpi.h HAVE_SYS_DLPI_H)
  891. if(BPF_H_DEFINES_BIOCSETIF)
  892. #
  893. # BPF.
  894. # Check this before DLPI, so that we pick BPF on
  895. # Solaris 11 and later.
  896. #
  897. set(PCAP_TYPE bpf)
  898. elseif(HAVE_LINUX_SOCKET_H)
  899. #
  900. # No prizes for guessing this one.
  901. #
  902. set(PCAP_TYPE linux)
  903. elseif(HAVE_NET_PFILT_H)
  904. #
  905. # DEC OSF/1, Digital UNIX, Tru64 UNIX
  906. #
  907. set(PCAP_TYPE pf)
  908. elseif(HAVE_NET_ENET_H)
  909. #
  910. # Stanford Enetfilter.
  911. #
  912. set(PCAP_TYPE enet)
  913. elseif(HAVE_NET_NIT_H)
  914. #
  915. # SunOS 4.x STREAMS NIT.
  916. #
  917. set(PCAP_TYPE snit)
  918. elseif(HAVE_SYS_NET_NIT_H)
  919. #
  920. # Pre-SunOS 4.x non-STREAMS NIT.
  921. #
  922. set(PCAP_TYPE nit)
  923. elseif(HAVE_NET_RAW_H)
  924. #
  925. # IRIX snoop.
  926. #
  927. set(PCAP_TYPE snoop)
  928. elseif(HAVE_SYS_DLPI_H)
  929. #
  930. # DLPI on pre-Solaris 11 SunOS 5, HP-UX, possibly others.
  931. #
  932. set(PCAP_TYPE dlpi)
  933. else()
  934. #
  935. # Nothing we support.
  936. #
  937. set(PCAP_TYPE null)
  938. endif()
  939. endif()
  940. endif(WIN32)
  941. message(STATUS "Packet capture mechanism type: ${PCAP_TYPE}")
  942. #
  943. # Do capture-mechanism-dependent tests.
  944. #
  945. if(WIN32)
  946. if(PCAP_TYPE STREQUAL "npf")
  947. #
  948. # Link with packet.dll before WinSock2.
  949. #
  950. set(PCAP_LINK_LIBRARIES ${PACKET_LIBRARIES} ${PCAP_LINK_LIBRARIES})
  951. elseif(PCAP_TYPE STREQUAL "null")
  952. else()
  953. message(ERROR "${PCAP_TYPE} is not a valid pcap type")
  954. endif()
  955. else(WIN32)
  956. if(PCAP_TYPE STREQUAL "dlpi")
  957. #
  958. # Needed for common functions used by pcap-[dlpi,libdlpi].c
  959. #
  960. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} dlpisubs.c)
  961. #
  962. # Checks for some header files.
  963. #
  964. check_include_file(sys/bufmod.h HAVE_SYS_BUFMOD_H)
  965. check_include_file(sys/dlpi_ext.h HAVE_SYS_DLPI_EXT_H)
  966. #
  967. # Checks to see if Solaris has the public libdlpi(3LIB) library.
  968. # Note: The existence of /usr/include/libdlpi.h does not mean it is the
  969. # public libdlpi(3LIB) version. Before libdlpi was made public, a
  970. # private version also existed, which did not have the same APIs.
  971. # Due to a gcc bug, the default search path for 32-bit libraries does
  972. # not include /lib, we add it explicitly here.
  973. # [http://bugs.opensolaris.org/view_bug.do?bug_id=6619485].
  974. # Also, due to the bug above applications that link to libpcap with
  975. # libdlpi will have to add "-L/lib" option to "configure".
  976. #
  977. cmake_push_check_state()
  978. set(CMAKE_REQUIRED_FLAGS "-L/lib")
  979. set(CMAKE_REQUIRED_LIBRARIES dlpi)
  980. check_function_exists(dlpi_walk HAVE_LIBDLPI)
  981. cmake_pop_check_state()
  982. if(HAVE_LIBDLPI)
  983. #
  984. # XXX - add -L/lib
  985. #
  986. set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} dlpi)
  987. set(PCAP_TYPE libdlpi)
  988. endif()
  989. #
  990. # This check is for Solaris with DLPI support for passive modes.
  991. # See dlpi(7P) for more details.
  992. #
  993. # XXX - there's no check_type() macro that's like check_type_size()
  994. # except that it only checks for the existence of the structure type,
  995. # so we use check_type_size() and ignore the size.
  996. #
  997. cmake_push_check_state()
  998. set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/dlpi.h)
  999. check_type_size(dl_passive_req_t DL_PASSIVE_REQ_T)
  1000. cmake_pop_check_state()
  1001. elseif(PCAP_TYPE STREQUAL "linux")
  1002. #
  1003. # Do we have the wireless extensions?
  1004. # linux/wireless.h requires sys/socket.h.
  1005. #
  1006. check_include_files("sys/socket.h;linux/wireless.h" HAVE_LINUX_WIRELESS_H)
  1007. #
  1008. # Do we have libnl?
  1009. #
  1010. if(BUILD_WITH_LIBNL)
  1011. #
  1012. # Try libnl 3.x first.
  1013. #
  1014. cmake_push_check_state()
  1015. set(CMAKE_REQUIRED_LIBRARIES nl-3)
  1016. check_function_exists(nl_socket_alloc HAVE_LIBNL)
  1017. cmake_pop_check_state()
  1018. if(HAVE_LIBNL)
  1019. #
  1020. # Yes, we have libnl 3.x.
  1021. #
  1022. set(PCAP_LINK_LIBRARIES nl-genl-3 nl-3 ${PCAP_LINK_LIBRARIES})
  1023. set(HAVE_LIBNL_3_x ON)
  1024. set(HAVE_LIBNL_NLE ON)
  1025. set(HAVE_LIBNL_SOCKETS ON)
  1026. include_directories("/usr/include/libnl3")
  1027. else()
  1028. #
  1029. # Try libnl 2.x.
  1030. #
  1031. cmake_push_check_state()
  1032. set(CMAKE_REQUIRED_LIBRARIES nl)
  1033. check_function_exists(nl_socket_alloc HAVE_LIBNL)
  1034. cmake_pop_check_state()
  1035. if(HAVE_LIBNL)
  1036. #
  1037. # Yes, we have libnl 2.x.
  1038. #
  1039. set(PCAP_LINK_LIBRARIES nl-genl nl ${PCAP_LINK_LIBRARIES})
  1040. set(HAVE_LIBNL_2_x ON)
  1041. set(HAVE_LIBNL_NLE ON)
  1042. set(HAVE_LIBNL_SOCKETS ON)
  1043. else()
  1044. #
  1045. # No, we don't; do we have libnl 1.x?
  1046. #
  1047. cmake_push_check_state()
  1048. set(CMAKE_REQUIRED_LIBRARIES nl)
  1049. check_function_exists(nl_handle_alloc HAVE_LIBNL)
  1050. cmake_pop_check_state()
  1051. if(HAVE_LIBNL)
  1052. set(PCAP_LINK_LIBRARIES nl ${PCAP_LINK_LIBRARIES})
  1053. endif()
  1054. endif()
  1055. endif()
  1056. endif()
  1057. check_include_file(linux/ethtool.h HAVE_LINUX_ETHTOOL_H)
  1058. #
  1059. # Checks to see if tpacket_stats is defined in linux/if_packet.h
  1060. # If so then pcap-linux.c can use this to report proper statistics.
  1061. #
  1062. # XXX - there's no check_type() macro that's like check_type_size()
  1063. # except that it only checks for the existence of the structure type,
  1064. # so we use check_type_size() and ignore the size.
  1065. #
  1066. cmake_push_check_state()
  1067. set(CMAKE_EXTRA_INCLUDE_FILES linux/if_packet.h)
  1068. check_type_size("struct tpacket_stats" STRUCT_TPACKET_STATS)
  1069. cmake_pop_check_state()
  1070. check_struct_has_member("struct tpacket_auxdata" tp_vlan_tci linux/if_packet.h HAVE_STRUCT_TPACKET_AUXDATA_TP_VLAN_TCI)
  1071. elseif(PCAP_TYPE STREQUAL "bpf")
  1072. #
  1073. # Check whether we have the *BSD-style ioctls.
  1074. #
  1075. check_include_files("sys/types.h;net/if_media.h" HAVE_NET_IF_MEDIA_H)
  1076. #
  1077. # Check whether we have struct BPF_TIMEVAL.
  1078. #
  1079. # XXX - there's no check_type() macro that's like check_type_size()
  1080. # except that it only checks for the existence of the structure type,
  1081. # so we use check_type_size() and ignore the size.
  1082. #
  1083. cmake_push_check_state()
  1084. if(HAVE_SYS_IOCCOM_H)
  1085. set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/ioccom.h net/bpf.h)
  1086. check_type_size("struct BPF_TIMEVAL" STRUCT_BPF_TIMEVAL)
  1087. else()
  1088. set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h net/bpf.h)
  1089. check_type_size("struct BPF_TIMEVAL" STRUCT_BPF_TIMEVAL)
  1090. endif()
  1091. cmake_pop_check_state()
  1092. elseif(PCAP_TYPE STREQUAL "null")
  1093. else()
  1094. message(FATAL_ERROR "${PCAP_TYPE} is not a valid pcap type")
  1095. endif()
  1096. endif(WIN32)
  1097. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-${PCAP_TYPE}.c)
  1098. #
  1099. # Now figure out how we get a list of interfaces and addresses,
  1100. # if we support capturing. Don't bother if we don't support
  1101. # capturing.
  1102. #
  1103. if(NOT WIN32)
  1104. #
  1105. # UN*X - figure out what type of interface list mechanism we
  1106. # have.
  1107. #
  1108. # If the capture type is null, that means we can't capture,
  1109. # so we can't open any capture devices, so we won't return
  1110. # any interfaces.
  1111. #
  1112. if(NOT PCAP_TYPE STREQUAL "null")
  1113. cmake_push_check_state()
  1114. set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
  1115. check_function_exists(getifaddrs HAVE_GETIFADDRS)
  1116. cmake_pop_check_state()
  1117. if(NOT HAVE_GETIFADDRS)
  1118. #
  1119. # It's not in the libraries that, at this point, we've
  1120. # found we need to link libpcap with.
  1121. #
  1122. # It's in libsocket on Solaris and possibly other OSes;
  1123. # as long as we're not linking with libxnet, check there.
  1124. #
  1125. # NOTE: if you hand check_library_exists as its last
  1126. # argument a variable that's been set, it skips the test,
  1127. # so we need different variables.
  1128. #
  1129. if(NOT LIBXNET_HAS_GETHOSTBYNAME)
  1130. check_library_exists(socket getifaddrs "" SOCKET_HAS_GETIFADDRS)
  1131. if(SOCKET_HAS_GETIFADDRS)
  1132. set(PCAP_LINK_LIBRARIES socket ${PCAP_LINK_LIBRARIES})
  1133. set(HAVE_GETIFADDRS TRUE)
  1134. endif()
  1135. endif()
  1136. endif()
  1137. if(HAVE_GETIFADDRS)
  1138. #
  1139. # We have "getifaddrs()"; make sure we have <ifaddrs.h>
  1140. # as well, just in case some platform is really weird.
  1141. # It may require that sys/types.h be included first,
  1142. # so include it first.
  1143. #
  1144. check_include_files("sys/types.h;ifaddrs.h" HAVE_IFADDRS_H)
  1145. if(HAVE_IFADDRS_H)
  1146. #
  1147. # We have the header, so we use "getifaddrs()" to
  1148. # get the list of interfaces.
  1149. #
  1150. set(FINDALLDEVS_TYPE getad)
  1151. else()
  1152. #
  1153. # We don't have the header - give up.
  1154. # XXX - we could also fall back on some other
  1155. # mechanism, but, for now, this'll catch this
  1156. # problem so that we can at least try to figure
  1157. # out something to do on systems with "getifaddrs()"
  1158. # but without "ifaddrs.h", if there is something
  1159. # we can do on those systems.
  1160. #
  1161. message(FATAL_ERROR "Your system has getifaddrs() but doesn't have a usable <ifaddrs.h>.")
  1162. endif()
  1163. else()
  1164. #
  1165. # Well, we don't have "getifaddrs()", at least not with the
  1166. # libraries with which we've decided we need to link
  1167. # libpcap with, so we have to use some other mechanism.
  1168. #
  1169. # Note that this may happen on Solaris, which has
  1170. # getifaddrs(), but in -lsocket, not in -lxnet, so we
  1171. # won't find it if we link with -lxnet, which we want
  1172. # to do for other reasons.
  1173. #
  1174. # For now, we use either the SIOCGIFCONF ioctl or the
  1175. # SIOCGLIFCONF ioctl, preferring the latter if we have
  1176. # it; the latter is a Solarisism that first appeared
  1177. # in Solaris 8. (Solaris's getifaddrs() appears to
  1178. # be built atop SIOCGLIFCONF; using it directly
  1179. # avoids a not-all-that-useful middleman.)
  1180. #
  1181. try_compile(HAVE_SIOCGLIFCONF ${CMAKE_CURRENT_BINARY_DIR} "${pcap_SOURCE_DIR}/cmake/have_siocglifconf.c" )
  1182. if(HAVE_SIOCGLIFCONF)
  1183. set(FINDALLDEVS_TYPE glifc)
  1184. else()
  1185. set(FINDALLDEVS_TYPE gifc)
  1186. endif()
  1187. endif()
  1188. message(STATUS "Find-interfaces mechanism type: ${FINDALLDEVS_TYPE}")
  1189. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} fad-${FINDALLDEVS_TYPE}.c)
  1190. endif()
  1191. endif()
  1192. # Check for hardware timestamp support.
  1193. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  1194. check_include_file(linux/net_tstamp.h HAVE_LINUX_NET_TSTAMP_H)
  1195. endif()
  1196. #
  1197. # Check for additional native sniffing capabilities.
  1198. #
  1199. # Check for USB sniffing support on Linux.
  1200. # On FreeBSD, it uses BPF, so we don't need to do anything special here.
  1201. if(NOT DISABLE_USB)
  1202. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  1203. set(PCAP_SUPPORT_USB TRUE)
  1204. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-usb-linux.c)
  1205. set(LINUX_USB_MON_DEV /dev/usbmon)
  1206. #
  1207. # Do we have a version of <linux/compiler.h> available?
  1208. # If so, we might need it for <linux/usbdevice_fs.h>.
  1209. #
  1210. check_include_files("linux/compiler.h" HAVE_LINUX_COMPILER_H)
  1211. if(HAVE_LINUX_COMPILER_H)
  1212. #
  1213. # Yes - include it when testing for <linux/usbdevice_fs.h>.
  1214. #
  1215. check_include_files("linux/compiler.h;linux/usbdevice_fs.h" HAVE_LINUX_USBDEVICE_FS_H)
  1216. else(HAVE_LINUX_COMPILER_H)
  1217. check_include_files("linux/usbdevice_fs.h" HAVE_LINUX_USBDEVICE_FS_H)
  1218. endif(HAVE_LINUX_COMPILER_H)
  1219. if(HAVE_LINUX_USBDEVICE_FS_H)
  1220. #
  1221. # OK, does it define bRequestType? Older versions of the kernel
  1222. # define fields with names like "requesttype, "request", and
  1223. # "value", rather than "bRequestType", "bRequest", and
  1224. # "wValue".
  1225. #
  1226. if(HAVE_LINUX_COMPILER_H)
  1227. check_struct_has_member("struct usbdevfs_ctrltransfer" bRequestType "linux/compiler.h;linux/usbdevice_fs.h" HAVE_STRUCT_USBDEVFS_CTRLTRANSFER_BREQUESTTYPE)
  1228. else(HAVE_LINUX_COMPILER_H)
  1229. check_struct_has_member("struct usbdevfs_ctrltransfer" bRequestType "linux/usbdevice_fs.h" HAVE_STRUCT_USBDEVFS_CTRLTRANSFER_BREQUESTTYPE)
  1230. endif(HAVE_LINUX_COMPILER_H)
  1231. endif()
  1232. endif()
  1233. endif()
  1234. # Check for netfilter sniffing support.
  1235. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  1236. #
  1237. # Life's too short to deal with trying to get this to compile
  1238. # if you don't get the right types defined with
  1239. # __KERNEL_STRICT_NAMES getting defined by some other include.
  1240. #
  1241. # Check whether the includes Just Work. If not, don't turn on
  1242. # netfilter support.
  1243. #
  1244. check_c_source_compiles(
  1245. "#include <sys/socket.h>
  1246. #include <netinet/in.h>
  1247. #include <linux/types.h>
  1248. #include <linux/netlink.h>
  1249. #include <linux/netfilter.h>
  1250. #include <linux/netfilter/nfnetlink.h>
  1251. #include <linux/netfilter/nfnetlink_log.h>
  1252. #include <linux/netfilter/nfnetlink_queue.h>
  1253. int
  1254. main(void)
  1255. {
  1256. return 0;
  1257. }
  1258. "
  1259. PCAP_SUPPORT_NETFILTER)
  1260. if(PCAP_SUPPORT_NETFILTER)
  1261. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-netfilter-linux.c)
  1262. endif(PCAP_SUPPORT_NETFILTER)
  1263. endif()
  1264. # Check for netmap sniffing support.
  1265. if(NOT DISABLE_NETMAP)
  1266. #
  1267. # Check whether net/netmap_user.h is usable if NETMAP_WITH_LIBS is
  1268. # defined; it's not usable on DragonFly BSD 4.6 if NETMAP_WITH_LIBS
  1269. # is defined, for example, as it includes a non-existent malloc.h
  1270. # header.
  1271. #
  1272. check_c_source_compiles(
  1273. "#define NETMAP_WITH_LIBS
  1274. #include <net/netmap_user.h>
  1275. int
  1276. main(void)
  1277. {
  1278. return 0;
  1279. }
  1280. "
  1281. PCAP_SUPPORT_NETMAP)
  1282. if(PCAP_SUPPORT_NETMAP)
  1283. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-netmap.c)
  1284. endif(PCAP_SUPPORT_NETMAP)
  1285. endif()
  1286. # Check for Bluetooth sniffing support
  1287. if(NOT DISABLE_BLUETOOTH)
  1288. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  1289. check_include_file(bluetooth/bluetooth.h HAVE_BLUETOOTH_BLUETOOTH_H)
  1290. if(HAVE_BLUETOOTH_BLUETOOTH_H)
  1291. set(PCAP_SUPPORT_BT TRUE)
  1292. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-bt-linux.c)
  1293. #
  1294. # OK, does struct sockaddr_hci have an hci_channel
  1295. # member?
  1296. #
  1297. check_struct_has_member("struct sockaddr_hci" hci_channel "bluetooth/bluetooth.h;bluetooth/hci.h" HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL)
  1298. if(HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL)
  1299. #
  1300. # OK, is HCI_CHANNEL_MONITOR defined?
  1301. #
  1302. check_c_source_compiles(
  1303. "#include <bluetooth/bluetooth.h>
  1304. #include <bluetooth/hci.h>
  1305. int
  1306. main(void)
  1307. {
  1308. u_int i = HCI_CHANNEL_MONITOR;
  1309. return 0;
  1310. }
  1311. "
  1312. PCAP_SUPPORT_BT_MONITOR)
  1313. if(PCAP_SUPPORT_BT_MONITOR)
  1314. #
  1315. # Yes, so we can also support Bluetooth monitor
  1316. # sniffing.
  1317. #
  1318. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-bt-monitor-linux.c)
  1319. endif(PCAP_SUPPORT_BT_MONITOR)
  1320. endif(HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL)
  1321. endif(HAVE_BLUETOOTH_BLUETOOTH_H)
  1322. endif()
  1323. endif()
  1324. # Check for Bluetooth sniffing support
  1325. if(NOT DISABLE_DBUS)
  1326. #
  1327. # We don't support D-Bus sniffing on macOS; see
  1328. #
  1329. # https://bugs.freedesktop.org/show_bug.cgi?id=74029
  1330. #
  1331. if(APPLE)
  1332. message(FATAL_ERROR "Due to freedesktop.org bug 74029, D-Bus capture support is not available on macOS")
  1333. endif(APPLE)
  1334. include(FindPkgConfig)
  1335. pkg_check_modules(DBUS dbus-1)
  1336. if(DBUS_FOUND)
  1337. set(PCAP_SUPPORT_DBUS TRUE)
  1338. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dbus.c)
  1339. include_directories(${DBUS_INCLUDE_DIRS})
  1340. set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DBUS_LIBRARIES})
  1341. endif(DBUS_FOUND)
  1342. endif(NOT DISABLE_DBUS)
  1343. # Check for RDMA sniffing support
  1344. if(NOT DISABLE_RDMA)
  1345. check_library_exists(ibverbs ibv_get_device_list "" LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
  1346. if(LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
  1347. check_include_file(infiniband/verbs.h HAVE_INFINIBAND_VERBS_H)
  1348. if(HAVE_INFINIBAND_VERBS_H)
  1349. check_symbol_exists(ibv_create_flow infiniband/verbs.h PCAP_SUPPORT_RDMASNIFF)
  1350. if(PCAP_SUPPORT_RDMASNIFF)
  1351. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-rdmasniff.c)
  1352. set(PCAP_LINK_LIBRARIES ibverbs ${PCAP_LINK_LIBRARIES})
  1353. endif(PCAP_SUPPORT_RDMASNIFF)
  1354. endif(HAVE_INFINIBAND_VERBS_H)
  1355. endif(LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
  1356. endif(NOT DISABLE_RDMA)
  1357. #
  1358. # Check for sniffing capabilities using third-party APIs.
  1359. #
  1360. # Check for Endace DAG card support.
  1361. if(NOT DISABLE_DAG)
  1362. #
  1363. # Try to find the DAG header file and library.
  1364. #
  1365. find_package(DAG)
  1366. #
  1367. # Did we succeed?
  1368. #
  1369. if(DAG_FOUND)
  1370. #
  1371. # Yes.
  1372. # Check for various DAG API functions.
  1373. #
  1374. cmake_push_check_state()
  1375. set(CMAKE_REQUIRED_INCLUDES ${DAG_INCLUDE_DIRS})
  1376. set(CMAKE_REQUIRED_LIBRARIES ${DAG_LIBRARIES})
  1377. check_function_exists(dag_attach_stream HAVE_DAG_STREAMS_API)
  1378. if(NOT HAVE_DAG_STREAMS_API)
  1379. message(FATAL_ERROR "DAG library lacks streams support")
  1380. endif()
  1381. check_function_exists(dag_attach_stream64 HAVE_DAG_LARGE_STREAMS_API)
  1382. check_function_exists(dag_get_erf_types HAVE_DAG_GET_ERF_TYPES)
  1383. check_function_exists(dag_get_stream_erf_types HAVE_DAG_GET_STREAM_ERF_TYPES)
  1384. cmake_pop_check_state()
  1385. include_directories(AFTER ${DAG_INCLUDE_DIRS})
  1386. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dag.c)
  1387. set(HAVE_DAG_API TRUE)
  1388. set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DAG_LIBRARIES})
  1389. if(HAVE_DAG_LARGE_STREAMS_API)
  1390. get_filename_component(DAG_LIBRARY_DIR ${DAG_LIBRARY} PATH)
  1391. check_library_exists(vdag vdag_set_device_info ${DAG_LIBRARY_DIR} HAVE_DAG_VDAG)
  1392. if(HAVE_DAG_VDAG)
  1393. set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  1394. endif()
  1395. endif()
  1396. endif()
  1397. endif()
  1398. # Check for Septel card support.
  1399. set(PROJECT_EXTERNAL_OBJECT_LIST "")
  1400. if(NOT DISABLE_SEPTEL)
  1401. #
  1402. # Do we have the msg.h header?
  1403. #
  1404. set(SEPTEL_INCLUDE_DIRS "${SEPTEL_ROOT}/INC")
  1405. cmake_push_check_state()
  1406. set(CMAKE_REQUIRED_INCLUDES ${SEPTEL_INCLUDE_DIRS})
  1407. check_include_file(msg.h HAVE_INC_MSG_H)
  1408. cmake_pop_check_state()
  1409. if(HAVE_INC_MSG_H)
  1410. #
  1411. # Yes.
  1412. #
  1413. include_directories(AFTER ${SEPTEL_INCLUDE_DIRS})
  1414. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-septel.c)
  1415. set(PROJECT_EXTERNAL_OBJECT_LIST ${PROJECT_EXTERNAL_OBJECT_LIST} "${SEPTEL_ROOT}/asciibin.o ${SEPTEL_ROOT}/bit2byte.o ${SEPTEL_ROOT}/confirm.o ${SEPTEL_ROOT}/fmtmsg.o ${SEPTEL_ROOT}/gct_unix.o ${SEPTEL_ROOT}/hqueue.o ${SEPTEL_ROOT}/ident.o ${SEPTEL_ROOT}/mem.o ${SEPTEL_ROOT}/pack.o ${SEPTEL_ROOT}/parse.o ${SEPTEL_ROOT}/pool.o ${SEPTEL_ROOT}/sdlsig.o ${SEPTEL_ROOT}/strtonum.o ${SEPTEL_ROOT}/timer.o ${SEPTEL_ROOT}/trace.o")
  1416. set(HAVE_SEPTEL_API TRUE)
  1417. endif()
  1418. endif()
  1419. # Check for Myricom SNF support.
  1420. if(NOT DISABLE_SNF)
  1421. #
  1422. # Try to find the SNF header file and library.
  1423. #
  1424. find_package(SNF)
  1425. #
  1426. # Did we succeed?
  1427. #
  1428. if(SNF_FOUND)
  1429. #
  1430. # Yes.
  1431. #
  1432. include_directories(AFTER ${SNF_INCLUDE_DIRS})
  1433. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-snf.c)
  1434. set(HAVE_SNF_API TRUE)
  1435. set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${SNF_LIBRARIES})
  1436. endif()
  1437. endif()
  1438. # Check for Riverbed TurboCap support.
  1439. if(NOT DISABLE_TC)
  1440. #
  1441. # Try to find the TurboCap header file and library.
  1442. #
  1443. find_package(TC)
  1444. #
  1445. # Did we succeed?
  1446. #
  1447. if(TC_FOUND)
  1448. #
  1449. # Yes.
  1450. #
  1451. include_directories(AFTER ${TC_INCLUDE_DIRS})
  1452. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-tc.c)
  1453. set(HAVE_TC_API TRUE)
  1454. set(PCAP_LINK_LIBRARIES "${PCAP_LINK_LIBRARIES} ${TC_LIBRARIES} ${CMAKE_USE_PTHREADS_INIT} stdc++")
  1455. endif()
  1456. endif()
  1457. #
  1458. # Remote capture support.
  1459. #
  1460. if(ENABLE_REMOTE)
  1461. #
  1462. # Check for various members of struct msghdr.
  1463. # We need to include ftmacros.h on some platforms, to make sure we
  1464. # get the POSIX/Single USER Specification version of struct msghdr,
  1465. # which has those members, rather than the backwards-compatible
  1466. # version, which doesn't. That's not a system header file, and
  1467. # at least some versions of CMake include it as <ftmacros.h>, which
  1468. # won't check the current directory, so we add the top-level
  1469. # source directory to the list of include directories when we do
  1470. # the check.
  1471. #
  1472. cmake_push_check_state()
  1473. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_SOURCE_DIR})
  1474. check_struct_has_member("struct msghdr" msg_control "ftmacros.h;sys/socket.h" HAVE_STRUCT_MSGHDR_MSG_CONTROL)
  1475. check_struct_has_member("struct msghdr" msg_flags "ftmacros.h;sys/socket.h" HAVE_STRUCT_MSGHDR_MSG_FLAGS)
  1476. cmake_pop_check_state()
  1477. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C}
  1478. pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c)
  1479. endif(ENABLE_REMOTE)
  1480. ###################################################################
  1481. # Warning options
  1482. ###################################################################
  1483. #
  1484. # Check and add warning options if we have a .devel file.
  1485. #
  1486. if(EXISTS ${CMAKE_SOURCE_DIR}/.devel OR EXISTS ${CMAKE_BINARY_DIR}/.devel)
  1487. #
  1488. # Warning options.
  1489. #
  1490. if(MSVC AND NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
  1491. #
  1492. # MSVC, with Microsoft's front end and code generator.
  1493. # "MSVC" is also set for Microsoft's compiler with a Clang
  1494. # front end and their code generator ("Clang/C2"), so we
  1495. # check for clang.exe and treat that differently.
  1496. #
  1497. check_and_add_compiler_option(-Wall)
  1498. #
  1499. # Disable some pointless warnings that /Wall turns on.
  1500. #
  1501. # Unfortunately, MSVC does not appear to have an equivalent
  1502. # to "__attribute__((unused))" to mark a particular function
  1503. # parameter as being known to be unused, so that the compiler
  1504. # won't warn about it (for example, the function might have
  1505. # that parameter because a pointer to it is being used, and
  1506. # the signature of that function includes that parameter).
  1507. # C++ lets you give a parameter a type but no name, but C
  1508. # doesn't have that.
  1509. #
  1510. check_and_add_compiler_option(-wd4100)
  1511. #
  1512. # In theory, we care whether somebody uses f() rather than
  1513. # f(void) to declare a function with no arguments, but, in
  1514. # practice, there are places in the Windows header files
  1515. # that appear to do that, so we squelch that warning.
  1516. #
  1517. check_and_add_compiler_option(-wd4255)
  1518. #
  1519. # Windows FD_SET() generates this, so we suppress it.
  1520. #
  1521. check_and_add_compiler_option(-wd4548)
  1522. #
  1523. # Perhaps testing something #defined to be 0 with #ifdef is an
  1524. # error, and it should be tested with #if, but perhaps it's
  1525. # not, and Microsoft does that in its headers, so we squelch
  1526. # that warning.
  1527. #
  1528. check_and_add_compiler_option(-wd4574)
  1529. #
  1530. # The Windows headers also test not-defined values in #if, so
  1531. # we don't want warnings about that, either.
  1532. #
  1533. check_and_add_compiler_option(-wd4668)
  1534. #
  1535. # We do *not* care whether some function is, or isn't, going to be
  1536. # expanded inline.
  1537. #
  1538. check_and_add_compiler_option(-wd4710)
  1539. check_and_add_compiler_option(-wd4711)
  1540. #
  1541. # We do *not* care whether we're adding padding bytes after
  1542. # structure members.
  1543. #
  1544. check_and_add_compiler_option(-wd4820)
  1545. else()
  1546. #
  1547. # Other compilers, including MSVC with a Clang front end and
  1548. # Microsoft's code generator. We currently treat them as if
  1549. # they might support GCC-style -W options.
  1550. #
  1551. check_and_add_compiler_option(-Wall)
  1552. check_and_add_compiler_option(-Wsign-compare)
  1553. check_and_add_compiler_option(-Wmissing-prototypes)
  1554. check_and_add_compiler_option(-Wstrict-prototypes)
  1555. check_and_add_compiler_option(-Wshadow)
  1556. check_and_add_compiler_option(-Wdeclaration-after-statement)
  1557. check_and_add_compiler_option(-Wused-but-marked-unused)
  1558. check_and_add_compiler_option(-Wdocumentation)
  1559. check_and_add_compiler_option(-Wcomma)
  1560. check_and_add_compiler_option(-Wmissing-noreturn)
  1561. # Warns about safeguards added in case the enums are extended
  1562. # check_and_add_compiler_option(-Wcovered-switch-default)
  1563. check_and_add_compiler_option(-Wmissing-variable-declarations)
  1564. check_and_add_compiler_option(-Wunused-parameter)
  1565. check_and_add_compiler_option(-Wformat-nonliteral)
  1566. check_and_add_compiler_option(-Wunreachable-code)
  1567. endif()
  1568. endif()
  1569. #
  1570. # Suppress some warnings we get with MSVC even without /Wall.
  1571. #
  1572. if(MSVC AND NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
  1573. #
  1574. # Yes, we have some functions that never return but that
  1575. # have a non-void return type. That's because, on some
  1576. # platforms, they *do* return values but, on other
  1577. # platforms, including Windows, they just fail and
  1578. # longjmp out by calling bpf_error().
  1579. #
  1580. check_and_add_compiler_option(-wd4646)
  1581. endif()
  1582. file(GLOB PROJECT_SOURCE_LIST_H
  1583. *.h
  1584. pcap/*.h
  1585. )
  1586. #
  1587. # Try to have the compiler default to hiding symbols, so that only
  1588. # symbols explicitly exported with PCAP_API will be visible outside
  1589. # (shared) libraries.
  1590. #
  1591. # Not necessary with MSVC, as that's the default.
  1592. #
  1593. # XXX - we don't use ADD_COMPILER_EXPORT_FLAGS, because, as of CMake
  1594. # 2.8.12.2, it doesn't know about Sun C/Oracle Studio, and, as of
  1595. # CMake 2.8.6, it only sets the C++ compiler flags, rather than
  1596. # allowing an arbitrary variable to be set with the "hide symbols
  1597. # not explicitly exported" flag.
  1598. #
  1599. if(NOT MSVC)
  1600. if(CMAKE_C_COMPILER_ID MATCHES "SunPro")
  1601. #
  1602. # Sun C/Oracle Studio.
  1603. #
  1604. check_and_add_compiler_option(-xldscope=hidden)
  1605. else()
  1606. #
  1607. # Try this for all other compilers; it's what GCC uses,
  1608. # and a number of other compilers, such as Clang and Intel C,
  1609. # use it as well.
  1610. #
  1611. check_and_add_compiler_option(-fvisibility=hidden)
  1612. endif()
  1613. endif(NOT MSVC)
  1614. #
  1615. # Flex/Lex and YACC/Berkeley YACC/Bison.
  1616. # From a mail message to the CMake mailing list by Andy Cedilnik of
  1617. # Kitware.
  1618. #
  1619. #
  1620. # Try to find Flex, a Windows version of Flex, or Lex.
  1621. #
  1622. find_program(LEX_EXECUTABLE NAMES flex win_flex lex)
  1623. if(LEX_EXECUTABLE STREQUAL "LEX_EXECUTABLE-NOTFOUND")
  1624. message(FATAL_ERROR "Neither flex nor win_flex nor lex was found.")
  1625. endif()
  1626. message(STATUS "Lexical analyzer generator: ${LEX_EXECUTABLE}")
  1627. add_custom_command(
  1628. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${CMAKE_CURRENT_BINARY_DIR}/scanner.h
  1629. SOURCE ${pcap_SOURCE_DIR}/scanner.l
  1630. COMMAND ${LEX_EXECUTABLE} -P pcap_ --header-file=scanner.h --nounput -o${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${pcap_SOURCE_DIR}/scanner.l
  1631. DEPENDS ${pcap_SOURCE_DIR}/scanner.l
  1632. )
  1633. #
  1634. # Since scanner.c does not exist yet when cmake is run, mark
  1635. # it as generated.
  1636. #
  1637. # Since scanner.c includes grammar.h, mark that as a dependency.
  1638. #
  1639. set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/scanner.c PROPERTIES
  1640. GENERATED TRUE
  1641. OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/grammar.h
  1642. )
  1643. #
  1644. # Add scanner.c to the list of sources.
  1645. #
  1646. #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/scanner.c)
  1647. #
  1648. # Try to find YACC or Bison.
  1649. #
  1650. find_program(YACC_EXECUTABLE NAMES bison win_bison byacc yacc)
  1651. if(YACC_EXECUTABLE STREQUAL "YACC_EXECUTABLE-NOTFOUND")
  1652. message(FATAL_ERROR "Neither bison nor win_bison nor byacc nor yacc was found.")
  1653. endif()
  1654. message(STATUS "Parser generator: ${YACC_EXECUTABLE}")
  1655. #
  1656. # Create custom command for the scanner.
  1657. # Find out whether it's Bison or not by looking at the last component
  1658. # of the path (without a .exe extension, if this is Windows).
  1659. #
  1660. get_filename_component(YACC_NAME ${YACC_EXECUTABLE} NAME_WE)
  1661. if("${YACC_NAME}" STREQUAL "bison" OR "${YACC_NAME}" STREQUAL "win_bison")
  1662. set(YACC_COMPATIBILITY_FLAG "-y")
  1663. endif()
  1664. add_custom_command(
  1665. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/grammar.c ${CMAKE_CURRENT_BINARY_DIR}/grammar.h
  1666. SOURCE ${pcap_SOURCE_DIR}/grammar.y
  1667. COMMAND ${YACC_EXECUTABLE} ${YACC_COMPATIBILITY_FLAG} -p pcap_ -o ${CMAKE_CURRENT_BINARY_DIR}/grammar.c -d ${pcap_SOURCE_DIR}/grammar.y
  1668. DEPENDS ${pcap_SOURCE_DIR}/grammar.y
  1669. )
  1670. #
  1671. # Since grammar.c does not exists yet when cmake is run, mark
  1672. # it as generated.
  1673. #
  1674. set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/grammar.c PROPERTIES
  1675. GENERATED TRUE
  1676. OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/scanner.h
  1677. )
  1678. #
  1679. # Add grammar.c to the list of sources.
  1680. #
  1681. #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/grammar.c)
  1682. #
  1683. # Assume, by default, no support for shared libraries and V7/BSD
  1684. # convention for man pages (file formats in section 5, miscellaneous
  1685. # info in section 7, administrative commands and daemons in section 8).
  1686. # Individual cases can override this.
  1687. #
  1688. set(MAN_FILE_FORMATS 5)
  1689. set(MAN_MISC_INFO 7)
  1690. set(MAN_ADMIN_COMMANDS 8)
  1691. if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
  1692. # Workaround to enable certain features
  1693. set(_SUN TRUE)
  1694. if(PCAP_TYPE STREQUAL "bpf")
  1695. #
  1696. # If we're using BPF, we need libodm and libcfg, as
  1697. # we use them to load the BPF module.
  1698. #
  1699. set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} odm cfg)
  1700. endif()
  1701. elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
  1702. if(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*9\.[0-9]*")
  1703. #
  1704. # HP-UX 9.x.
  1705. #
  1706. set(HAVE_HPUX9 TRUE)
  1707. elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.0")
  1708. #
  1709. # HP-UX 10.0.
  1710. #
  1711. elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.1")
  1712. #
  1713. # HP-UX 10.1.
  1714. #
  1715. else()
  1716. #
  1717. # HP-UX 10.20 and later.
  1718. #
  1719. set(HAVE_HPUX10_20_OR_LATER TRUE)
  1720. endif()
  1721. #
  1722. # Use System V conventions for man pages.
  1723. #
  1724. set(MAN_ADMIN_COMMANDS 1m)
  1725. set(MAN_FILE_FORMATS 4)
  1726. set(MAN_MISC_INFO 5)
  1727. elseif(CMAKE_SYSTEM_NAME STREQUAL "IRIX" OR CMAKE_SYSTEM_NAME STREQUAL "IRIX64")
  1728. #
  1729. # Use IRIX conventions for man pages; they're the same as the
  1730. # System V conventions, except that they use section 8 for
  1731. # administrative commands and daemons.
  1732. #
  1733. set(MAN_FILE_FORMATS 4)
  1734. set(MAN_MISC_INFO 5)
  1735. elseif(CMAKE_SYSTEM_NAME STREQUAL "OSF1")
  1736. #
  1737. # DEC OSF/1, a/k/a Digial UNIX, a/k/a Tru64 UNIX.
  1738. # Use Tru64 UNIX conventions for man pages; they're the same as the
  1739. # System V conventions except that they use section 8 for
  1740. # administrative commands and daemons.
  1741. #
  1742. set(MAN_FILE_FORMATS 4)
  1743. set(MAN_MISC_INFO 5)
  1744. elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
  1745. #
  1746. # SunOS 5.x.
  1747. #
  1748. set(HAVE_SOLARIS TRUE)
  1749. #
  1750. # Make sure errno is thread-safe, in case we're called in
  1751. # a multithreaded program. We don't guarantee that two
  1752. # threads can use the *same* pcap_t safely, but the
  1753. # current version does guarantee that you can use different
  1754. # pcap_t's in different threads, and even that pcap_compile()
  1755. # is thread-safe (it wasn't thread-safe in some older versions).
  1756. #
  1757. add_definitions(-D_TS_ERRNO)
  1758. if(CMAKE_SYSTEM_VERSION STREQUAL "5.12")
  1759. else()
  1760. #
  1761. # Use System V conventions for man pages.
  1762. #
  1763. set(MAN_ADMIN_COMMANDS 1m)
  1764. set(MAN_FILE_FORMATS 4)
  1765. set(MAN_MISC_INFO 5)
  1766. endif()
  1767. endif()
  1768. source_group("Source Files" FILES ${PROJECT_SOURCE_LIST_C})
  1769. source_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H})
  1770. if(WIN32)
  1771. #
  1772. # Add pcap-dll.rc to the list of sources.
  1773. #
  1774. set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${pcap_SOURCE_DIR}/pcap-dll.rc)
  1775. endif(WIN32)
  1776. #
  1777. # Add subdirectories after we've set various variables, so they pick up
  1778. # pick up those variables.
  1779. #
  1780. if(ENABLE_REMOTE)
  1781. add_subdirectory(rpcapd)
  1782. endif(ENABLE_REMOTE)
  1783. add_subdirectory(testprogs)
  1784. ######################################
  1785. # Register targets
  1786. ######################################
  1787. #
  1788. # Special target to serialize the building of the generated source.
  1789. #
  1790. # See
  1791. #
  1792. # http://public.kitware.com/pipermail/cmake/2013-August/055510.html
  1793. #
  1794. add_custom_target(SerializeTarget
  1795. DEPENDS
  1796. ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
  1797. ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
  1798. )
  1799. set_source_files_properties(${PROJECT_EXTERNAL_OBJECT_LIST} PROPERTIES
  1800. EXTERNAL_OBJECT TRUE)
  1801. if(BUILD_SHARED_LIBS)
  1802. add_library(${LIBRARY_NAME} SHARED
  1803. ${PROJECT_SOURCE_LIST_C}
  1804. ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
  1805. ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
  1806. ${PROJECT_EXTERNAL_OBJECT_LIST}
  1807. )
  1808. add_dependencies(${LIBRARY_NAME} SerializeTarget)
  1809. set_target_properties(${LIBRARY_NAME} PROPERTIES
  1810. COMPILE_DEFINITIONS BUILDING_PCAP)
  1811. endif(BUILD_SHARED_LIBS)
  1812. add_library(${LIBRARY_NAME}_static STATIC
  1813. ${PROJECT_SOURCE_LIST_C}
  1814. ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
  1815. ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
  1816. ${PROJECT_EXTERNAL_OBJECT_LIST}
  1817. )
  1818. add_dependencies(${LIBRARY_NAME}_static SerializeTarget)
  1819. set_target_properties(${LIBRARY_NAME}_static PROPERTIES
  1820. COMPILE_DEFINITIONS BUILDING_PCAP)
  1821. if(WIN32)
  1822. if(BUILD_SHARED_LIBS)
  1823. set_target_properties(${LIBRARY_NAME} PROPERTIES
  1824. VERSION ${PACKAGE_VERSION_NOSUFFIX} # only MAJOR and MINOR are needed
  1825. )
  1826. endif(BUILD_SHARED_LIBS)
  1827. if(MSVC)
  1828. # XXX For DLLs, the TARGET_PDB_FILE generator expression can be used to locate
  1829. # its PDB file's output directory for installation.
  1830. # cmake doesn't offer a generator expression for PDB files generated by the
  1831. # compiler (static libraries).
  1832. # So instead of considering any possible output there is (there are many),
  1833. # this will search for the PDB file in the compiler's initial output directory,
  1834. # which is always ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles\wpcap_static.dir
  1835. # regardless of architecture, build generator etc.
  1836. # Quite hackish indeed.
  1837. set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:${LIBRARY_NAME}_static>)
  1838. set_target_properties(${LIBRARY_NAME}_static PROPERTIES
  1839. COMPILE_PDB_NAME ${LIBRARY_NAME}_static
  1840. OUTPUT_NAME "${LIBRARY_NAME}_static"
  1841. )
  1842. elseif(MINGW)
  1843. #
  1844. # For compatibility, build the shared library without the "lib" prefix on
  1845. # MinGW as well.
  1846. #
  1847. set_target_properties(${LIBRARY_NAME} PROPERTIES
  1848. PREFIX ""
  1849. OUTPUT_NAME "${LIBRARY_NAME}"
  1850. )
  1851. set_target_properties(${LIBRARY_NAME}_static PROPERTIES
  1852. OUTPUT_NAME "${LIBRARY_NAME}"
  1853. )
  1854. endif()
  1855. else(WIN32) # UN*X
  1856. if(BUILD_SHARED_LIBS)
  1857. if(APPLE)
  1858. set_target_properties(${LIBRARY_NAME} PROPERTIES
  1859. VERSION ${PACKAGE_VERSION}
  1860. SOVERSION A
  1861. )
  1862. else(APPLE)
  1863. set_target_properties(${LIBRARY_NAME} PROPERTIES
  1864. VERSION ${PACKAGE_VERSION}
  1865. SOVERSION ${PACKAGE_VERSION_MAJOR}
  1866. )
  1867. endif(APPLE)
  1868. endif(BUILD_SHARED_LIBS)
  1869. set_target_properties(${LIBRARY_NAME}_static PROPERTIES
  1870. OUTPUT_NAME "${LIBRARY_NAME}"
  1871. )
  1872. endif(WIN32)
  1873. if(BUILD_SHARED_LIBS)
  1874. if(NOT C_ADDITIONAL_FLAGS STREQUAL "")
  1875. set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
  1876. endif()
  1877. target_link_libraries(${LIBRARY_NAME} ${PCAP_LINK_LIBRARIES})
  1878. endif(BUILD_SHARED_LIBS)
  1879. if(NOT C_ADDITIONAL_FLAGS STREQUAL "")
  1880. set_target_properties(${LIBRARY_NAME}_static PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
  1881. endif()
  1882. ######################################
  1883. # Write out the config.h file
  1884. ######################################
  1885. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
  1886. ######################################
  1887. # Install pcap library, include files, and man pages
  1888. ######################################
  1889. #
  1890. # "Define GNU standard installation directories", which actually
  1891. # are also defined, to some degree, by autotools, and at least
  1892. # some of which are general UN*X conventions.
  1893. #
  1894. include(GNUInstallDirs)
  1895. set(LIBRARY_NAME_STATIC ${LIBRARY_NAME}_static)
  1896. function(install_manpage_symlink SOURCE TARGET MANDIR)
  1897. if(MINGW)
  1898. find_program(LINK_EXECUTABLE ln)
  1899. if(LINK_EXECUTABLE)
  1900. set(LINK_COMMAND "\"${LINK_EXECUTABLE}\" \"-s\" \"${SOURCE}\" \"${TARGET}\"")
  1901. else(LINK_EXECUTABLE)
  1902. message(FATAL_ERROR "ln (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ln.html) not found.")
  1903. endif(LINK_EXECUTABLE)
  1904. else(MINGW)
  1905. set(LINK_COMMAND "\"${CMAKE_COMMAND}\" \"-E\" \"create_symlink\" \"${SOURCE}\" \"${TARGET}\"")
  1906. endif(MINGW)
  1907. install(CODE
  1908. "message(STATUS \"Symlinking: ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\")
  1909. execute_process(
  1910. COMMAND \"${CMAKE_COMMAND}\" \"-E\" \"remove\" \"${TARGET}\"
  1911. WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
  1912. )
  1913. execute_process(
  1914. COMMAND ${LINK_COMMAND}
  1915. WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
  1916. RESULT_VARIABLE EXIT_STATUS
  1917. )
  1918. if(NOT EXIT_STATUS EQUAL 0)
  1919. message(FATAL_ERROR \"Could not create symbolic link from ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\")
  1920. endif()
  1921. set(CMAKE_INSTALL_MANIFEST_FILES \${CMAKE_INSTALL_MANIFEST_FILES} ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${TARGET})")
  1922. endfunction(install_manpage_symlink)
  1923. set(MAN1_NOEXPAND pcap-config.1)
  1924. set(MAN3PCAP_EXPAND
  1925. pcap.3pcap.in
  1926. pcap_compile.3pcap.in
  1927. pcap_datalink.3pcap.in
  1928. pcap_dump_open.3pcap.in
  1929. pcap_get_tstamp_precision.3pcap.in
  1930. pcap_list_datalinks.3pcap.in
  1931. pcap_list_tstamp_types.3pcap.in
  1932. pcap_open_dead.3pcap.in
  1933. pcap_open_offline.3pcap.in
  1934. pcap_set_tstamp_precision.3pcap.in
  1935. pcap_set_tstamp_type.3pcap.in
  1936. )
  1937. set(MAN3PCAP_NOEXPAND
  1938. pcap_activate.3pcap
  1939. pcap_breakloop.3pcap
  1940. pcap_can_set_rfmon.3pcap
  1941. pcap_close.3pcap
  1942. pcap_create.3pcap
  1943. pcap_datalink_name_to_val.3pcap
  1944. pcap_datalink_val_to_name.3pcap
  1945. pcap_dump.3pcap
  1946. pcap_dump_close.3pcap
  1947. pcap_dump_file.3pcap
  1948. pcap_dump_flush.3pcap
  1949. pcap_dump_ftell.3pcap
  1950. pcap_file.3pcap
  1951. pcap_fileno.3pcap
  1952. pcap_findalldevs.3pcap
  1953. pcap_freecode.3pcap
  1954. pcap_get_required_select_timeout.3pcap
  1955. pcap_get_selectable_fd.3pcap
  1956. pcap_geterr.3pcap
  1957. pcap_inject.3pcap
  1958. pcap_is_swapped.3pcap
  1959. pcap_lib_version.3pcap
  1960. pcap_lookupdev.3pcap
  1961. pcap_lookupnet.3pcap
  1962. pcap_loop.3pcap
  1963. pcap_major_version.3pcap
  1964. pcap_next_ex.3pcap
  1965. pcap_offline_filter.3pcap
  1966. pcap_open_live.3pcap
  1967. pcap_set_buffer_size.3pcap
  1968. pcap_set_datalink.3pcap
  1969. pcap_set_immediate_mode.3pcap
  1970. pcap_set_promisc.3pcap
  1971. pcap_set_protocol_linux.3pcap
  1972. pcap_set_rfmon.3pcap
  1973. pcap_set_snaplen.3pcap
  1974. pcap_set_timeout.3pcap
  1975. pcap_setdirection.3pcap
  1976. pcap_setfilter.3pcap
  1977. pcap_setnonblock.3pcap
  1978. pcap_snapshot.3pcap
  1979. pcap_stats.3pcap
  1980. pcap_statustostr.3pcap
  1981. pcap_strerror.3pcap
  1982. pcap_tstamp_type_name_to_val.3pcap
  1983. pcap_tstamp_type_val_to_name.3pcap
  1984. )
  1985. set(MANFILE_EXPAND pcap-savefile.manfile.in)
  1986. set(MANMISC_EXPAND
  1987. pcap-filter.manmisc.in
  1988. pcap-linktype.manmisc.in
  1989. pcap-tstamp.manmisc.in
  1990. )
  1991. if(NOT BUILD_SHARED_LIBS)
  1992. unset(LIBRARY_NAME)
  1993. endif(NOT BUILD_SHARED_LIBS)
  1994. if(WIN32)
  1995. if(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
  1996. #
  1997. # Install 64-bit code built with MSVC in the amd64 subdirectories,
  1998. # as that's where it expects it to be.
  1999. #
  2000. install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
  2001. RUNTIME DESTINATION bin/amd64
  2002. LIBRARY DESTINATION lib/amd64
  2003. ARCHIVE DESTINATION lib/amd64)
  2004. if(NOT MINGW)
  2005. install(FILES $<TARGET_FILE_DIR:${LIBRARY_NAME_STATIC}>/${LIBRARY_NAME_STATIC}.pdb
  2006. DESTINATION bin/amd64 OPTIONAL)
  2007. if(BUILD_SHARED_LIBS)
  2008. install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}>
  2009. DESTINATION bin/amd64 OPTIONAL)
  2010. endif(BUILD_SHARED_LIBS)
  2011. endif(NOT MINGW)
  2012. else(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
  2013. #
  2014. # Install 32-bit code, and 64-bit code not built with MSVC
  2015. # in the top-level directories, as those are where they
  2016. # expect it to be.
  2017. #
  2018. install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
  2019. RUNTIME DESTINATION bin
  2020. LIBRARY DESTINATION lib
  2021. ARCHIVE DESTINATION lib)
  2022. if(NOT MINGW)
  2023. install(FILES $<TARGET_FILE_DIR:${LIBRARY_NAME_STATIC}>/${LIBRARY_NAME_STATIC}.pdb
  2024. DESTINATION bin OPTIONAL)
  2025. if(BUILD_SHARED_LIBS)
  2026. install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}>
  2027. DESTINATION bin OPTIONAL)
  2028. endif(BUILD_SHARED_LIBS)
  2029. endif(NOT MINGW)
  2030. endif(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
  2031. else(WIN32)
  2032. install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC} DESTINATION lib)
  2033. endif(WIN32)
  2034. install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pcap/ DESTINATION include/pcap)
  2035. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap.h DESTINATION include)
  2036. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap-bpf.h DESTINATION include)
  2037. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap-namedb.h DESTINATION include)
  2038. # On UN*X, and on Windows when not using MSVC, generate libpcap.pc and
  2039. # pcap-config and process man pages and arrange that they be installed.
  2040. if(NOT MSVC)
  2041. set(PACKAGE_NAME ${LIBRARY_NAME})
  2042. set(prefix ${CMAKE_INSTALL_PREFIX})
  2043. set(exec_prefix "\${prefix}")
  2044. set(includedir "\${prefix}/include")
  2045. set(libdir "\${exec_prefix}/lib")
  2046. if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
  2047. CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR
  2048. CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
  2049. CMAKE_SYSTEM_NAME STREQUAL "DragonFly BSD" OR
  2050. CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
  2051. CMAKE_SYSTEM_NAME STREQUAL "OSF1")
  2052. #
  2053. # Platforms where the linker is the GNU linker
  2054. # or accepts command-line arguments like
  2055. # those the GNU linker accepts.
  2056. #
  2057. set(V_RPATH_OPT "-Wl,-rpath,")
  2058. elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
  2059. #
  2060. # SunOS 5.x.
  2061. #
  2062. # XXX - this assumes GCC is using the Sun linker,
  2063. # rather than the GNU linker.
  2064. #
  2065. set(V_RPATH_OPT "-Wl,-R,")
  2066. else()
  2067. #
  2068. # No option needed to set the RPATH.
  2069. #
  2070. set(V_RPATH_OPT "")
  2071. endif()
  2072. set(LIBS "")
  2073. foreach(LIB ${PCAP_LINK_LIBRARIES})
  2074. set(LIBS "${LIBS} -l${LIB}")
  2075. endforeach(LIB)
  2076. configure_file(${CMAKE_SOURCE_DIR}/pcap-config.in ${CMAKE_CURRENT_BINARY_DIR}/pcap-config @ONLY)
  2077. configure_file(${CMAKE_SOURCE_DIR}/libpcap.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libpcap.pc @ONLY)
  2078. install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/pcap-config DESTINATION bin)
  2079. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpcap.pc DESTINATION lib/pkgconfig)
  2080. #
  2081. # Man pages.
  2082. #
  2083. # For each section of the manual for which we have man pages
  2084. # that require macro expansion, do the expansion.
  2085. #
  2086. set(MAN1 "")
  2087. foreach(MANPAGE ${MAN1_NOEXPAND})
  2088. set(MAN1 ${MAN1} ${CMAKE_SOURCE_DIR}/${MANPAGE})
  2089. endforeach(MANPAGE)
  2090. install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
  2091. set(MAN3PCAP "")
  2092. foreach(MANPAGE ${MAN3PCAP_NOEXPAND})
  2093. set(MAN3PCAP ${MAN3PCAP} ${CMAKE_SOURCE_DIR}/${MANPAGE})
  2094. endforeach(MANPAGE)
  2095. foreach(TEMPLATE_MANPAGE ${MAN3PCAP_EXPAND})
  2096. string(REPLACE ".in" "" MANPAGE ${TEMPLATE_MANPAGE})
  2097. configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
  2098. set(MAN3PCAP ${MAN3PCAP} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
  2099. endforeach(TEMPLATE_MANPAGE)
  2100. install(FILES ${MAN3PCAP} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
  2101. install_manpage_symlink(pcap_datalink_val_to_name.3pcap pcap_datalink_val_to_description.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2102. install_manpage_symlink(pcap_dump_open.3pcap pcap_dump_fopen.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2103. install_manpage_symlink(pcap_findalldevs.3pcap pcap_freealldevs.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2104. install_manpage_symlink(pcap_geterr.3pcap pcap_perror.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2105. install_manpage_symlink(pcap_inject.3pcap pcap_sendpacket.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2106. install_manpage_symlink(pcap_list_datalinks.3pcap pcap_free_datalinks.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2107. install_manpage_symlink(pcap_list_tstamp_types.3pcap pcap_free_tstamp_types.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2108. install_manpage_symlink(pcap_loop.3pcap pcap_dispatch.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2109. install_manpage_symlink(pcap_major_version.3pcap pcap_minor_version.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2110. install_manpage_symlink(pcap_next_ex.3pcap pcap_next.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2111. install_manpage_symlink(pcap_open_dead.3pcap pcap_open_dead_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2112. install_manpage_symlink(pcap_open_offline.3pcap pcap_open_offline_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2113. install_manpage_symlink(pcap_open_offline.3pcap pcap_fopen_offline.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2114. install_manpage_symlink(pcap_open_offline.3pcap pcap_fopen_offline_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2115. install_manpage_symlink(pcap_tstamp_type_val_to_name.3pcap pcap_tstamp_type_val_to_description.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2116. install_manpage_symlink(pcap_setnonblock.3pcap pcap_getnonblock.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
  2117. set(MANFILE "")
  2118. foreach(TEMPLATE_MANPAGE ${MANFILE_EXPAND})
  2119. string(REPLACE ".manfile.in" ".${MAN_FILE_FORMATS}" MANPAGE ${TEMPLATE_MANPAGE})
  2120. configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
  2121. set(MANFILE ${MANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
  2122. endforeach(TEMPLATE_MANPAGE)
  2123. install(FILES ${MANFILE} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_FILE_FORMATS})
  2124. set(MANMISC "")
  2125. foreach(TEMPLATE_MANPAGE ${MANMISC_EXPAND})
  2126. string(REPLACE ".manmisc.in" ".${MAN_MISC_INFO}" MANPAGE ${TEMPLATE_MANPAGE})
  2127. configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
  2128. set(MANMISC ${MANMISC} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
  2129. endforeach(TEMPLATE_MANPAGE)
  2130. install(FILES ${MANMISC} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_MISC_INFO})
  2131. endif(NOT MSVC)
  2132. # uninstall target
  2133. configure_file(
  2134. "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  2135. "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  2136. IMMEDIATE @ONLY)
  2137. add_custom_target(uninstall
  2138. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)