view cmake/Modules/Findrpc.cmake @ 1062:f18c53022946

cmake: search for xdr functions in tirpc as well At some point in the relatively recent past, rpc/rpc.h apparently got moved from glibc to libtirpc. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Wed, 17 Apr 2024 08:34:49 -0400
parents d82835b66d5a
children
line wrap: on
line source

#
# Copyright (c) 2024 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

#
# Find the RPC includes and library.
#
# This module defines:
#   RPC_INCLUDE_DIR
#   RPC_LIBRARY
#   RPC_FOUND
#

find_path(RPC_INCLUDE_DIR rpc/rpc.h
	HINTS /usr/include/tirpc)

check_function_exists(xdr_opaque HAVE_XDR_OPAQUE)
if(HAVE_XDR_OPAQUE)
	set(RPC_LIBRARY)
	set(RPC_LIBRARY_ACTUAL libc)
else()
	foreach(lib nsl;tirpc)
		string(TOUPPER ${lib} libname)
		check_library_exists(${lib} xdr_opaque "" HAVE_${libname}_XDR_OPAQUE)
		if(HAVE_${libname}_XDR_OPAQUE)
			set(RPC_LIBRARY ${lib})
			set(RPC_LIBRARY_ACTUAL ${lib})
			break()
		endif()
	endforeach()
endif()

#
# Handle the QUIETLY and REQUIRED arguments and set RPC_FOUND to TRUE if
# all listed variables are TRUE.  We check RPC_LIBRARY_ACTUAL instead of
# RPC_LIBRARY because when we determine that we don't need any libs (i.e.,
# xdr functions are in libc), find_package_handle_standard_args would error
# out because of the empty RPC_LIBRARY.
#
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(rpc DEFAULT_MSG RPC_LIBRARY_ACTUAL
	RPC_INCLUDE_DIR)