--- CMakeLists.txt.orig	2014-05-05 09:49:48.000000000 +0200
+++ CMakeLists.txt	2014-05-05 09:58:30.000000000 +0200
@@ -53,6 +55,7 @@
     set(MODULE_FLAGS "-module -shared -avoid-version")
     set(SYSCONFDIR "/etc" CACHE PATH "config directory")
     set(STATEDIR "/var" CACHE PATH "state directory")
+    set(INSTALL_MANDIR man)
 endif()
 
 if(NOT INSTALL_SBINDIR)
@@ -227,13 +230,15 @@
 
 
 if(UNIX OR MSYS OR MINGW OR CYGWIN)
-    check_library_exists(dl dlopen "" HAVE_DL_LIB)
-    if (HAVE_DL_LIB)
-        set (UCOMMON_LIBS ${UCOMMON_LIBS} dl)
-    else()
-        check_library_exists(compat dlopen "" HAVE_COMPAT_LIB)
-        if(HAVE_COMPAT_LIB)
-            set (UCOMMON_LIBS ${UCOMMON_LIBS} compat)
+    if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
+        check_library_exists(dl dlopen "" HAVE_DL_LIB)
+        if (HAVE_DL_LIB)
+            set (UCOMMON_LIBS ${UCOMMON_LIBS} dl)
+        else()
+            check_library_exists(compat dlopen "" HAVE_COMPAT_LIB)
+            if(HAVE_COMPAT_LIB)
+                set (UCOMMON_LIBS ${UCOMMON_LIBS} compat)
+            endif()
         endif()
     endif()
 
@@ -330,7 +335,11 @@
 check_include_files(sys/event.h HAVE_SYS_EVENT_H)
 check_include_files(syslog.h HAVE_SYSLOG_H)
 check_include_files(openssl/ssl.h HAVE_OPENSSL)
-check_include_files(openssl/fips.h HAVE_OPENSSL_FIPS_H)
+if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
+    set(HAVE_OPENSSL_FIPS_H "")
+else()
+    check_include_files(openssl/fips.h HAVE_OPENSSL_FIPS_H)
+endif()
 check_include_files(libintl.h HAVE_LIBINTL_H)
 check_include_files(netinet/in.h HAVE_NETINET_IN_H)
 check_include_files(net/if.h HAVE_NET_IF_H)
@@ -434,11 +443,19 @@
     endforeach()
     foreach(lib ${UCOMMON_LIBS})
         STRING(REGEX REPLACE "^[-]l" "" slib ${lib})
-        set(PACKAGE_LIBS "${PACKAGE_LIBS} -l${slib}")
+        if(${lib} STREQUAL "-pthread")
+            set(PACKAGE_LIBS "${PACKAGE_LIBS} ${slib}" )
+        else()
+            set(PACKAGE_LIBS "${PACKAGE_LIBS} -l${slib}")
+        endif()
     endforeach()
     foreach(lib ${SECURE_LIBS})
         STRING(REGEX REPLACE "^[-]l" "" slib ${lib})
-        set(ADDITIONAL_LIBS "${ADDITIONAL_LIBS} -l${slib}")
+        if(${lib} STREQUAL "-pthread")
+            set(ADDITIONAL_LIBS "${ADDITIONAL_LIBS} ${slib}")
+        else()
+            set(ADDITIONAL_LIBS "${ADDITIONAL_LIBS} -l${slib}")
+        endif()
     endforeach()
     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc)
     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config)
@@ -594,11 +611,11 @@
 endif()
 
 if(NOT WIN32)
-    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${INSTALL_LIBDIR}/pkgconfig)
+    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION libdata/pkgconfig)
     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ucommon-config DESTINATION ${INSTALL_BINDIR})
     if(BUILD_STDLIB)
         install(FILES ${CMAKE_CURRENT_BINARY_DIR}/commoncpp-config DESTINATION ${INSTALL_BINDIR})
-        install(FILES ${CMAKE_CURRENT_BINARY_DIR}/commoncpp.pc DESTINATION ${INSTALL_LIBDIR}/pkgconfig)
+        install(FILES ${CMAKE_CURRENT_BINARY_DIR}/commoncpp.pc DESTINATION libdata/pkgconfig)
     endif()
 endif(NOT WIN32)
 
