Blame cmake/FindGSSAPI.cmake

Packit 1fb8d4
# - Try to find the GSS Kerberos libraries
Packit 1fb8d4
# Once done this will define
Packit 1fb8d4
#
Packit 1fb8d4
#  GSS_ROOT_DIR - Set this variable to the root installation of GSS
Packit 1fb8d4
#  GSS_ROOT_FLAVOUR - Set this variable to the flavour of Kerberos installation (MIT or Heimdal)
Packit 1fb8d4
#
Packit 1fb8d4
# Read-Only variables:
Packit 1fb8d4
#  GSS_FOUND - system has the Heimdal library
Packit 1fb8d4
#  GSS_FLAVOUR - "MIT" or "Heimdal" if anything found.
Packit 1fb8d4
#  GSS_INCLUDE_DIR - the Heimdal include directory
Packit 1fb8d4
#  GSS_LIBRARIES - The libraries needed to use GSS
Packit 1fb8d4
#  GSS_LINK_DIRECTORIES - Directories to add to linker search path
Packit 1fb8d4
#  GSS_LINKER_FLAGS - Additional linker flags
Packit 1fb8d4
#  GSS_COMPILER_FLAGS - Additional compiler flags
Packit 1fb8d4
#  GSS_VERSION - This is set to version advertised by pkg-config or read from manifest.
Packit 1fb8d4
#                In case the library is found but no version info availabe it'll be set to "unknown"
Packit 1fb8d4
Packit 1fb8d4
set(_MIT_MODNAME mit-krb5-gssapi)
Packit 1fb8d4
set(_HEIMDAL_MODNAME heimdal-gssapi)
Packit 1fb8d4
Packit 1fb8d4
include(CheckIncludeFile)
Packit 1fb8d4
include(CheckIncludeFiles)
Packit 1fb8d4
include(CheckTypeSize)
Packit 1fb8d4
Packit 1fb8d4
# export GSS_ROOT_FLAVOUR to use pkg-config system under UNIX
Packit 1fb8d4
if(UNIX)
Packit 1fb8d4
  if(NOT "$ENV{GSS_ROOT_FLAVOUR} " STREQUAL " ")
Packit 1fb8d4
    string(REGEX MATCH "^[M|m]it$" MIT_FLAVOUR "$ENV{GSS_ROOT_FLAVOUR}")
Packit 1fb8d4
    if(NOT MIT_FLAVOUR)
Packit 1fb8d4
      string(REGEX MATCH "^MIT$" MIT_FLAVOUR "$ENV{GSS_ROOT_FLAVOUR}")
Packit 1fb8d4
    endif()
Packit 1fb8d4
    string(REGEX MATCH "^[H|h]eimdal$" HEIMDAL_FLAVOUR "$ENV{GSS_ROOT_FLAVOUR}")
Packit 1fb8d4
    if(NOT HEIMDAL_FLAVOUR)
Packit 1fb8d4
      string(REGEX MATCH "^HEIMDAL$" HEIMDAL_FLAVOUR "$ENV{GSS_ROOT_FLAVOUR}")
Packit 1fb8d4
    endif()
Packit 1fb8d4
    if(MIT_FLAVOUR)
Packit 1fb8d4
      set(GSS_FLAVOUR "MIT")
Packit 1fb8d4
    elseif(HEIMDAL_FLAVOUR)
Packit 1fb8d4
      set(GSS_FLAVOUR "Heimdal")
Packit 1fb8d4
    else()
Packit 1fb8d4
      message(SEND_ERROR "Kerberos flavour unknown ($ENV{GSS_ROOT_FLAVOUR}). Choose MIT or Heimdal.")
Packit 1fb8d4
    endif()
Packit 1fb8d4
  endif()
Packit 1fb8d4
endif()
Packit 1fb8d4
Packit 1fb8d4
set(_GSS_ROOT_HINTS
Packit 1fb8d4
    "${GSS_ROOT_DIR}"
Packit 1fb8d4
    "$ENV{GSS_ROOT_DIR}"
Packit 1fb8d4
)
Packit 1fb8d4
Packit 1fb8d4
# try to find library using system pkg-config if user did not specify root dir
Packit 1fb8d4
if(UNIX)
Packit 1fb8d4
  if("$ENV{GSS_ROOT_DIR} " STREQUAL " ")
Packit 1fb8d4
    if(GSS_FLAVOUR)
Packit 1fb8d4
      find_package(PkgConfig QUIET)
Packit 1fb8d4
      if(GSS_FLAVOUR STREQUAL "MIT")
Packit 1fb8d4
        pkg_search_module(_GSS_PKG ${_MIT_MODNAME})
Packit 1fb8d4
      else()
Packit 1fb8d4
        pkg_search_module(_GSS_PKG ${_HEIMDAL_MODNAME})
Packit 1fb8d4
      endif()
Packit 1fb8d4
Packit 1fb8d4
      if("${_GSS_PKG_PREFIX} " STREQUAL " ")
Packit 1fb8d4
        if(NOT "$ENV{PKG_CONFIG_PATH} " STREQUAL " ")
Packit 1fb8d4
          list(APPEND _GSS_ROOT_HINTS "$ENV{PKG_CONFIG_PATH}")
Packit 1fb8d4
        else()
Packit 1fb8d4
          message(SEND_ERROR "pkg_search_module failed : try to set PKG_CONFIG_PATH to PREFIX_OF_KERBEROS/lib/pkgconfig")
Packit 1fb8d4
        endif()
Packit 1fb8d4
      else()
Packit 1fb8d4
	if($ENV{GSS_ROOT_FLAVOUR} STREQUAL "Heimdal")
Packit 1fb8d4
	  string(FIND "${_GSS_PKG_PREFIX}" "heimdal" PKG_HEIMDAL_PREFIX_POSITION)
Packit 1fb8d4
          if(PKG_HEIMDAL_PREFIX_POSITION STREQUAL "-1")
Packit 1fb8d4
	    message(WARNING "Try to set PKG_CONFIG_PATH to \"PREFIX_OF_KERBEROS/lib/pkgconfig\"")
Packit 1fb8d4
	  else()
Packit 1fb8d4
	    list(APPEND _GSS_ROOT_HINTS "${_GSS_PKG_PREFIX}")
Packit 1fb8d4
          endif()
Packit 1fb8d4
	else()
Packit 1fb8d4
	  list(APPEND _GSS_ROOT_HINTS "${_GSS_PKG_PREFIX}")
Packit 1fb8d4
	endif()
Packit 1fb8d4
      endif()
Packit 1fb8d4
    else()
Packit 1fb8d4
      message(WARNING "export GSS_ROOT_FLAVOUR to use pkg-config")
Packit 1fb8d4
    endif()
Packit 1fb8d4
  endif()
Packit 1fb8d4
elseif(WIN32)
Packit 1fb8d4
  list(APPEND _GSS_ROOT_HINTS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MIT\\Kerberos;InstallDir]")
Packit 1fb8d4
endif()
Packit 1fb8d4
Packit 1fb8d4
if(NOT GSS_FOUND) # not found by pkg-config. Let's take more traditional approach.
Packit 1fb8d4
  find_file(_GSS_CONFIGURE_SCRIPT
Packit 1fb8d4
      NAMES
Packit 1fb8d4
          "krb5-config"
Packit 1fb8d4
      HINTS
Packit 1fb8d4
          ${_GSS_ROOT_HINTS}
Packit 1fb8d4
      PATH_SUFFIXES
Packit 1fb8d4
          bin
Packit 1fb8d4
      NO_CMAKE_PATH
Packit 1fb8d4
      NO_CMAKE_ENVIRONMENT_PATH
Packit 1fb8d4
  )
Packit 1fb8d4
Packit 1fb8d4
  # if not found in user-supplied directories, maybe system knows better
Packit 1fb8d4
  find_file(_GSS_CONFIGURE_SCRIPT
Packit 1fb8d4
      NAMES
Packit 1fb8d4
          "krb5-config"
Packit 1fb8d4
      PATH_SUFFIXES
Packit 1fb8d4
          bin
Packit 1fb8d4
  )
Packit 1fb8d4
Packit 1fb8d4
  execute_process(
Packit 1fb8d4
       COMMAND ${_GSS_CONFIGURE_SCRIPT} "--vendor"
Packit 1fb8d4
       OUTPUT_VARIABLE _GSS_VENDOR
Packit 1fb8d4
       RESULT_VARIABLE _GSS_CONFIGURE_FAILED
Packit 1fb8d4
  )
Packit 1fb8d4
Packit 1fb8d4
  if(NOT _GSS_CONFIGURE_FAILED)
Packit 1fb8d4
    string(STRIP "${_GSS_VENDOR}" _GSS_VENDOR)
Packit 1fb8d4
    if((GSS_FLAVOUR STREQUAL "Heimdal" AND NOT _GSS_VENDOR STREQUAL "Heimdal")
Packit 1fb8d4
       OR (GSS_FLAVOUR STREQUAL "MIT" AND NOT _GSS_VENDOR STREQUAL "Massachusetts Institute of Technology"))
Packit Service 5a9772
      message(SEND_ERROR "GSS vendor and GSS flavour are not matching : _GSS_VENDOR=${_GSS_VENDOR} ; GSS_FLAVOUR=${GSS_FLAVOUR}")
Packit 1fb8d4
      message(STATUS "Try to set the path to GSS root folder in the system variable GSS_ROOT_DIR")
Packit 1fb8d4
    endif()
Packit 1fb8d4
  else()
Packit 1fb8d4
    message(SEND_ERROR "GSS configure script failed to get vendor")
Packit 1fb8d4
  endif()
Packit 1fb8d4
Packit 1fb8d4
  # NOTE: fail to link Heimdal libraries using configure script due to limitations
Packit 1fb8d4
  # during Heimdal linking process. Then, we do it "manually".
Packit 1fb8d4
  if(NOT "${_GSS_CONFIGURE_SCRIPT} " STREQUAL " " AND GSS_FLAVOUR AND NOT _GSS_VENDOR STREQUAL "Heimdal")
Packit 1fb8d4
    execute_process(
Packit 1fb8d4
          COMMAND ${_GSS_CONFIGURE_SCRIPT} "--cflags" "gssapi"
Packit 1fb8d4
          OUTPUT_VARIABLE _GSS_CFLAGS
Packit 1fb8d4
          RESULT_VARIABLE _GSS_CONFIGURE_FAILED
Packit 1fb8d4
    )
Packit 1fb8d4
Packit 1fb8d4
    if(NOT _GSS_CONFIGURE_FAILED) # 0 means success
Packit 1fb8d4
      # should also work in an odd case when multiple directories are given
Packit 1fb8d4
      string(STRIP "${_GSS_CFLAGS}" _GSS_CFLAGS)
Packit 1fb8d4
      string(REGEX REPLACE " +-I" ";" _GSS_CFLAGS "${_GSS_CFLAGS}")
Packit 1fb8d4
      string(REGEX REPLACE " +-([^I][^ \\t;]*)" ";-\\1" _GSS_CFLAGS "${_GSS_CFLAGS}")
Packit 1fb8d4
Packit 1fb8d4
      foreach(_flag ${_GSS_CFLAGS})
Packit 1fb8d4
        if(_flag MATCHES "^-I.*")
Packit 1fb8d4
          string(REGEX REPLACE "^-I" "" _val "${_flag}")
Packit 1fb8d4
          list(APPEND _GSS_INCLUDE_DIR "${_val}")
Packit 1fb8d4
        else()
Packit 1fb8d4
          list(APPEND _GSS_COMPILER_FLAGS "${_flag}")
Packit 1fb8d4
        endif()
Packit 1fb8d4
      endforeach()
Packit 1fb8d4
    endif()
Packit 1fb8d4
Packit 1fb8d4
    if(_GSS_VENDOR STREQUAL "Massachusetts Institute of Technology")
Packit 1fb8d4
      execute_process(
Packit 1fb8d4
            COMMAND ${_GSS_CONFIGURE_SCRIPT} "--libs" "gssapi"
Packit 1fb8d4
            OUTPUT_VARIABLE _GSS_LIB_FLAGS
Packit 1fb8d4
            RESULT_VARIABLE _GSS_CONFIGURE_FAILED
Packit 1fb8d4
      )
Packit 1fb8d4
    elseif(_GSS_VENDOR STREQUAL "Heimdal")
Packit 1fb8d4
      execute_process(
Packit 1fb8d4
            COMMAND ${_GSS_CONFIGURE_SCRIPT} "--deps --libs" "gssapi kafs"
Packit 1fb8d4
            OUTPUT_VARIABLE _GSS_LIB_FLAGS
Packit 1fb8d4
            RESULT_VARIABLE _GSS_CONFIGURE_FAILED
Packit 1fb8d4
      )
Packit 1fb8d4
    else()
Packit 1fb8d4
      message(SEND_ERROR "Unknown vendor")
Packit 1fb8d4
    endif()
Packit 1fb8d4
Packit 1fb8d4
    if(NOT _GSS_CONFIGURE_FAILED) # 0 means success
Packit 1fb8d4
      # this script gives us libraries and link directories. We have to deal with it.
Packit 1fb8d4
      string(STRIP "${_GSS_LIB_FLAGS}" _GSS_LIB_FLAGS)
Packit 1fb8d4
      string(REGEX REPLACE " +-(L|l)" ";-\\1" _GSS_LIB_FLAGS "${_GSS_LIB_FLAGS}")
Packit 1fb8d4
      string(REGEX REPLACE " +-([^Ll][^ \\t;]*)" ";-\\1" _GSS_LIB_FLAGS "${_GSS_LIB_FLAGS}")
Packit 1fb8d4
Packit 1fb8d4
      foreach(_flag ${_GSS_LIB_FLAGS})
Packit 1fb8d4
        if(_flag MATCHES "^-l.*")
Packit 1fb8d4
          string(REGEX REPLACE "^-l" "" _val "${_flag}")
Packit 1fb8d4
          list(APPEND _GSS_LIBRARIES "${_val}")
Packit 1fb8d4
        elseif(_flag MATCHES "^-L.*")
Packit 1fb8d4
          string(REGEX REPLACE "^-L" "" _val "${_flag}")
Packit 1fb8d4
          list(APPEND _GSS_LINK_DIRECTORIES "${_val}")
Packit 1fb8d4
        else()
Packit 1fb8d4
          list(APPEND _GSS_LINKER_FLAGS "${_flag}")
Packit 1fb8d4
        endif()
Packit 1fb8d4
      endforeach()
Packit 1fb8d4
Packit 1fb8d4
    endif()
Packit 1fb8d4
Packit 1fb8d4
    execute_process(
Packit 1fb8d4
          COMMAND ${_GSS_CONFIGURE_SCRIPT} "--version"
Packit 1fb8d4
          OUTPUT_VARIABLE _GSS_VERSION
Packit 1fb8d4
          RESULT_VARIABLE _GSS_CONFIGURE_FAILED
Packit 1fb8d4
    )
Packit 1fb8d4
Packit 1fb8d4
    # older versions may not have the "--version" parameter. In this case we just don't care.
Packit 1fb8d4
    if(_GSS_CONFIGURE_FAILED)
Packit 1fb8d4
      set(_GSS_VERSION 0)
Packit 1fb8d4
    endif()
Packit 1fb8d4
Packit 1fb8d4
  else() # either there is no config script or we are on platform that doesn't provide one (Windows?)
Packit 1fb8d4
    if(_GSS_VENDOR STREQUAL "Massachusetts Institute of Technology")
Packit 1fb8d4
      find_path(_GSS_INCLUDE_DIR
Packit 1fb8d4
               NAMES
Packit 1fb8d4
                   "gssapi/gssapi_generic.h"
Packit 1fb8d4
               HINTS
Packit 1fb8d4
                   ${_GSS_ROOT_HINTS}
Packit 1fb8d4
               PATH_SUFFIXES
Packit 1fb8d4
                   include
Packit 1fb8d4
                   inc
Packit 1fb8d4
      )
Packit 1fb8d4
Packit 1fb8d4
      if(_GSS_INCLUDE_DIR) # we've found something
Packit 1fb8d4
        set(CMAKE_REQUIRED_INCLUDES "${_GSS_INCLUDE_DIR}")
Packit 1fb8d4
        check_include_files( "gssapi/gssapi_generic.h;gssapi/gssapi_ext.h" _GSS_HAVE_MIT_HEADERS)
Packit 1fb8d4
        if(_GSS_HAVE_MIT_HEADERS)
Packit 1fb8d4
          set(GSS_FLAVOUR "MIT")
Packit 1fb8d4
        else()
Packit 1fb8d4
          message(SEND_ERROR "Try to set the Kerberos flavour (GSS_ROOT_FLAVOUR)")
Packit 1fb8d4
        endif()
Packit 1fb8d4
      elseif("$ENV{PKG_CONFIG_PATH} " STREQUAL " ")
Packit 1fb8d4
	message(WARNING "Try to set PKG_CONFIG_PATH to PREFIX_OF_KERBEROS/lib/pkgconfig")
Packit 1fb8d4
      endif()
Packit 1fb8d4
    elseif(_GSS_VENDOR STREQUAL "Heimdal")
Packit 1fb8d4
      find_path(_GSS_INCLUDE_DIR
Packit 1fb8d4
               NAMES
Packit 1fb8d4
                   "gssapi/gssapi_spnego.h"
Packit 1fb8d4
               HINTS
Packit 1fb8d4
                   ${_GSS_ROOT_HINTS}
Packit 1fb8d4
	       PATHS
Packit 1fb8d4
	           /usr/heimdal
Packit 1fb8d4
		   /usr/local/heimdal
Packit 1fb8d4
               PATH_SUFFIXES
Packit 1fb8d4
                   include
Packit 1fb8d4
                   inc
Packit 1fb8d4
      )
Packit 1fb8d4
Packit 1fb8d4
      if(_GSS_INCLUDE_DIR) # we've found something
Packit 1fb8d4
        set(CMAKE_REQUIRED_INCLUDES "${_GSS_INCLUDE_DIR}")
Packit 1fb8d4
        # prevent compiling the header - just check if we can include it
Packit 1fb8d4
        set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D__ROKEN_H__")
Packit 1fb8d4
        check_include_file( "roken.h" _GSS_HAVE_ROKEN_H)
Packit 1fb8d4
        check_include_file( "heimdal/roken.h" _GSS_HAVE_HEIMDAL_ROKEN_H)
Packit 1fb8d4
        if(_GSS_HAVE_ROKEN_H OR _GSS_HAVE_HEIMDAL_ROKEN_H)
Packit 1fb8d4
          set(GSS_FLAVOUR "Heimdal")
Packit 1fb8d4
        endif()
Packit 1fb8d4
        set(CMAKE_REQUIRED_DEFINITIONS "")
Packit 1fb8d4
      elseif("$ENV{PKG_CONFIG_PATH} " STREQUAL " ")
Packit 1fb8d4
        message(WARNING "Try to set PKG_CONFIG_PATH to PREFIX_OF_KERBEROS/lib/pkgconfig")
Packit 1fb8d4
      endif()
Packit 1fb8d4
    else()
Packit 1fb8d4
      message(SEND_ERROR "Kerberos vendor unknown (${_GSS_VENDOR})")
Packit 1fb8d4
    endif()
Packit 1fb8d4
Packit 1fb8d4
    # if we have headers, check if we can link libraries
Packit 1fb8d4
    if(GSS_FLAVOUR)
Packit 1fb8d4
      set(_GSS_LIBDIR_SUFFIXES "")
Packit 1fb8d4
      set(_GSS_LIBDIR_HINTS ${_GSS_ROOT_HINTS})
Packit 1fb8d4
      get_filename_component(_GSS_CALCULATED_POTENTIAL_ROOT "${_GSS_INCLUDE_DIR}" PATH)
Packit 1fb8d4
      list(APPEND _GSS_LIBDIR_HINTS ${_GSS_CALCULATED_POTENTIAL_ROOT})
Packit 1fb8d4
Packit 1fb8d4
      if(WIN32)
Packit 1fb8d4
        if(CMAKE_SIZEOF_VOID_P EQUAL 8)
Packit 1fb8d4
          list(APPEND _GSS_LIBDIR_SUFFIXES "lib/AMD64")
Packit 1fb8d4
          if(GSS_FLAVOUR STREQUAL "MIT")
Packit 1fb8d4
            set(_GSS_LIBNAME "gssapi64")
Packit 1fb8d4
          else()
Packit 1fb8d4
            set(_GSS_LIBNAME "libgssapi")
Packit 1fb8d4
          endif()
Packit 1fb8d4
        else()
Packit 1fb8d4
          list(APPEND _GSS_LIBDIR_SUFFIXES "lib/i386")
Packit 1fb8d4
          if(GSS_FLAVOUR STREQUAL "MIT")
Packit 1fb8d4
            set(_GSS_LIBNAME "gssapi32")
Packit 1fb8d4
          else()
Packit 1fb8d4
            set(_GSS_LIBNAME "libgssapi")
Packit 1fb8d4
          endif()
Packit 1fb8d4
        endif()
Packit 1fb8d4
      else()
Packit 1fb8d4
        list(APPEND _GSS_LIBDIR_SUFFIXES "lib;lib64;x86_64-linux-gnu") # those suffixes are not checked for HINTS
Packit 1fb8d4
        if(GSS_FLAVOUR STREQUAL "MIT")
Packit 1fb8d4
          set(_GSS_LIBNAME "gssapi_krb5")
Packit 1fb8d4
          set(_KRB5_LIBNAME "krb5")
Packit 1fb8d4
          set(_COMERR_LIBNAME "com_err")
Packit 1fb8d4
          set(_KRB5SUPPORT_LIBNAME "krb5support")
Packit 1fb8d4
        else()
Packit 1fb8d4
          set(_GSS_LIBNAME "gssapi")
Packit 1fb8d4
          set(_KRB5_LIBNAME "krb5")
Packit 1fb8d4
          set(_KAFS_LIBNAME "kafs")
Packit 1fb8d4
          set(_ROKEN_LIBNAME "roken")
Packit 1fb8d4
        endif()
Packit 1fb8d4
      endif()
Packit 1fb8d4
Packit 1fb8d4
      find_library(_GSS_LIBRARIES
Packit 1fb8d4
                  NAMES
Packit 1fb8d4
                      ${_GSS_LIBNAME}
Packit 1fb8d4
                  HINTS
Packit 1fb8d4
                      ${_GSS_LIBDIR_HINTS}
Packit 1fb8d4
                  PATH_SUFFIXES
Packit 1fb8d4
                      ${_GSS_LIBDIR_SUFFIXES}
Packit 1fb8d4
      )
Packit 1fb8d4
Packit 1fb8d4
      if(GSS_FLAVOUR STREQUAL "MIT")
Packit 1fb8d4
        find_library(_KRB5_LIBRARY
Packit 1fb8d4
                    NAMES
Packit 1fb8d4
                        ${_KRB5_LIBNAME}
Packit 1fb8d4
                    HINTS
Packit 1fb8d4
                        ${_GSS_LIBDIR_HINTS}
Packit 1fb8d4
                    PATH_SUFFIXES
Packit 1fb8d4
                        ${_GSS_LIBDIR_SUFFIXES}
Packit 1fb8d4
        )
Packit 1fb8d4
        find_library(_COMERR_LIBRARY
Packit 1fb8d4
                    NAMES
Packit 1fb8d4
                        ${_COMERR_LIBNAME}
Packit 1fb8d4
                    HINTS
Packit 1fb8d4
                        ${_GSS_LIBDIR_HINTS}
Packit 1fb8d4
                    PATH_SUFFIXES
Packit 1fb8d4
                        ${_GSS_LIBDIR_SUFFIXES}
Packit 1fb8d4
        )
Packit 1fb8d4
        find_library(_KRB5SUPPORT_LIBRARY
Packit 1fb8d4
                    NAMES
Packit 1fb8d4
                        ${_KRB5SUPPORT_LIBNAME}
Packit 1fb8d4
                    HINTS
Packit 1fb8d4
                        ${_GSS_LIBDIR_HINTS}
Packit 1fb8d4
                    PATH_SUFFIXES
Packit 1fb8d4
                        ${_GSS_LIBDIR_SUFFIXES}
Packit 1fb8d4
        )
Packit 1fb8d4
        list(APPEND _GSS_LIBRARIES ${_KRB5_LIBRARY} ${_KRB5SUPPORT_LIBRARY} ${_COMERR_LIBRARY})
Packit 1fb8d4
      endif()
Packit 1fb8d4
Packit 1fb8d4
      if(GSS_FLAVOUR STREQUAL "Heimdal")
Packit 1fb8d4
        find_library(_KRB5_LIBRARY
Packit 1fb8d4
	            NAMES
Packit 1fb8d4
                        ${_KRB5_LIBNAME}
Packit 1fb8d4
                    HINTS
Packit 1fb8d4
                        ${_GSS_LIBDIR_HINTS}
Packit 1fb8d4
                    PATH_SUFFIXES
Packit 1fb8d4
                        ${_GSS_LIBDIR_SUFFIXES}
Packit 1fb8d4
        )
Packit 1fb8d4
	find_library(_KAFS_LIBRARY
Packit 1fb8d4
		    NAMES
Packit 1fb8d4
                        ${_KAFS_LIBNAME}
Packit 1fb8d4
                    HINTS
Packit 1fb8d4
                        ${_GSS_LIBDIR_HINTS}
Packit 1fb8d4
                    PATH_SUFFIXES
Packit 1fb8d4
                        ${_GSS_LIBDIR_SUFFIXES}
Packit 1fb8d4
        )
Packit 1fb8d4
	find_library(_ROKEN_LIBRARY
Packit 1fb8d4
		    NAMES
Packit 1fb8d4
                        ${_ROKEN_LIBNAME}
Packit 1fb8d4
                    HINTS
Packit 1fb8d4
                        ${_GSS_LIBDIR_HINTS}
Packit 1fb8d4
                    PATH_SUFFIXES
Packit 1fb8d4
                        ${_GSS_LIBDIR_SUFFIXES}
Packit 1fb8d4
          )
Packit 1fb8d4
	list(APPEND _GSS_LIBRARIES ${_KRB5_LIBRARY} ${_KAFS_LIBRARY} ${_ROKEN_LIBRARY})
Packit 1fb8d4
      endif()
Packit 1fb8d4
    endif()
Packit 1fb8d4
Packit 1fb8d4
    execute_process(
Packit 1fb8d4
          COMMAND ${_GSS_CONFIGURE_SCRIPT} "--version"
Packit 1fb8d4
          OUTPUT_VARIABLE _GSS_VERSION
Packit 1fb8d4
          RESULT_VARIABLE _GSS_CONFIGURE_FAILED
Packit 1fb8d4
    )
Packit 1fb8d4
Packit 1fb8d4
    # older versions may not have the "--version" parameter. In this case we just don't care.
Packit 1fb8d4
    if(_GSS_CONFIGURE_FAILED)
Packit 1fb8d4
      set(_GSS_VERSION 0)
Packit 1fb8d4
    endif()
Packit 1fb8d4
Packit 1fb8d4
  endif()
Packit 1fb8d4
else()
Packit 1fb8d4
  if(_GSS_PKG_${_MIT_MODNAME}_VERSION)
Packit 1fb8d4
    set(GSS_FLAVOUR "MIT")
Packit 1fb8d4
    set(_GSS_VERSION _GSS_PKG_${_MIT_MODNAME}_VERSION)
Packit 1fb8d4
  else()
Packit 1fb8d4
    set(GSS_FLAVOUR "Heimdal")
Packit 1fb8d4
    set(_GSS_VERSION _GSS_PKG_${_HEIMDAL_MODNAME}_VERSION)
Packit 1fb8d4
  endif()
Packit 1fb8d4
endif()
Packit 1fb8d4
Packit 1fb8d4
set(GSS_INCLUDE_DIR ${_GSS_INCLUDE_DIR})
Packit 1fb8d4
set(GSS_LIBRARIES ${_GSS_LIBRARIES})
Packit 1fb8d4
set(GSS_LINK_DIRECTORIES ${_GSS_LINK_DIRECTORIES})
Packit 1fb8d4
set(GSS_LINKER_FLAGS ${_GSS_LINKER_FLAGS})
Packit 1fb8d4
set(GSS_COMPILER_FLAGS ${_GSS_COMPILER_FLAGS})
Packit 1fb8d4
set(GSS_VERSION ${_GSS_VERSION})
Packit 1fb8d4
Packit 1fb8d4
if(GSS_FLAVOUR)
Packit 1fb8d4
  if(NOT GSS_VERSION AND GSS_FLAVOUR STREQUAL "Heimdal")
Packit 1fb8d4
    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
Packit 1fb8d4
      set(HEIMDAL_MANIFEST_FILE "Heimdal.Application.amd64.manifest")
Packit 1fb8d4
    else()
Packit 1fb8d4
      set(HEIMDAL_MANIFEST_FILE "Heimdal.Application.x86.manifest")
Packit 1fb8d4
    endif()
Packit 1fb8d4
    if(EXISTS "${GSS_INCLUDE_DIR}/${HEIMDAL_MANIFEST_FILE}")
Packit 1fb8d4
      file(STRINGS "${GSS_INCLUDE_DIR}/${HEIMDAL_MANIFEST_FILE}" heimdal_version_str
Packit 1fb8d4
                 REGEX "^.*version=\"[0-9]\\.[^\"]+\".*$")
Packit 1fb8d4
Packit 1fb8d4
      string(REGEX MATCH "[0-9]\\.[^\"]+"
Packit 1fb8d4
                   GSS_VERSION "${heimdal_version_str}")
Packit 1fb8d4
    endif()
Packit 1fb8d4
    if(NOT GSS_VERSION)
Packit 1fb8d4
      set(GSS_VERSION "Heimdal Unknown")
Packit 1fb8d4
    endif()
Packit 1fb8d4
  elseif(NOT GSS_VERSION AND GSS_FLAVOUR STREQUAL "MIT")
Packit 1fb8d4
    get_filename_component(_MIT_VERSION "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MIT\\Kerberos\\SDK\\CurrentVersion;VersionString]" NAME CACHE)
Packit 1fb8d4
    if(WIN32 AND _MIT_VERSION)
Packit 1fb8d4
      set(GSS_VERSION "${_MIT_VERSION}")
Packit 1fb8d4
    else()
Packit 1fb8d4
      set(GSS_VERSION "MIT Unknown")
Packit 1fb8d4
    endif()
Packit 1fb8d4
  endif()
Packit 1fb8d4
endif()
Packit 1fb8d4
Packit 1fb8d4
include(FindPackageHandleStandardArgs)
Packit 1fb8d4
Packit 1fb8d4
set(_GSS_REQUIRED_VARS GSS_LIBRARIES GSS_FLAVOUR)
Packit 1fb8d4
Packit 1fb8d4
find_package_handle_standard_args(GSS
Packit 1fb8d4
    REQUIRED_VARS
Packit 1fb8d4
        ${_GSS_REQUIRED_VARS}
Packit 1fb8d4
    VERSION_VAR
Packit 1fb8d4
        GSS_VERSION
Packit 1fb8d4
    FAIL_MESSAGE
Packit 1fb8d4
        "Could NOT find GSS, try to set the path to GSS root folder in the system variable GSS_ROOT_DIR"
Packit 1fb8d4
)
Packit 1fb8d4
Packit 1fb8d4
if(GSS_FLAVOUR STREQUAL "MIT")
Packit 1fb8d4
  string(STRIP "${GSS_VERSION}" GSS_VERSION)
Packit 1fb8d4
  string(SUBSTRING ${GSS_VERSION} 19 -1 GSS_RELEASE_NUMBER)
Packit 1fb8d4
  string(REGEX MATCH "([0-9]+)\\." GSS_VERSION_MAJOR ${GSS_RELEASE_NUMBER})
Packit 1fb8d4
  string(REGEX REPLACE "\\." "" GSS_VERSION_MAJOR "${GSS_VERSION_MAJOR}")
Packit 1fb8d4
  string(REGEX MATCH "\\.([0-9]+)$" GSS_VERSION_MINOR ${GSS_RELEASE_NUMBER})
Packit 1fb8d4
  if(NOT GSS_VERSION_MINOR)
Packit Service 5a9772
    string(REGEX MATCH "\\.([0-9]+)[-\\.]" GSS_VERSION_MINOR ${GSS_RELEASE_NUMBER})
Packit Service 5a9772
    string(REGEX REPLACE "\\." ""     GSS_VERSION_MINOR "${GSS_VERSION_MINOR}")
Packit Service 5a9772
    string(REGEX REPLACE "\\." ""     GSS_VERSION_MINOR "${GSS_VERSION_MINOR}")
Packit Service 5a9772
    string(REGEX REPLACE "-"   ""     GSS_VERSION_MINOR "${GSS_VERSION_MINOR}")
Packit Service 5a9772
    string(REGEX MATCH "\\.([0-9]+)$" GSS_VERSION_PATCH "${GSS_RELEASE_NUMBER}")
Packit Service 5a9772
    string(REGEX REPLACE "\\." ""     GSS_VERSION_PATCH "${GSS_VERSION_PATCH}")
Packit Service 5a9772
    if(NOT GSS_VERSION_PATCH)
Packit Service 5a9772
      set(GSS_VERSION_PATCH "0")
Packit Service 5a9772
    endif()
Packit 1fb8d4
  else()
Packit Service 5a9772
    string(REGEX REPLACE "\\." ""     GSS_VERSION_MINOR "${GSS_VERSION_MINOR}")
Packit 1fb8d4
    set(GSS_VERSION_PATCH "0")
Packit 1fb8d4
  endif()
Packit 1fb8d4
  if(GSS_VERSION_MAJOR AND GSS_VERSION_MINOR)
Packit 1fb8d4
    string(COMPARE GREATER ${GSS_VERSION_MAJOR} 0 GSS_VERSION_1)
Packit 1fb8d4
    string(COMPARE GREATER ${GSS_VERSION_MINOR} 12 GSS_VERSION_1_13)
Packit 1fb8d4
  else()
Packit 1fb8d4
    message(SEND_ERROR "Failed to retrieved Kerberos version number")
Packit 1fb8d4
  endif()
Packit Service 5a9772
  message(STATUS "Located Kerberos ${GSS_VERSION_MAJOR}.${GSS_VERSION_MINOR}.${GSS_VERSION_PATCH}")
Packit 1fb8d4
endif()
Packit 1fb8d4
Packit 1fb8d4
mark_as_advanced(GSS_INCLUDE_DIR GSS_LIBRARIES)