diff --git a/configure.cmake b/configure.cmake
index 271e18c04fded0540712fa4a07c71caf2ce6c6f6..244fa1e0e9e278a89cd2a21c343171ffcc39234b 100644
--- a/configure.cmake
+++ b/configure.cmake
@@ -326,15 +326,6 @@ IF(UNIX)
   ENDIF()
 ENDIF()
 
-IF (CMAKE_SYSTEM_NAME MATCHES "SunOS")
-  INCLUDE(CheckLibraryExists)
-  CHECK_LIBRARY_EXISTS(mtmalloc malloc "" HAVE_LIBMTMALLOC)
-  IF(HAVE_LIBMTMALLOC)
-    LINK_LIBRARIES(mtmalloc)
-  ENDIF()
-ENDIF()
-
-
 # Workaround for CMake bug#9051
 IF(CMAKE_OSX_SYSROOT)
  SET(ENV{CMAKE_OSX_SYSROOT} ${CMAKE_OSX_SYSROOT})
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index 389b1a8766b902bed9e802d4e2226cb74812d1e0..eaf8a45b25d45c948cc40cf7a0fad0108c8ce5ee 100755
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -132,6 +132,7 @@ ENDIF()
 
 SET_TARGET_PROPERTIES(mysqld PROPERTIES ENABLE_EXPORTS TRUE) 
 TARGET_LINK_LIBRARIES(mysqld sql)
+
 # Provide plugins with minimal set of libraries
 SET(INTERFACE_LIBS ${LIBRT})
 IF(INTERFACE_LIBS)
@@ -145,6 +146,17 @@ DTRACE_INSTRUMENT_STATIC_LIBS(mysqld
  "sql;mysys;${MYSQLD_STATIC_PLUGIN_LIBS}")
  
 
+SET(WITH_MYSQLD_LIBS "" CACHE STRING "Additional linker flags for mysqld")
+MARK_AS_ADVANCED(WITH_MYSQLD_LIBS)
+IF(WITH_MYSQLD_LIBS)
+  GET_TARGET_PROPERTY(mysqld LINK_FLAGS MYSQLD_LINK_FLAGS)
+  IF(NOT MYSQLD_LINK_FLAGS)
+    SET(MYSQLD_LINK_FLAGS) 
+  ENDIF() 
+  SET_TARGET_PROPERTIES(mysqld PROPERTIES LINK_FLAGS 
+     "${MYSQLD_LINK_FLAGS} ${WITH_MYSQLD_LIBS}")
+ENDIF()
+
 # Handle out-of-source build from source package with possibly broken 
 # bison. Copy bison output to from source to build directory, if not already 
 # there