From feff52d42ca18a52fd99e8fdfd3093c3a94eb498 Mon Sep 17 00:00:00 2001
From: Brad King <brad.king@kitware.com>
Date: Fri, 24 Feb 2017 11:19:24 -0500
Subject: [PATCH] Fix COMPILE_PDB_NAME when used on an OBJECT library

When `COMPILE_PDB_NAME` is used without `COMPILE_PDB_OUTPUT_DIRECTORY`
we cannot fall back on the link `PDB_OUTPUT_DIRECTORY` for an object
library because it has no link step.

Fixes: #16674
---
 Source/cmGeneratorTarget.cxx         | 2 +-
 Tests/ObjectLibrary/A/CMakeLists.txt | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 6ce814058b..3fe5c83f51 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -1147,7 +1147,7 @@ std::string cmGeneratorTarget::GetCompilePDBPath(
 {
   std::string dir = this->GetCompilePDBDirectory(config);
   std::string name = this->GetCompilePDBName(config);
-  if (dir.empty() && !name.empty()) {
+  if (dir.empty() && !name.empty() && this->HaveWellDefinedOutputFiles()) {
     dir = this->GetPDBDirectory(config);
   }
   if (!dir.empty()) {
diff --git a/Tests/ObjectLibrary/A/CMakeLists.txt b/Tests/ObjectLibrary/A/CMakeLists.txt
index 188fd64e59..c185d75216 100644
--- a/Tests/ObjectLibrary/A/CMakeLists.txt
+++ b/Tests/ObjectLibrary/A/CMakeLists.txt
@@ -21,3 +21,4 @@ add_custom_command(
 
 add_library(A OBJECT a1.c a2.c a.cmake)
 target_include_directories(A PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
+set_property(TARGET A PROPERTY COMPILE_PDB_NAME Apdb)
-- 
GitLab