if(PROJECT_ENABLE_FUSE AND NOT PROJECT_IS_MINGW)
  if(PROJECT_BUILD)
    add_definitions(-DPROJECT_ENABLE_FUSE)

    include_directories(BEFORE SYSTEM ${PROJECT_FUSE_INCLUDE_DIRS})

    if(PROJECT_FUSE STREQUAL "fuse3")
      add_definitions(-DFUSE_USE_VERSION=30)
      if(PROJECT_STATIC_LINK)
        link_libraries(libfuse3.a)
      else()
        link_libraries(fuse3)
      endif()
    elseif(PROJECT_FUSE STREQUAL "fuse2")
      add_definitions(-DFUSE_USE_VERSION=29)
      if(PROJECT_STATIC_LINK)
        link_libraries(libfuse.a)
      else()
        link_libraries(fuse)
      endif()
    endif()
  else()
    if (PROJECT_IS_DARWIN)
      find_library(OSXFUSE NO_CACHE NAMES MACFUSE OSXFUSE)
      if (NOT OSXFUSE)
        message(FATAL_ERROR "FUSE for macOS not found (https://macfuse.github.io)")
      endif ()
      set(PROJECT_FUSE fuse2)
    else()
      pkg_check_modules(LIBFUSE3 fuse3>=3.0.0)
      if(LIBFUSE3_FOUND)
        set(PROJECT_FUSE fuse3)
        set(PROJECT_FUSE_INCLUDE_DIRS ${LIBFUSE3_INCLUDE_DIRS})
      else()
        pkg_check_modules(LIBFUSE2 fuse>=2.9.0)
        if(LIBFUSE2_FOUND)
          set(PROJECT_FUSE fuse2)
          set(PROJECT_FUSE_INCLUDE_DIRS ${LIBFUSE2_INCLUDE_DIRS})
        else()
          message(FATAL_ERROR "fuse library not found")
        endif()
      endif()
    endif()
  endif()
endif()
