1*8b26181fSAndroid Build Coastguard Worker# 2*8b26181fSAndroid Build Coastguard Worker# Copyright (C) 2017 Ali Abdulkadir <[email protected]>. 3*8b26181fSAndroid Build Coastguard Worker# 4*8b26181fSAndroid Build Coastguard Worker# Permission is hereby granted, free of charge, to any person 5*8b26181fSAndroid Build Coastguard Worker# obtaining a copy of this software and associated documentation files 6*8b26181fSAndroid Build Coastguard Worker# (the "Software"), to deal in the Software without restriction, 7*8b26181fSAndroid Build Coastguard Worker# including without limitation the rights to use, copy, modify, merge, 8*8b26181fSAndroid Build Coastguard Worker# publish, distribute, sub-license, and/or sell copies of the Software, 9*8b26181fSAndroid Build Coastguard Worker# and to permit persons to whom the Software is furnished to do so, 10*8b26181fSAndroid Build Coastguard Worker# subject to the following conditions: 11*8b26181fSAndroid Build Coastguard Worker# 12*8b26181fSAndroid Build Coastguard Worker# The above copyright notice and this permission notice shall be 13*8b26181fSAndroid Build Coastguard Worker# included in all copies or substantial portions of the Software. 14*8b26181fSAndroid Build Coastguard Worker# 15*8b26181fSAndroid Build Coastguard Worker# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16*8b26181fSAndroid Build Coastguard Worker# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17*8b26181fSAndroid Build Coastguard Worker# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18*8b26181fSAndroid Build Coastguard Worker# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19*8b26181fSAndroid Build Coastguard Worker# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20*8b26181fSAndroid Build Coastguard Worker# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21*8b26181fSAndroid Build Coastguard Worker# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22*8b26181fSAndroid Build Coastguard Worker# SOFTWARE. 23*8b26181fSAndroid Build Coastguard Worker# 24*8b26181fSAndroid Build Coastguard Worker# FindPacket 25*8b26181fSAndroid Build Coastguard Worker# ========== 26*8b26181fSAndroid Build Coastguard Worker# 27*8b26181fSAndroid Build Coastguard Worker# Find the Packet library and include files. 28*8b26181fSAndroid Build Coastguard Worker# 29*8b26181fSAndroid Build Coastguard Worker# This module defines the following variables: 30*8b26181fSAndroid Build Coastguard Worker# 31*8b26181fSAndroid Build Coastguard Worker# Packet_INCLUDE_DIR - absolute path to the directory containing Packet32.h. 32*8b26181fSAndroid Build Coastguard Worker# 33*8b26181fSAndroid Build Coastguard Worker# Packet_LIBRARY - relative or absolute path to the Packet library to 34*8b26181fSAndroid Build Coastguard Worker# link with. An absolute path is will be used if the 35*8b26181fSAndroid Build Coastguard Worker# Packet library is not located in the compiler's 36*8b26181fSAndroid Build Coastguard Worker# default search path. 37*8b26181fSAndroid Build Coastguard Worker 38*8b26181fSAndroid Build Coastguard Worker# Packet_FOUND - TRUE if the Packet library *and* header are found. 39*8b26181fSAndroid Build Coastguard Worker# 40*8b26181fSAndroid Build Coastguard Worker# Hints and Backward Compatibility 41*8b26181fSAndroid Build Coastguard Worker# ================================ 42*8b26181fSAndroid Build Coastguard Worker# 43*8b26181fSAndroid Build Coastguard Worker# To tell this module where to look, a user may set the environment variable 44*8b26181fSAndroid Build Coastguard Worker# Packet_ROOT to point cmake to the *root* of a directory with include and 45*8b26181fSAndroid Build Coastguard Worker# lib subdirectories for packet.dll (e.g WpdPack or npcap-sdk). 46*8b26181fSAndroid Build Coastguard Worker# Alternatively, Packet_ROOT may also be set from cmake command line or GUI 47*8b26181fSAndroid Build Coastguard Worker# (e.g cmake -DPacket_ROOT=C:\path\to\packet [...]) 48*8b26181fSAndroid Build Coastguard Worker# 49*8b26181fSAndroid Build Coastguard Worker 50*8b26181fSAndroid Build Coastguard Worker# The 64-bit Packet.lib is located under /x64 51*8b26181fSAndroid Build Coastguard Workerif(CMAKE_SIZEOF_VOID_P EQUAL 8) 52*8b26181fSAndroid Build Coastguard Worker # 53*8b26181fSAndroid Build Coastguard Worker # For the WinPcap and Npcap SDKs, the Lib subdirectory of the top-level 54*8b26181fSAndroid Build Coastguard Worker # directory contains 32-bit libraries; the 64-bit libraries are in the 55*8b26181fSAndroid Build Coastguard Worker # Lib/x64 directory. 56*8b26181fSAndroid Build Coastguard Worker # 57*8b26181fSAndroid Build Coastguard Worker # The only way to *FORCE* CMake to look in the Lib/x64 directory 58*8b26181fSAndroid Build Coastguard Worker # without searching in the Lib directory first appears to be to set 59*8b26181fSAndroid Build Coastguard Worker # CMAKE_LIBRARY_ARCHITECTURE to "x64". 60*8b26181fSAndroid Build Coastguard Worker # 61*8b26181fSAndroid Build Coastguard Worker # In newer versions of CMake, CMAKE_LIBRARY_ARCHITECTURE is set according to 62*8b26181fSAndroid Build Coastguard Worker # the language, e.g., CMAKE_<LANG>_LIBRARY_ARCHITECTURE. So, set the new 63*8b26181fSAndroid Build Coastguard Worker # variable, CMAKE_C_LIBRARY_ARCHITECTURE, so that CMAKE_LIBRARY_ARCHITECTURE 64*8b26181fSAndroid Build Coastguard Worker # inherits the correct value. 65*8b26181fSAndroid Build Coastguard Worker # 66*8b26181fSAndroid Build Coastguard Worker set(archdetect_c_code " 67*8b26181fSAndroid Build Coastguard Worker #ifndef _M_ARM64 68*8b26181fSAndroid Build Coastguard Worker #error Not ARM64 69*8b26181fSAndroid Build Coastguard Worker #endif 70*8b26181fSAndroid Build Coastguard Worker int main() { return 0; } 71*8b26181fSAndroid Build Coastguard Worker ") 72*8b26181fSAndroid Build Coastguard Worker 73*8b26181fSAndroid Build Coastguard Worker file(WRITE "${CMAKE_BINARY_DIR}/archdetect.c" "${archdetect_c_code}") 74*8b26181fSAndroid Build Coastguard Worker try_compile( 75*8b26181fSAndroid Build Coastguard Worker IsArm64 76*8b26181fSAndroid Build Coastguard Worker "${CMAKE_BINARY_DIR}/archdetect" 77*8b26181fSAndroid Build Coastguard Worker "${CMAKE_BINARY_DIR}/archdetect.c" 78*8b26181fSAndroid Build Coastguard Worker ) 79*8b26181fSAndroid Build Coastguard Worker if(IsArm64) 80*8b26181fSAndroid Build Coastguard Worker set(CMAKE_C_LIBRARY_ARCHITECTURE "ARM64") 81*8b26181fSAndroid Build Coastguard Worker set(CMAKE_LIBRARY_ARCHITECTURE "ARM64") 82*8b26181fSAndroid Build Coastguard Worker else() 83*8b26181fSAndroid Build Coastguard Worker set(CMAKE_C_LIBRARY_ARCHITECTURE "x64") 84*8b26181fSAndroid Build Coastguard Worker set(CMAKE_LIBRARY_ARCHITECTURE "x64") 85*8b26181fSAndroid Build Coastguard Worker endif() 86*8b26181fSAndroid Build Coastguard Workerendif() 87*8b26181fSAndroid Build Coastguard Worker 88*8b26181fSAndroid Build Coastguard Worker# Find the header 89*8b26181fSAndroid Build Coastguard Workerfind_path(Packet_INCLUDE_DIR Packet32.h 90*8b26181fSAndroid Build Coastguard Worker PATH_SUFFIXES include Include 91*8b26181fSAndroid Build Coastguard Worker) 92*8b26181fSAndroid Build Coastguard Worker 93*8b26181fSAndroid Build Coastguard Worker# Find the library 94*8b26181fSAndroid Build Coastguard Workerfind_library(Packet_LIBRARY 95*8b26181fSAndroid Build Coastguard Worker NAMES Packet packet 96*8b26181fSAndroid Build Coastguard Worker) 97*8b26181fSAndroid Build Coastguard Worker 98*8b26181fSAndroid Build Coastguard Worker# Set Packet_FOUND to TRUE if Packet_INCLUDE_DIR and Packet_LIBRARY are TRUE. 99*8b26181fSAndroid Build Coastguard Workerinclude(FindPackageHandleStandardArgs) 100*8b26181fSAndroid Build Coastguard Workerfind_package_handle_standard_args(Packet 101*8b26181fSAndroid Build Coastguard Worker DEFAULT_MSG 102*8b26181fSAndroid Build Coastguard Worker Packet_INCLUDE_DIR 103*8b26181fSAndroid Build Coastguard Worker Packet_LIBRARY 104*8b26181fSAndroid Build Coastguard Worker) 105*8b26181fSAndroid Build Coastguard Worker 106*8b26181fSAndroid Build Coastguard Workermark_as_advanced(Packet_INCLUDE_DIR Packet_LIBRARY) 107*8b26181fSAndroid Build Coastguard Worker 108*8b26181fSAndroid Build Coastguard Workerset(Packet_INCLUDE_DIRS ${Packet_INCLUDE_DIR}) 109*8b26181fSAndroid Build Coastguard Workerset(Packet_LIBRARIES ${Packet_LIBRARY}) 110