Fix issues with FreeBSD build: use just built, instead of already installed, libraries (this one is not really FreeBSD specific) and use kqueue even if sys/inotify.h is available but inotify itself isn't (at least without linking with an extra library). Closes #18729.