From 8909a450a6fb74447ef6dc49f16d747bae3c72ea Mon Sep 17 00:00:00 2001
From: Daniel Eiband <daniel.eiband@brainlab.com>
Date: Mon, 26 Aug 2019 15:22:43 +0200
Subject: VS: Add support for generator expressions to VS_CONFIGURATION_TYPE

Generator expressions in target property VS_CONFIGURATION_TYPE might be used to
set the ConfigurationType to Utility for certain configurations to not build
the target while still linking to the target in other configurations.

Fixes: #19613
---
 Help/prop_tgt/VS_CONFIGURATION_TYPE.rst                    | 2 ++
 Help/release/dev/vs-configuration-type-genex.rst           | 5 +++++
 Source/cmVisualStudio10TargetGenerator.cxx                 | 5 ++++-
 Tests/RunCMake/VS10Project/VsConfigurationType-check.cmake | 2 +-
 Tests/RunCMake/VS10Project/VsConfigurationType.cmake       | 2 +-
 5 files changed, 13 insertions(+), 3 deletions(-)
 create mode 100644 Help/release/dev/vs-configuration-type-genex.rst

diff --git a/Help/prop_tgt/VS_CONFIGURATION_TYPE.rst b/Help/prop_tgt/VS_CONFIGURATION_TYPE.rst
index ff987ff..640bed5 100644
--- a/Help/prop_tgt/VS_CONFIGURATION_TYPE.rst
+++ b/Help/prop_tgt/VS_CONFIGURATION_TYPE.rst
@@ -4,6 +4,8 @@ VS_CONFIGURATION_TYPE
 Visual Studio project configuration type.
 
 Sets the ``ConfigurationType`` attribute for a generated Visual Studio project.
+The property value may use
+:manual:`generator expressions <cmake-generator-expressions(7)>`.
 If this property is set, it overrides the default setting that is based on the
 target type (e.g. ``StaticLibrary``, ``Application``, ...).
 
diff --git a/Help/release/dev/vs-configuration-type-genex.rst b/Help/release/dev/vs-configuration-type-genex.rst
new file mode 100644
index 0000000..d930d5b
--- /dev/null
+++ b/Help/release/dev/vs-configuration-type-genex.rst
@@ -0,0 +1,5 @@
+vs-configuration-type-genex
+---------------------------
+
+* :prop_tgt:`VS_CONFIGURATION_TYPE` now supports
+  :manual:`generator expressions <cmake-generator-expressions(7)>`.
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index c5cf9a7..ea2d16c 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -1115,7 +1115,10 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues(Elem& e0)
       std::string configType;
       if (const char* vsConfigurationType =
             this->GeneratorTarget->GetProperty("VS_CONFIGURATION_TYPE")) {
-        configType = vsConfigurationType;
+        cmGeneratorExpression ge;
+        std::unique_ptr<cmCompiledGeneratorExpression> cge =
+          ge.Parse(vsConfigurationType);
+        configType = cge->Evaluate(this->LocalGenerator, c);
       } else {
         switch (this->GeneratorTarget->GetType()) {
           case cmStateEnums::SHARED_LIBRARY:
diff --git a/Tests/RunCMake/VS10Project/VsConfigurationType-check.cmake b/Tests/RunCMake/VS10Project/VsConfigurationType-check.cmake
index 4690970..bbd34da 100644
--- a/Tests/RunCMake/VS10Project/VsConfigurationType-check.cmake
+++ b/Tests/RunCMake/VS10Project/VsConfigurationType-check.cmake
@@ -9,7 +9,7 @@ file(STRINGS "${vcProjectFile}" lines)
 foreach(line IN LISTS lines)
   if(line MATCHES "^ *<ConfigurationType>(.*)</ConfigurationType>$")
     set(propertyFound TRUE)
-    set(expectedValue "MyValue")
+    set(expectedValue "MyValue foo")
     set(actualValue ${CMAKE_MATCH_1})
     if(NOT (${actualValue} STREQUAL ${expectedValue}))
       set(RunCMake_TEST_FAILED "ConfigurationType \"${actualValue}\" differs from expected value \"${expectedValue}\".")
diff --git a/Tests/RunCMake/VS10Project/VsConfigurationType.cmake b/Tests/RunCMake/VS10Project/VsConfigurationType.cmake
index a73dfe8..a2f544a 100644
--- a/Tests/RunCMake/VS10Project/VsConfigurationType.cmake
+++ b/Tests/RunCMake/VS10Project/VsConfigurationType.cmake
@@ -1,3 +1,3 @@
 enable_language(CXX)
 add_library(foo foo.cpp)
-set_target_properties(foo PROPERTIES VS_CONFIGURATION_TYPE "MyValue")
+set_target_properties(foo PROPERTIES VS_CONFIGURATION_TYPE "MyValue $<TARGET_PROPERTY:foo,NAME>")
-- 
cgit v0.12