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