Make the installation of opt-viewer dependent on the presence of its dependencies

The cmake build system already checks if the dependencies for opt-viewer are met and defines LLVM_HAVE_OPT_VIEWER_MODULES if python3-pygments and python3-yaml are found. However, the opt-viewer code is installed regardless of whether it can run on the target. My idea was to install opt-viewer only if LLVM_HAVE_OPT_VIEWER_MODULES was set. Bad idea ?

diff --git a/llvm/tools/opt-viewer/CMakeLists.txt b/llvm/tools/opt-viewer/CMakeLists.txt
index c0070f8cbfac..fb6ee384f6d1 100644
--- a/llvm/tools/opt-viewer/CMakeLists.txt
+++ b/llvm/tools/opt-viewer/CMakeLists.txt
@@ -1,20 +1,22 @@
-set (files
-  "opt-diff.py"
-  "opt-stats.py"
-  "opt-viewer.py"
-  "optpmap.py"
-  "optrecord.py"
-  "style.css")
+if(LLVM_HAVE_OPT_VIEWER_MODULES)
+  set (files
+    "opt-diff.py"
+    "opt-stats.py"
+    "opt-viewer.py"
+    "optpmap.py"
+    "optrecord.py"
+    "style.css")
 
-foreach (file ${files})
-  install(PROGRAMS ${file}
-    DESTINATION "${CMAKE_INSTALL_DATADIR}/opt-viewer"
-    COMPONENT opt-viewer)
-endforeach (file)
+  foreach (file ${files})
+    install(PROGRAMS ${file}
+      DESTINATION "${CMAKE_INSTALL_DATADIR}/opt-viewer"
+      COMPONENT opt-viewer)
+  endforeach (file)
 
-add_custom_target(opt-viewer DEPENDS ${files})
-if(NOT LLVM_ENABLE_IDE)
-  add_llvm_install_targets("install-opt-viewer"
-                           DEPENDS opt-viewer
-                           COMPONENT opt-viewer)
+  add_custom_target(opt-viewer DEPENDS ${files})
+  if(NOT LLVM_ENABLE_IDE)
+    add_llvm_install_targets("install-opt-viewer"
+                             DEPENDS opt-viewer
+                             COMPONENT opt-viewer)
+  endif()
 endif()