diff --git a/cmake/modules/ExternalProject.cmake b/cmake/modules/ExternalProject.cmake
index 29c5e6efae6741212b9753689a7fc7581361b588..0bb2849d243fb586ec858bbeabb07e44e4c23232 100644
--- a/cmake/modules/ExternalProject.cmake
+++ b/cmake/modules/ExternalProject.cmake
@@ -1161,7 +1161,7 @@ function(ExternalProject_Add_Step name step)
   if(command AND log)
     _ep_write_log_script(${name} ${step} command)
   endif()
-
+if(${work_dir})
   add_custom_command(
     OUTPUT ${stamp_file}
     COMMENT ${comment}
@@ -1171,7 +1171,16 @@ function(ExternalProject_Add_Step name step)
     $<$<BOOL:${work_dir}>:WORKING_DIRECTORY ${work_dir}>
     VERBATIM
     )
-
+else()
+  add_custom_command(
+    OUTPUT ${stamp_file}
+    COMMENT ${comment}
+    COMMAND ${command}
+    COMMAND ${touch}
+    DEPENDS ${depends}
+    VERBATIM
+    )
+endif()
   # Add custom "step target"?
   get_property(step_targets TARGET ${name} PROPERTY _EP_STEP_TARGETS)
   if(NOT step_targets)