File: FindLUAJIT.cmake

package info (click to toggle)
ettercap 1:0.8.2-10
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 5,468 kB
  • ctags: 6,333
  • sloc: ansic: 47,337; yacc: 310; lex: 204; makefile: 121; xml: 31; sh: 24
file content (91 lines) | stat: -rw-r--r-- 3,288 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Copyright 2013 Ettercap Development Team.
#
# Distributed under GPL licnse.
#

# Look for the header file
FIND_PATH(LUAJIT_INCLUDE_DIR NAMES luajit.h PATH_SUFFIXES luajit-2.1 luajit-2.0 luajit)
MARK_AS_ADVANCED(LUAJIT_INCLUDE_DIR)

#Look for the library
FIND_LIBRARY(LUAJIT_LIBRARY NAMES luajit-5.1)
MARK_AS_ADVANCED(LUAJIT_LIBRARY)

# Make sure we've got an include dir.
if(NOT LUAJIT_INCLUDE_DIR)
  if(LUAJIT_FIND_REQUIRED AND NOT LUAJIT_FIND_QUIETLY)
    message(FATAL_ERROR "Could not find LUAJIT include directory.")
  endif()
  return()
endif()

if(NOT LUAJIT_LIBRARY)
  if(LUAJIT_FIND_REQUIRED AND NOT LUAJIT_FIND_QUIETLY)
    message(FATAL_ERROR "Could not find LUAJIT library.")
  endif()
  return()
endif()

#=============================================================
# _LUAJIT_GET_VERSION
# Internal function to parse the version number in luajit.h
#   _OUT_version = The version number
#   _luajit_hdr = Header file to parse
#=============================================================
function(_LUAJIT_GET_VERSION _OUT_version _luajit_hdr)
    file(READ ${_luajit_hdr} _contents)
    if(_contents)
      # Example: #define LUAJIT_VERSION_NUM      20000  /* Version 2.0.0 = 02.00.00. */
      string(REGEX REPLACE ".*#define LUAJIT_VERSION_NUM[ \t]+([0-9]+)([0-9][0-9])([0-9][0-9])[^0-9].*" "\\1.\\2.\\3" ${_OUT_version} "${_contents}")
        
        if(NOT ${_OUT_version} MATCHES "[0-9.]+")
            message(FATAL_ERROR "Version parsing failed for LUAJIT_VERSION!")
        endif()

        set(${_OUT_version} ${${_OUT_version}} PARENT_SCOPE)
    else()
        message(FATAL_ERROR "Include file ${_luajit_hdr} does not exist")
    endif()
endfunction()

if(LUAJIT_FIND_VERSION)
    set(LUAJIT_FAILED_VERSION_CHECK true)
    _LUAJIT_GET_VERSION(LUAJIT_VERSION ${LUAJIT_INCLUDE_DIR}/luajit.h)

    if(LUAJIT_FIND_VERSION_EXACT)
        if(LUAJIT_VERSION VERSION_EQUAL LUAJIT_FIND_VERSION)
            set(LUAJIT_FAILED_VERSION_CHECK false)
        endif()
    else()
        if(LUAJIT_VERSION VERSION_EQUAL   LUAJIT_FIND_VERSION OR
           LUAJIT_VERSION VERSION_GREATER LUAJIT_FIND_VERSION)
            set(LUAJIT_FAILED_VERSION_CHECK false)
        endif()
    endif()

    if(LUAJIT_FAILED_VERSION_CHECK)
        if(LUAJIT_FIND_REQUIRED AND NOT LUAJIT_FIND_QUIETLY)
            if(LUAJIT_FIND_VERSION_EXACT)
                message(FATAL_ERROR "LUAJIT version check failed.  Version ${LUAJIT_VERSION} was found, version ${LUAJIT_FIND_VERSION} is needed exactly.")
            else()
                message(FATAL_ERROR "LUAJIT version check failed.  Version ${LUAJIT_VERSION} was found, at least version ${LUAJIT_FIND_VERSION} is required")
            endif()
        endif()    
        
        # If the version check fails, exit out of the module here
        return()
    endif()
        

endif(LUAJIT_FIND_VERSION)

#handle the QUIETLY and REQUIRED arguments and set LUAJIT_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LUAJIT DEFAULT_MSG LUAJIT_LIBRARY LUAJIT_INCLUDE_DIR)

if(LUAJIT_FOUND)
	set(LUAJIT_LIBRARY ${LUAJIT_LIBRARY})
	set(LUAJIT_INCLUDE_DIR ${LUAJIT_INCLUDE_DIR})
        set(LUAJIT_VERSION ${LUAJIT_VERSION})
endif(LUAJIT_FOUND)