--- eiskaltdcpp-qt/CMakeLists.txt.orig	2011-10-02 18:12:43.000000000 +0300
+++ eiskaltdcpp-qt/CMakeLists.txt	2011-10-03 11:20:59.000000000 +0300
@@ -238,6 +238,10 @@
     set_property(SOURCE ${PROJECT_SOURCE_DIR}/src/main.cpp PROPERTY COMPILE_DEFINITIONS ENABLE_STACKTRACE)
 endif (ENABLE_STACKTRACE)
 
+if (USE_MINIUPNP OR FREE_SPACE_BAR_C)
+	list(APPEND LIBS extra)
+endif (USE_MINIUPNP OR FREE_SPACE_BAR_C)
+
 if (APPLE)
   set (MACOSICON "${PROJECT_SOURCE_DIR}/../data/icons/icon_128x128.icns")
   set (MACOSICONINBUNDLE "icon_128x128.icns")
@@ -275,12 +279,21 @@
   add_definitions(-DCLIENT_RES_DIR="${CLIENT_DATA_DIR}/qt/resources")
 endif (APPLE)
 
+if (BUILD_LIB)
+	set(DCPP_LIB dcpp)
+else (BUILD_LIB)
+	find_library(DCPP_LIB eiskaltdcpp)
+	if (DCPP_LIB)
+		message(STATUS "EiskaltDC++ shared library found at ${DCPP_LIB}")
+	endif (DCPP_LIB)
+endif (BUILD_LIB)
+
 if (APPLE)
-  target_link_libraries (${PROJECT_NAME} ${LIBS} dcpp iconv)
+  target_link_libraries (${PROJECT_NAME} ${LIBS} ${DCPP_LIB} iconv)
 elseif (HAIKU)
-  target_link_libraries (${PROJECT_NAME} ${LIBS} dcpp be)
+  target_link_libraries (${PROJECT_NAME} ${LIBS} ${DCPP_LIB} be)
 else (APPLE)
-  target_link_libraries (${PROJECT_NAME} ${LIBS} dcpp)
+  target_link_libraries (${PROJECT_NAME} ${LIBS} ${DCPP_LIB})
 endif (APPLE)
 
 if (APPLE)
