diff --git a/libmysqld/examples/CMakeLists.txt b/libmysqld/examples/CMakeLists.txt
index 400ddd8b7293b5bce1dc2dc79611afd129ed69a7..ed0e5a361a8996ccf0faf4c684f85abaf8572291 100644
--- a/libmysqld/examples/CMakeLists.txt
+++ b/libmysqld/examples/CMakeLists.txt
@@ -39,9 +39,13 @@ IF(CMAKE_GENERATOR MATCHES "Xcode")
 # It does not seem possible to tell Xcode the resulting target might need
 # to be linked with C++ runtime. The project needs to have at least one C++
 # file. Add a dummy one.
-  MYSQL_CREATE_EMPTY_FILE(mysql_client_test_embedded_dummy.cc)
+  ADD_CUSTOM_COMMAND(OUTPUT  
+    ${CMAKE_CURRENT_BINARY_DIR}/mysql_client_test_embedded_dummy.cc
+   COMMAND ${CMAKE_COMMAND} -E touch 
+    ${CMAKE_CURRENT_BINARY_DIR}/mysql_client_test_embedded_dummy.cc
+  )
   ADD_EXECUTABLE(mysql_client_test_embedded
-    mysql_client_test_embedded_dummy.cc
+    ${CMAKE_CURRENT_BINARY_DIR}/mysql_client_test_embedded_dummy.cc
     ../../tests/mysql_client_test.c)
 ELSE()
   ADD_EXECUTABLE(mysql_client_test_embedded ../../tests/mysql_client_test.c)
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index 881772bfc5afed0ab4214b86ab09d1e3c3008b90..336f94c0718a004ec5da590b8cc318777391d468 100755
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -187,6 +187,9 @@ IF(WIN32 OR HAVE_DLOPEN)
      SET_TARGET_PROPERTIES(udf_example PROPERTIES LINK_FLAGS "/DEF:${CMAKE_CURRENT_SOURCE_DIR}/udf_example.def")
     ENDIF()
     TARGET_LINK_LIBRARIES(udf_example strings)
+  ELSE()
+    # udf_example is using safemutex exported by mysqld
+    TARGET_LINK_LIBRARIES(udf_example mysqld)
   ENDIF()
 ENDIF()
 
@@ -246,4 +249,4 @@ IF(WIN32 AND MYSQLD_EXECUTABLE)
 ELSE()
   # Not windows or cross compiling, just install an empty directory
   INSTALL(FILES ${DUMMY_FILE} DESTINATION data/mysql)
-ENDIF()
\ No newline at end of file
+ENDIF()