4 # Finds the libnfs library
6 # This will define the following variables::
8 # NFS_FOUND - system has libnfs
9 # NFS_INCLUDE_DIRS - the libnfs include directory
10 # NFS_LIBRARIES - the libnfs libraries
11 # NFS_DEFINITIONS - the libnfs compile definitions
13 # and the following imported targets::
15 # NFS::NFS - The libnfs library
17 include(cmake/scripts/common/ModuleHelpers.cmake)
23 # Search for cmake config. Suitable for all platforms including windows
24 find_package(LIBNFS CONFIG QUIET)
27 if(ENABLE_INTERNAL_NFS)
28 set(CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF
30 -DENABLE_DOCUMENTATION=OFF
32 -DENABLE_EXAMPLES=OFF)
36 set(NFS_LIBRARY ${${MODULE}_LIBRARY})
37 set(NFS_INCLUDE_DIR ${${MODULE}_INCLUDE_DIR})
39 # Try pkgconfig based search. Linux may not have a version with cmake config installed
41 pkg_check_modules(PC_NFS libnfs>=3.0.0 QUIET)
44 find_path(NFS_INCLUDE_DIR nfsc/libnfs.h
45 PATHS ${PC_NFS_INCLUDEDIR})
47 set(LIBNFS_VERSION ${PC_NFS_VERSION})
49 find_library(NFS_LIBRARY NAMES nfs libnfs
50 PATHS ${PC_NFS_LIBDIR})
53 # Find lib and path as we cant easily rely on cmake-config
54 find_library(NFS_LIBRARY NAMES nfs libnfs
55 PATHS ${DEPENDS_PATH}/lib)
56 find_path(NFS_INCLUDE_DIR nfsc/libnfs.h PATHS ${DEPENDS_PATH}/include)
59 include(FindPackageHandleStandardArgs)
60 find_package_handle_standard_args(NFS
61 REQUIRED_VARS NFS_LIBRARY NFS_INCLUDE_DIR
62 VERSION_VAR LIBNFS_VERSION)
65 set(NFS_LIBRARIES ${NFS_LIBRARY})
66 set(NFS_INCLUDE_DIRS ${NFS_INCLUDE_DIR})
67 set(NFS_DEFINITIONS -DHAS_FILESYSTEM_NFS=1)
69 set(CMAKE_REQUIRED_INCLUDES "${NFS_INCLUDE_DIR}")
70 set(CMAKE_REQUIRED_LIBRARIES ${NFS_LIBRARY})
72 # Check for nfs_set_timeout
73 check_cxx_source_compiles("
75 #include <nfsc/libnfs.h>
78 nfs_set_timeout(NULL, 0);
83 list(APPEND NFS_DEFINITIONS -DHAS_NFS_SET_TIMEOUT)
86 # Check for mount_getexports_timeout
87 check_cxx_source_compiles("
89 #include <nfsc/libnfs.h>
92 mount_getexports_timeout(NULL, 0);
94 " NFS_MOUNT_GETEXPORTS_TIMEOUT)
96 if(NFS_MOUNT_GETEXPORTS_TIMEOUT)
97 list(APPEND NFS_DEFINITIONS -DHAS_NFS_MOUNT_GETEXPORTS_TIMEOUT)
100 unset(CMAKE_REQUIRED_INCLUDES)
101 unset(CMAKE_REQUIRED_LIBRARIES)
103 if(NOT TARGET NFS::NFS)
104 add_library(NFS::NFS UNKNOWN IMPORTED)
106 set_target_properties(NFS::NFS PROPERTIES
107 IMPORTED_LOCATION "${NFS_LIBRARY_RELEASE}"
108 INTERFACE_INCLUDE_DIRECTORIES "${NFS_INCLUDE_DIR}"
109 INTERFACE_COMPILE_DEFINITIONS "${NFS_DEFINITIONS}")
111 add_dependencies(NFS::NFS libnfs)
114 set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP NFS::NFS)
117 mark_as_advanced(NFS_INCLUDE_DIR NFS_LIBRARY)