瀏覽代碼

cmake_host_system_information: Add undocumented VS_MSBUILD_COMMAND key

When using the Visual Studio generator for VS 10 or above,
offer this key to get the location of the MSBuild command
before the first `project()` or `enable_language()` command
has finished running.

This will be needed only by one of our own modules, so leave it
undocumented for now.
Brad King 4 年之前
父節點
當前提交
44a86d0b38

+ 7 - 0
Source/cmCMakeHostSystemInformationCommand.cxx

@@ -27,6 +27,7 @@
 #ifdef _WIN32
 #  include "cmAlgorithms.h"
 #  include "cmGlobalGenerator.h"
+#  include "cmGlobalVisualStudio10Generator.h"
 #  include "cmGlobalVisualStudioVersionedGenerator.h"
 #  include "cmVSSetupHelper.h"
 #  define HAVE_VS_SETUP_HELPER
@@ -434,6 +435,12 @@ cm::optional<std::string> GetValue(cmExecutionStatus& status,
     }
   }
 
+  if (key == "VS_MSBUILD_COMMAND"_s && gg->IsVisualStudioAtLeast10()) {
+    cmGlobalVisualStudio10Generator* vs10gen =
+      static_cast<cmGlobalVisualStudio10Generator*>(gg);
+    return vs10gen->FindMSBuildCommandEarly(&status.GetMakefile());
+  }
+
   return {};
 }
 #endif

+ 6 - 0
Tests/RunCMake/cmake_host_system_information/RunCMakeTest.cmake

@@ -15,3 +15,9 @@ run_cmake(CentOS6)
 run_cmake(Debian6)
 
 run_cmake(UserFallbackScript)
+
+if(RunCMake_GENERATOR MATCHES "^Visual Studio " AND NOT RunCMake_GENERATOR STREQUAL "Visual Studio 9 2008")
+  run_cmake(VsMSBuild)
+else()
+  run_cmake(VsMSBuildMissing)
+endif()

+ 4 - 0
Tests/RunCMake/cmake_host_system_information/VsMSBuild.cmake

@@ -0,0 +1,4 @@
+cmake_host_system_information(RESULT msbuild QUERY VS_MSBUILD_COMMAND)
+if(NOT EXISTS "${msbuild}")
+  message(FATAL_ERROR "VS_MSBUILD_COMMAND returned path that does not exist:\n ${msbuild}")
+endif()

+ 1 - 0
Tests/RunCMake/cmake_host_system_information/VsMSBuildMissing-result.txt

@@ -0,0 +1 @@
+1

+ 4 - 0
Tests/RunCMake/cmake_host_system_information/VsMSBuildMissing-stderr.txt

@@ -0,0 +1,4 @@
+^CMake Error at VsMSBuildMissing.cmake:[0-9]+ \(cmake_host_system_information\):
+  cmake_host_system_information does not recognize <key> VS_MSBUILD_COMMAND
+Call Stack \(most recent call first\):
+  CMakeLists.txt:[0-9]+ \(include\)$

+ 1 - 0
Tests/RunCMake/cmake_host_system_information/VsMSBuildMissing.cmake

@@ -0,0 +1 @@
+cmake_host_system_information(RESULT msbuild QUERY VS_MSBUILD_COMMAND)