19185e895Schristos# 29185e895Schristos# Copyright (C) 2017 Ali Abdulkadir <autostart.ini@gmail.com>. 39185e895Schristos# 49185e895Schristos# Permission is hereby granted, free of charge, to any person 59185e895Schristos# obtaining a copy of this software and associated documentation files 69185e895Schristos# (the "Software"), to deal in the Software without restriction, 79185e895Schristos# including without limitation the rights to use, copy, modify, merge, 89185e895Schristos# publish, distribute, sub-license, and/or sell copies of the Software, 99185e895Schristos# and to permit persons to whom the Software is furnished to do so, 109185e895Schristos# subject to the following conditions: 119185e895Schristos# 129185e895Schristos# The above copyright notice and this permission notice shall be 139185e895Schristos# included in all copies or substantial portions of the Software. 149185e895Schristos# 159185e895Schristos# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 169185e895Schristos# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 179185e895Schristos# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 189185e895Schristos# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 199185e895Schristos# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 209185e895Schristos# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 219185e895Schristos# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 229185e895Schristos# SOFTWARE. 239185e895Schristos# 249185e895Schristos# FindPacket 259185e895Schristos# ========== 269185e895Schristos# 279185e895Schristos# Find the Packet library and include files. 289185e895Schristos# 299185e895Schristos# This module defines the following variables: 309185e895Schristos# 31*748408edSchristos# Packet_INCLUDE_DIR - absolute path to the directory containing Packet32.h. 329185e895Schristos# 33*748408edSchristos# Packet_LIBRARY - relative or absolute path to the Packet library to 349185e895Schristos# link with. An absolute path is will be used if the 359185e895Schristos# Packet library is not located in the compiler's 36*748408edSchristos# default search path. 379185e895Schristos 38*748408edSchristos# Packet_FOUND - TRUE if the Packet library *and* header are found. 399185e895Schristos# 409185e895Schristos# Hints and Backward Compatibility 419185e895Schristos# ================================ 429185e895Schristos# 439185e895Schristos# To tell this module where to look, a user may set the environment variable 44*748408edSchristos# Packet_ROOT to point cmake to the *root* of a directory with include and 45*748408edSchristos# lib subdirectories for packet.dll (e.g WpdPack or npcap-sdk). 46*748408edSchristos# Alternatively, Packet_ROOT may also be set from cmake command line or GUI 47*748408edSchristos# (e.g cmake -DPacket_ROOT=C:\path\to\packet [...]) 489185e895Schristos# 499185e895Schristos 509185e895Schristos# The 64-bit Packet.lib is located under /x64 519185e895Schristosif(CMAKE_SIZEOF_VOID_P EQUAL 8) 524a71e5f3Schristos # 534a71e5f3Schristos # For the WinPcap and Npcap SDKs, the Lib subdirectory of the top-level 544a71e5f3Schristos # directory contains 32-bit libraries; the 64-bit libraries are in the 554a71e5f3Schristos # Lib/x64 directory. 564a71e5f3Schristos # 574a71e5f3Schristos # The only way to *FORCE* CMake to look in the Lib/x64 directory 584a71e5f3Schristos # without searching in the Lib directory first appears to be to set 594a71e5f3Schristos # CMAKE_LIBRARY_ARCHITECTURE to "x64". 604a71e5f3Schristos # 61*748408edSchristos # In newer versions of CMake, CMAKE_LIBRARY_ARCHITECTURE is set according to 62*748408edSchristos # the language, e.g., CMAKE_<LANG>_LIBRARY_ARCHITECTURE. So, set the new 63*748408edSchristos # variable, CMAKE_C_LIBRARY_ARCHITECTURE, so that CMAKE_LIBRARY_ARCHITECTURE 64*748408edSchristos # inherits the correct value. 65*748408edSchristos # 66*748408edSchristos set(archdetect_c_code " 67*748408edSchristos #ifndef _M_ARM64 68*748408edSchristos #error Not ARM64 69*748408edSchristos #endif 70*748408edSchristos int main() { return 0; } 71*748408edSchristos ") 72*748408edSchristos 73*748408edSchristos file(WRITE "${CMAKE_BINARY_DIR}/archdetect.c" "${archdetect_c_code}") 74*748408edSchristos try_compile( 75*748408edSchristos IsArm64 76*748408edSchristos "${CMAKE_BINARY_DIR}/archdetect" 77*748408edSchristos "${CMAKE_BINARY_DIR}/archdetect.c" 78*748408edSchristos ) 79*748408edSchristos if(IsArm64) 80*748408edSchristos set(CMAKE_C_LIBRARY_ARCHITECTURE "ARM64") 81*748408edSchristos set(CMAKE_LIBRARY_ARCHITECTURE "ARM64") 82*748408edSchristos else() 83*748408edSchristos set(CMAKE_C_LIBRARY_ARCHITECTURE "x64") 844a71e5f3Schristos set(CMAKE_LIBRARY_ARCHITECTURE "x64") 859185e895Schristos endif() 86*748408edSchristosendif() 879185e895Schristos 889185e895Schristos# Find the header 89*748408edSchristosfind_path(Packet_INCLUDE_DIR Packet32.h 909185e895Schristos PATH_SUFFIXES include Include 919185e895Schristos) 929185e895Schristos 939185e895Schristos# Find the library 94*748408edSchristosfind_library(Packet_LIBRARY 959185e895Schristos NAMES Packet packet 969185e895Schristos) 979185e895Schristos 98*748408edSchristos# Set Packet_FOUND to TRUE if Packet_INCLUDE_DIR and Packet_LIBRARY are TRUE. 999185e895Schristosinclude(FindPackageHandleStandardArgs) 100*748408edSchristosfind_package_handle_standard_args(Packet 1019185e895Schristos DEFAULT_MSG 102*748408edSchristos Packet_INCLUDE_DIR 103*748408edSchristos Packet_LIBRARY 1049185e895Schristos) 1059185e895Schristos 106*748408edSchristosmark_as_advanced(Packet_INCLUDE_DIR Packet_LIBRARY) 1079185e895Schristos 108*748408edSchristosset(Packet_INCLUDE_DIRS ${Packet_INCLUDE_DIR}) 109*748408edSchristosset(Packet_LIBRARIES ${Packet_LIBRARY}) 110