4 # Finds the libnfs library
6 # This will define the following target:
8 # ${APP_NAME_LC}::NFS - The libnfs library
10 if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
13 set(CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF
15 -DENABLE_DOCUMENTATION=OFF
17 -DENABLE_EXAMPLES=OFF)
19 if(WIN32 OR WINDOWS_STORE)
20 set(${MODULE}_C_FLAGS "/sdl-")
21 set(${MODULE}_CXX_FLAGS "/sdl-")
23 set(patches "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/01-MSUWP-compat.patch")
24 generate_patchcommand("${patches}")
29 set(_nfs_definitions HAS_NFS_SET_TIMEOUT
30 HAS_NFS_MOUNT_GETEXPORTS_TIMEOUT)
33 include(cmake/scripts/common/ModuleHelpers.cmake)
39 # Search for cmake config. Suitable for all platforms including windows
40 find_package(libnfs CONFIG QUIET
41 HINTS ${DEPENDS_PATH}/lib/cmake
42 ${${CORE_PLATFORM_NAME_LC}_SEARCH_CONFIG})
44 # Check for existing LIBNFS. If version >= LIBNFS-VERSION file version, dont build
45 # A corner case, but if a linux/freebsd user WANTS to build internal libnfs, build anyway
46 if((libnfs_VERSION VERSION_LESS ${${MODULE}_VER} AND ENABLE_INTERNAL_NFS) OR
47 ((CORE_SYSTEM_NAME STREQUAL linux OR CORE_SYSTEM_NAME STREQUAL freebsd) AND ENABLE_INTERNAL_NFS))
51 if(TARGET libnfs::nfs)
52 # This is for the case where a distro provides a non standard (Debug/Release) config type
53 # convert this back to either DEBUG/RELEASE or just RELEASE
54 # we only do this because we use find_package_handle_standard_args for config time output
55 # and it isnt capable of handling TARGETS, so we have to extract the info
56 get_target_property(_LIBNFS_CONFIGURATIONS libnfs::nfs IMPORTED_CONFIGURATIONS)
57 foreach(_libnfs_config IN LISTS _LIBNFS_CONFIGURATIONS)
58 # Just set to RELEASE var so select_library_configurations can continue to work its magic
59 string(TOUPPER ${_libnfs_config} _libnfs_config_UPPER)
60 if((NOT ${_libnfs_config_UPPER} STREQUAL "RELEASE") AND
61 (NOT ${_libnfs_config_UPPER} STREQUAL "DEBUG"))
62 get_target_property(LIBNFS_LIBRARY_RELEASE libnfs::nfs IMPORTED_LOCATION_${_libnfs_config_UPPER})
64 get_target_property(LIBNFS_LIBRARY_${_libnfs_config_UPPER} libnfs::nfs IMPORTED_LOCATION_${_libnfs_config_UPPER})
68 # libnfs cmake config doesnt include INTERFACE_INCLUDE_DIRECTORIES
69 find_path(LIBNFS_INCLUDE_DIR NAMES nfsc/libnfs.h
70 HINTS ${DEPENDS_PATH}/include
71 ${${CORE_PLATFORM_LC}_SEARCH_CONFIG})
73 find_package(PkgConfig)
74 # Try pkgconfig based search as last resort
75 if(PKG_CONFIG_FOUND AND NOT (WIN32 OR WINDOWS_STORE))
77 if(NFS_FIND_VERSION_EXACT)
78 set(NFS_FIND_SPEC "=${NFS_FIND_VERSION_COMPLETE}")
80 set(NFS_FIND_SPEC ">=${NFS_FIND_VERSION_COMPLETE}")
84 pkg_check_modules(PC_LIBNFS libnfs${NFS_FIND_SPEC} QUIET)
87 find_library(LIBNFS_LIBRARY_RELEASE NAMES nfs libnfs
88 HINTS ${DEPENDS_PATH}/lib
90 ${${CORE_PLATFORM_NAME_LC}_SEARCH_CONFIG})
91 find_path(LIBNFS_INCLUDE_DIR nfsc/libnfs.h HINTS ${PC_LIBNFS_INCLUDEDIR}
92 ${DEPENDS_PATH}/include
93 ${${CORE_PLATFORM_NAME_LC}_SEARCH_CONFIG})
94 set(LIBNFS_VERSION ${PC_LIBNFS_VERSION})
98 include(SelectLibraryConfigurations)
99 select_library_configurations(LIBNFS)
101 include(FindPackageHandleStandardArgs)
102 find_package_handle_standard_args(NFS
103 REQUIRED_VARS LIBNFS_LIBRARY LIBNFS_INCLUDE_DIR
104 VERSION_VAR LIBNFS_VERSION)
107 # Pre existing lib, so we can run checks
108 if(NOT TARGET libnfs)
109 set(CMAKE_REQUIRED_INCLUDES "${LIBNFS_INCLUDE_DIR}")
110 set(CMAKE_REQUIRED_LIBRARIES ${LIBNFS_LIBRARY})
112 # Check for nfs_set_timeout
113 check_cxx_source_compiles("
114 ${LIBNFS_CXX_INCLUDE}
115 #include <nfsc/libnfs.h>
118 nfs_set_timeout(NULL, 0);
123 list(APPEND _nfs_definitions HAS_NFS_SET_TIMEOUT)
126 # Check for mount_getexports_timeout
127 check_cxx_source_compiles("
128 ${LIBNFS_CXX_INCLUDE}
129 #include <nfsc/libnfs.h>
132 mount_getexports_timeout(NULL, 0);
134 " NFS_MOUNT_GETEXPORTS_TIMEOUT)
136 if(NFS_MOUNT_GETEXPORTS_TIMEOUT)
137 list(APPEND _nfs_definitions HAS_NFS_MOUNT_GETEXPORTS_TIMEOUT)
140 unset(CMAKE_REQUIRED_INCLUDES)
141 unset(CMAKE_REQUIRED_LIBRARIES)
144 list(APPEND _nfs_definitions HAS_FILESYSTEM_NFS)
146 # cmake target and not building internal
147 if(TARGET libnfs::nfs AND NOT TARGET libnfs)
148 add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} ALIAS libnfs::nfs)
151 add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UNKNOWN IMPORTED)
152 set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
153 IMPORTED_LOCATION "${LIBNFS_LIBRARY}")
156 # Test if target is an alias. We cant set properties on alias targets, and must find
158 get_property(aliased_target TARGET "${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME}" PROPERTY ALIASED_TARGET)
159 if("${aliased_target}" STREQUAL "")
160 set(_nfs_target "${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME}")
162 set(_nfs_target "${aliased_target}")
165 # We need to append in case the cmake config already has definitions
166 set_property(TARGET ${_nfs_target} APPEND PROPERTY
167 INTERFACE_COMPILE_DEFINITIONS ${_nfs_definitions})
169 # Need to manually set this, as libnfs cmake config does not provide INTERFACE_INCLUDE_DIRECTORIES
170 set_target_properties(${_nfs_target} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${LIBNFS_INCLUDE_DIR})
173 add_dependencies(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} libnfs)
176 # Add internal build target when a Multi Config Generator is used
177 # We cant add a dependency based off a generator expression for targeted build types,
178 # https://gitlab.kitware.com/cmake/cmake/-/issues/19467
179 # therefore if the find heuristics only find the library, we add the internal build
180 # target to the project to allow user to manually trigger for any build type they need
181 # in case only a specific build type is actually available (eg Release found, Debug Required)
182 # This is mainly targeted for windows who required different runtime libs for different
183 # types, and they arent compatible
184 if(_multiconfig_generator)
185 if(NOT TARGET libnfs)
187 set_target_properties(libnfs PROPERTIES EXCLUDE_FROM_ALL TRUE)
189 add_dependencies(build_internal_depends libnfs)