 Fix darktable build
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 5a4c6521d8..55b804d643 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -1157,7 +1157,13 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement(
   this->AddModuleDefinitionFlag(linkLineComputer.get(), vars["LINK_FLAGS"],
                                 config);
   if (gt->GetPropertyAsBool("LINK_WHAT_YOU_USE")) {
-    vars["LINK_FLAGS"] += " -Wl,--no-as-needed";
+    switch (targetType) {
+      case cmStateEnums::EXECUTABLE:
+      case cmStateEnums::SHARED_LIBRARY:
+      case cmStateEnums::MODULE_LIBRARY:
+        vars["LINK_FLAGS"] += " -Wl,--no-as-needed";
+        break;
+    }
   }
   vars["LINK_FLAGS"] = globalGen->EncodeLiteral(vars["LINK_FLAGS"]);
 
