diff --git a/var/spack/repos/builtin/packages/llvm/package.py b/var/spack/repos/builtin/packages/llvm/package.py
index c19c623cc960e82a605b0c95929df7ea21c9582e..d319da702ba2ae1f7addfe2573a7e083152417ed 100644
--- a/var/spack/repos/builtin/packages/llvm/package.py
+++ b/var/spack/repos/builtin/packages/llvm/package.py
@@ -664,10 +664,14 @@ def cmake_args(self):
         if '+all_targets' not in spec:  # all is default on cmake
 
             targets = ['NVPTX', 'AMDGPU']
-            if spec.version < Version('3.9.0'):
+            if (spec.version < Version('3.9.0')
+                and spec.version[0] != 'flang'):
                 # Starting in 3.9.0 CppBackend is no longer a target (see
                 # LLVM_ALL_TARGETS in llvm's top-level CMakeLists.txt for
                 # the complete list of targets)
+
+                # This also applies to the version of llvm used by flang
+                # hence the test to see if the version starts with "flang".
                 targets.append('CppBackend')
 
             if 'x86' in spec.architecture.target.lower():