Mercurial > libjeffpc
changeset 875:d82835b66d5a
cmake: properly check for xdr function locations
Instead of doing a quick-and-dirty check for xdr_opaque in libnsl, implement
a proper find_package module.
As a result, we can also be more correct and add an include dir for
rpc/rpc.h.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Wed, 17 Apr 2024 08:09:21 -0400 |
parents | e795a6fc02c3 |
children | f18c53022946 |
files | CMakeLists.txt cmake/Modules/Findrpc.cmake cmake/config.cmake |
diffstat | 3 files changed, 68 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Wed Apr 17 08:20:12 2024 -0400 +++ b/CMakeLists.txt Wed Apr 17 08:09:21 2024 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 2016-2020,2023 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> +# Copyright (c) 2016-2020,2023-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 @@ -146,11 +146,15 @@ ${UMEM_LIBRARY} ${EXECINFO_LIBRARY} ${SOCKET_LIBRARY} - ${XDR_LIBRARY} + ${RPC_LIBRARY} pthread ) -target_include_directories(jeffpc PRIVATE +target_include_directories(jeffpc + PUBLIC + ${RPC_INCLUDE_DIR} # uuid.h includes rpc/rpc.h + + PRIVATE ${UMEM_INCLUDE_DIR} )
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake/Modules/Findrpc.cmake Wed Apr 17 08:09:21 2024 -0400 @@ -0,0 +1,59 @@ +# +# 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) + +check_function_exists(xdr_opaque HAVE_XDR_OPAQUE) +if(HAVE_XDR_OPAQUE) + set(RPC_LIBRARY) + set(RPC_LIBRARY_ACTUAL libc) +else() + foreach(lib nsl) + 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)
--- a/cmake/config.cmake Wed Apr 17 08:20:12 2024 -0400 +++ b/cmake/config.cmake Wed Apr 17 08:09:21 2024 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 2016-2021 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> +# Copyright (c) 2016-2021,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 @@ -93,12 +93,12 @@ find_symbol(accept "socket" SOCKET_LIBRARY) find_symbol(backtrace "execinfo" EXECINFO_LIBRARY) -find_symbol(xdr_opaque "nsl" XDR_LIBRARY) include("${CMAKE_DIR}/config-gnu-ld.cmake") set(CMAKE_MODULE_PATH "${CMAKE_DIR}/Modules") find_package(umem) +find_package(rpc REQUIRED) # set a value that's "exported" into the generated config file & set up fake # but safe values when libumem is missing