diff --git a/jhbuild/modtypes/cmake.py b/jhbuild/modtypes/cmake.py
index d7868dbe..71654a42 100644
--- a/jhbuild/modtypes/cmake.py
+++ b/jhbuild/modtypes/cmake.py
@@ -105,6 +105,7 @@ class CMakeModule(MakeModule, DownloadableModule):
             raise CommandError(_('%s not found') % 'cmake')
         baseargs = '-DCMAKE_INSTALL_PREFIX=%s -DCMAKE_INSTALL_LIBDIR=lib' % prefix
         cmakeargs = self.get_cmakeargs()
+        self.ensure_ninja_binary()
         if self.use_ninja:
             baseargs += ' -G Ninja'
         # CMake on Windows generates VS projects or NMake makefiles by default.
@@ -121,8 +122,8 @@ class CMakeModule(MakeModule, DownloadableModule):
     def do_clean(self, buildscript):
         buildscript.set_action(_('Cleaning'), self)
         builddir = self.get_builddir(buildscript)
+        self.ensure_ninja_binary()
         if self.use_ninja:
-            self.ensure_ninja_binary()
             buildscript.execute(self.ninja_binary + ' clean', cwd=builddir, extra_env=self.extra_env)
         else:
             self.make(buildscript, 'clean')
@@ -132,8 +133,8 @@ class CMakeModule(MakeModule, DownloadableModule):
     def do_build(self, buildscript):
         buildscript.set_action(_('Building'), self)
         builddir = self.get_builddir(buildscript)
+        self.ensure_ninja_binary()
         if self.use_ninja:
-            self.ensure_ninja_binary()
             buildscript.execute(self.ninja_binary, cwd=builddir, extra_env=self.extra_env)
         else:
             self.make(buildscript)
@@ -156,8 +157,8 @@ class CMakeModule(MakeModule, DownloadableModule):
         buildscript.set_action(_('Installing'), self)
         builddir = self.get_builddir(buildscript)
         destdir = self.prepare_installroot(buildscript)
+        self.ensure_ninja_binary()
         if self.use_ninja:
-            self.ensure_ninja_binary()
             extra_env = self.extra_env or {}
             extra_env['DESTDIR'] = destdir
             buildscript.execute(self.ninja_binary + ' install', cwd=builddir, extra_env=extra_env)
