[cmake-developers] [PATCH] Add target property VS_CONFIGURATION_TYPE to Visual Studio 10 target generator

Fabian.Otto at rohde-schwarz.com Fabian.Otto at rohde-schwarz.com
Thu Feb 25 10:36:59 EST 2016


Hi Brad,

thanks for your feedback. I added a test for the feature.

Best regards,
Fabian


---
 Tests/RunCMake/CMakeLists.txt                      |  5 +++++
 Tests/RunCMake/VS10Project/CMakeLists.txt          |  3 +++
 Tests/RunCMake/VS10Project/RunCMakeTest.cmake      |  2 ++
 .../VS10Project/VsConfigurationType-check.cmake    | 24 
++++++++++++++++++++++
 .../RunCMake/VS10Project/VsConfigurationType.cmake |  3 +++
 Tests/RunCMake/VS10Project/foo.cpp                 |  1 +
 6 files changed, 38 insertions(+)
 create mode 100644 Tests/RunCMake/VS10Project/CMakeLists.txt
 create mode 100644 Tests/RunCMake/VS10Project/RunCMakeTest.cmake
 create mode 100644 
Tests/RunCMake/VS10Project/VsConfigurationType-check.cmake
 create mode 100644 Tests/RunCMake/VS10Project/VsConfigurationType.cmake
 create mode 100644 Tests/RunCMake/VS10Project/foo.cpp

diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 0a388c5..81df69f 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -236,6 +236,11 @@ if("${CMAKE_GENERATOR}" MATCHES "Visual Studio [^6]")
   add_RunCMake_test(SolutionGlobalSections)
 endif()
 
+if(MSVC AND MSVC_VERSION GREATER 1500)
+  # Visual Studio 2010 or newer
+  add_RunCMake_test(VS10Project)
+endif()
+
 if(XCODE_VERSION AND NOT "${XCODE_VERSION}" VERSION_LESS 3)
   add_RunCMake_test(XcodeProject -DXCODE_VERSION=${XCODE_VERSION})
 endif()
diff --git a/Tests/RunCMake/VS10Project/CMakeLists.txt 
b/Tests/RunCMake/VS10Project/CMakeLists.txt
new file mode 100644
index 0000000..91baae7
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.5.0)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake 
b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
new file mode 100644
index 0000000..cc2cc2e
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
@@ -0,0 +1,2 @@
+include(RunCMake)
+run_cmake(VsConfigurationType)
diff --git a/Tests/RunCMake/VS10Project/VsConfigurationType-check.cmake 
b/Tests/RunCMake/VS10Project/VsConfigurationType-check.cmake
new file mode 100644
index 0000000..69df345
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/VsConfigurationType-check.cmake
@@ -0,0 +1,24 @@
+set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj")
+if(NOT EXISTS "${vcProjectFile}")
+  set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not 
exist.")
+  return()
+endif()
+
+set(propertyFound FALSE)
+file(STRINGS "${vcProjectFile}" lines)
+foreach(line IN LISTS lines)
+  if(line MATCHES "^ *<ConfigurationType>([^<]*)</ConfigurationType>$")
+    set(propertyFound TRUE)
+    set(expectedValue "MyValue")
+    set(actualValue ${CMAKE_MATCH_1})
+    if(NOT (${actualValue} STREQUAL ${expectedValue}))
+      set(RunCMake_TEST_FAILED "ConfigurationType \"${actualValue}\" 
differs from expected value \"${expectedValue}\".")
+      return()
+    endif()
+  endif()
+endforeach()
+
+if(NOT propertyFound)
+  set(RunCMake_TEST_FAILED "Property ConfigurationType not found in 
project file.")
+  return()
+endif()
diff --git a/Tests/RunCMake/VS10Project/VsConfigurationType.cmake 
b/Tests/RunCMake/VS10Project/VsConfigurationType.cmake
new file mode 100644
index 0000000..a73dfe8
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/VsConfigurationType.cmake
@@ -0,0 +1,3 @@
+enable_language(CXX)
+add_library(foo foo.cpp)
+set_target_properties(foo PROPERTIES VS_CONFIGURATION_TYPE "MyValue")
diff --git a/Tests/RunCMake/VS10Project/foo.cpp 
b/Tests/RunCMake/VS10Project/foo.cpp
new file mode 100644
index 0000000..2fb55ee
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/foo.cpp
@@ -0,0 +1 @@
+void foo() { }
-- 
2.7.1.windows.2




Von:    Brad King <brad.king at kitware.com>
An:     Fabian.Otto at rohde-schwarz.com, 
Kopie:  cmake-developers at cmake.org
Datum:  24.02.2016 17:09
Betreff:        Re: [cmake-developers] [PATCH] Add target property 
VS_CONFIGURATION_TYPE to Visual Studio 10 target generator



On 02/22/2016 11:35 AM, Fabian.Otto at rohde-schwarz.com wrote:
> The patch adds the target property VS_CONFIGURATION_TYPE. It allows to
> set an arbitrary value to the "ConfigurationType" property
> 
> This is useful if you want to build a Windows Kernel Mode Driver.

This looks okay to me.  Please extend the test suite to cover this
feature.  So far all VS features that we test have effects on the
generation that we can test explicitly.  In this case it looks like
we might not be able to test actually building such a project.  For
that, take a look at these test directories:

 Tests/RunCMake/SolutionGlobalSections
 Tests/RunCMake/XcodeProject

It tests running CMake and then parses the actual project file content
to check that it is as expected.  A similar test could be added for
VS .vcxproj content testing and used to cover this feature.

Thanks,
-Brad

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160225/2910666d/attachment-0001.html>


More information about the cmake-developers mailing list