diff --git a/CMakeLists.txt b/CMakeLists.txt
index b920d6f2..a3279922 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,6 +14,12 @@ set (CMAKE_CXX_STANDARD 11)
 
 set (RENDERER_FLAGS "")
 
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(DNSSD REQUIRED avahi-compat-libdns_sd)
+pkg_check_modules(PLIST REQUIRED libplist-2.0)
+link_directories(${DNS_SD_LIBRARY_DIRS})
+link_directories(${PLIST_LIBRARY_DIRS})
+
 add_subdirectory(lib/playfair)
 add_subdirectory(lib/llhttp)
 add_subdirectory(lib)
@@ -23,6 +29,6 @@ add_subdirectory(renderers)
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${RENDERER_FLAGS}" )
 
 add_executable( rpiplay rpiplay.cpp)
-target_link_libraries ( rpiplay renderers airplay )
+target_link_libraries ( rpiplay renderers airplay ${PLIST_LIBRARIES})
 
 install(TARGETS rpiplay RUNTIME DESTINATION bin)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index c7903432..cbec1fc4 100755
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -21,7 +21,12 @@ if( UNIX AND NOT APPLE )
   find_package(OpenSSL 1.1.1 REQUIRED)
   target_compile_definitions(airplay PUBLIC OPENSSL_API_COMPAT=0x10101000L)
   target_link_libraries( airplay OpenSSL::Crypto )
-  target_link_libraries( airplay dns_sd )
+  target_include_directories( airplay PUBLIC ${DNSSD_INCLUDE_DIRS} )
+  target_include_directories( airplay PUBLIC ${PLIST_INCLUDE_DIRS} )
+  link_directories(${DNS_SD_LIBRARY_DIRS})
+  link_directories(${PLIST_LIBRARY_DIRS})
+  target_link_libraries( airplay ${PLIST_LIBRARIES})
+  target_link_libraries( airplay ${DNSSD_LIBRARIES})
 else()
   include_directories( /usr/local/opt/openssl@1.1/include/ )
   target_link_libraries( airplay /usr/local/opt/openssl@1.1/lib/libcrypto.a )
diff --git a/lib/byteutils.c b/lib/byteutils.c
index e3122ae8..ba469947 100755
--- a/lib/byteutils.c
+++ b/lib/byteutils.c
@@ -17,7 +17,12 @@
 #include "byteutils.h"
 
 #ifndef htonll
+#ifdef __linux__
 #include <endian.h>
+#endif
+#ifdef __FreeBSD__
+#include <sys/endian.h>
+#endif
 #define htonll(x) htobe64(x)
 #define ntohll(x) be64toh(x)
 #endif
diff --git a/lib/raop_rtp_mirror.c b/lib/raop_rtp_mirror.c
index 2040d7e2..5b62f2c5 100755
--- a/lib/raop_rtp_mirror.c
+++ b/lib/raop_rtp_mirror.c
@@ -30,6 +30,9 @@
 #include "mirror_buffer.h"
 #include "stream.h"
 
+#ifdef __FreeBSD__
+#define SOL_TCP 6
+#endif
 
 struct h264codec_s {
     unsigned char compatibility;