summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Modules/Platform/Android-Determine.cmake4
-rw-r--r--Source/cmCMakeHostSystemInformationCommand.cxx7
-rw-r--r--Source/cmGlobalGenerator.cxx13
-rw-r--r--Source/cmGlobalGenerator.h13
-rw-r--r--Source/cmGlobalVisualStudio10Generator.cxx7
-rw-r--r--Source/cmGlobalVisualStudio10Generator.h6
-rw-r--r--Source/cmGlobalVisualStudioGenerator.h5
-rw-r--r--Source/cmGlobalVisualStudioVersionedGenerator.cxx17
-rw-r--r--Source/cmGlobalVisualStudioVersionedGenerator.h5
-rw-r--r--Source/cmGlobalXCodeGenerator.h5
-rw-r--r--Tests/RunCMake/cmake_host_system_information/RunCMakeTest.cmake6
-rw-r--r--Tests/RunCMake/cmake_host_system_information/VsMSBuild.cmake4
-rw-r--r--Tests/RunCMake/cmake_host_system_information/VsMSBuildMissing-result.txt1
-rw-r--r--Tests/RunCMake/cmake_host_system_information/VsMSBuildMissing-stderr.txt4
-rw-r--r--Tests/RunCMake/cmake_host_system_information/VsMSBuildMissing.cmake1
15 files changed, 62 insertions, 36 deletions
diff --git a/Modules/Platform/Android-Determine.cmake b/Modules/Platform/Android-Determine.cmake
index 7b67f83..a4e9574 100644
--- a/Modules/Platform/Android-Determine.cmake
+++ b/Modules/Platform/Android-Determine.cmake
@@ -52,14 +52,16 @@ if(CMAKE_GENERATOR MATCHES "Visual Studio")
endif()
configure_file(${CMAKE_ROOT}/Modules/Platform/Android/VCXProjInspect.vcxproj.in
${CMAKE_PLATFORM_INFO_DIR}/VCXProjInspect.vcxproj @ONLY)
+ cmake_host_system_information(RESULT _msbuild QUERY VS_MSBUILD_COMMAND) # undocumented query
execute_process(
- COMMAND "${CMAKE_VS_MSBUILD_COMMAND}" "VCXProjInspect.vcxproj"
+ COMMAND "${_msbuild}" "VCXProjInspect.vcxproj"
"/p:Configuration=Debug" "/p:Platform=${vcx_platform}"
WORKING_DIRECTORY ${CMAKE_PLATFORM_INFO_DIR}
OUTPUT_VARIABLE VCXPROJ_INSPECT_OUTPUT
ERROR_VARIABLE VCXPROJ_INSPECT_OUTPUT
RESULT_VARIABLE VCXPROJ_INSPECT_RESULT
)
+ unset(_msbuild)
if(NOT CMAKE_SYSROOT AND VCXPROJ_INSPECT_OUTPUT MATCHES "CMAKE_SYSROOT=([^%\r\n]+)[\r\n]")
# Strip VS diagnostic output from the end of the line.
string(REGEX REPLACE " \\(TaskId:[0-9]*\\)$" "" _sysroot "${CMAKE_MATCH_1}")
diff --git a/Source/cmCMakeHostSystemInformationCommand.cxx b/Source/cmCMakeHostSystemInformationCommand.cxx
index 74071ff..3922c56 100644
--- a/Source/cmCMakeHostSystemInformationCommand.cxx
+++ b/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
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 6dabf63..ac283ab 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -593,16 +593,6 @@ void cmGlobalGenerator::EnableLanguage(
}
}
- if (readCMakeSystem) {
- // Find the native build tool for this generator.
- // This has to be done early so that MSBuild can be used to examine the
- // cross-compilation environment.
- if (this->GetFindMakeProgramStage() == FindMakeProgramStage::Early &&
- !this->FindMakeProgram(mf)) {
- return;
- }
- }
-
// Load the CMakeDetermineSystem.cmake file and find out
// what platform we are running on
if (!mf->GetDefinition("CMAKE_SYSTEM")) {
@@ -676,8 +666,7 @@ void cmGlobalGenerator::EnableLanguage(
}
// Find the native build tool for this generator.
- if (this->GetFindMakeProgramStage() == FindMakeProgramStage::Late &&
- !this->FindMakeProgram(mf)) {
+ if (!this->FindMakeProgram(mf)) {
return;
}
}
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index 23c5700..cc0ad29 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -444,6 +444,8 @@ public:
virtual bool IsVisualStudio() const { return false; }
+ virtual bool IsVisualStudioAtLeast10() const { return false; }
+
virtual bool IsNinja() const { return false; }
/** Return true if we know the exact location of object files.
@@ -623,17 +625,6 @@ protected:
std::string GetPredefinedTargetsFolder() const;
- enum class FindMakeProgramStage
- {
- Early,
- Late,
- };
-
- virtual FindMakeProgramStage GetFindMakeProgramStage() const
- {
- return FindMakeProgramStage::Late;
- }
-
private:
using TargetMap = std::unordered_map<std::string, cmTarget*>;
using GeneratorTargetMap =
diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx
index 488ff2e..c11516d 100644
--- a/Source/cmGlobalVisualStudio10Generator.cxx
+++ b/Source/cmGlobalVisualStudio10Generator.cxx
@@ -139,7 +139,6 @@ cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator(
"ProductDir",
vc10Express, cmSystemTools::KeyWOW64_32);
this->CudaEnabled = false;
- this->MSBuildCommandInitialized = false;
{
std::string envPlatformToolset;
if (cmSystemTools::GetEnv("PlatformToolset", envPlatformToolset) &&
@@ -857,6 +856,12 @@ std::string const& cmGlobalVisualStudio10Generator::GetMSBuildCommand()
return this->MSBuildCommand;
}
+cm::optional<std::string>
+cmGlobalVisualStudio10Generator::FindMSBuildCommandEarly(cmMakefile*)
+{
+ return this->GetMSBuildCommand();
+}
+
std::string cmGlobalVisualStudio10Generator::FindMSBuildCommand()
{
std::string msbuild;
diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h
index b7ae1ee..6e62390 100644
--- a/Source/cmGlobalVisualStudio10Generator.h
+++ b/Source/cmGlobalVisualStudio10Generator.h
@@ -20,6 +20,8 @@ class cmGlobalVisualStudio10Generator : public cmGlobalVisualStudio8Generator
public:
static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory();
+ bool IsVisualStudioAtLeast10() const override { return true; }
+
bool MatchesGeneratorName(const std::string& name) const override;
bool SetSystemName(std::string const& s, cmMakefile* mf) override;
@@ -132,6 +134,8 @@ public:
bool GetSupportsUnityBuilds() const { return this->SupportsUnityBuilds; }
+ virtual cm::optional<std::string> FindMSBuildCommandEarly(cmMakefile* mf);
+
bool FindMakeProgram(cmMakefile* mf) override;
bool IsIPOSupported() const override { return true; }
@@ -222,6 +226,7 @@ protected:
bool SystemIsWindowsPhone = false;
bool SystemIsWindowsStore = false;
bool SystemIsAndroid = false;
+ bool MSBuildCommandInitialized = false;
private:
class Factory;
@@ -243,7 +248,6 @@ private:
LongestSourcePath LongestSource;
std::string MSBuildCommand;
- bool MSBuildCommandInitialized;
std::set<std::string> AndroidExecutableWarnings;
virtual std::string FindMSBuildCommand();
std::string FindDevEnvCommand() override;
diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h
index d1bd6b1..23c8a02 100644
--- a/Source/cmGlobalVisualStudioGenerator.h
+++ b/Source/cmGlobalVisualStudioGenerator.h
@@ -167,11 +167,6 @@ protected:
void WriteSLNHeader(std::ostream& fout);
- FindMakeProgramStage GetFindMakeProgramStage() const override
- {
- return FindMakeProgramStage::Early;
- }
-
bool ComputeTargetDepends() override;
class VSDependSet : public std::set<std::string>
{
diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx
index 3ecf32e..ec2e74f 100644
--- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx
+++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx
@@ -436,6 +436,9 @@ bool cmGlobalVisualStudioVersionedGenerator::MatchesGeneratorName(
bool cmGlobalVisualStudioVersionedGenerator::SetGeneratorInstance(
std::string const& i, cmMakefile* mf)
{
+ if (this->GeneratorInstance && i == *(this->GeneratorInstance)) {
+ return true;
+ }
if (!i.empty()) {
if (!this->vsSetupAPIHelper.SetVSInstance(i)) {
std::ostringstream e;
@@ -472,6 +475,9 @@ bool cmGlobalVisualStudioVersionedGenerator::SetGeneratorInstance(
cmStateEnums::INTERNAL);
}
+ // The selected instance may have a different MSBuild than previously found.
+ this->MSBuildCommandInitialized = false;
+
return true;
}
@@ -712,6 +718,17 @@ cmGlobalVisualStudioVersionedGenerator::GetWindows10SDKMaxVersionDefault(
return std::string();
}
+cm::optional<std::string>
+cmGlobalVisualStudioVersionedGenerator::FindMSBuildCommandEarly(cmMakefile* mf)
+{
+ std::string instance = mf->GetSafeDefinition("CMAKE_GENERATOR_INSTANCE");
+ if (!this->SetGeneratorInstance(instance, mf)) {
+ cmSystemTools::SetFatalErrorOccured();
+ return {};
+ }
+ return this->cmGlobalVisualStudio14Generator::FindMSBuildCommandEarly(mf);
+}
+
std::string cmGlobalVisualStudioVersionedGenerator::FindMSBuildCommand()
{
std::string msbuild;
diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.h b/Source/cmGlobalVisualStudioVersionedGenerator.h
index f07492d..b7760ac 100644
--- a/Source/cmGlobalVisualStudioVersionedGenerator.h
+++ b/Source/cmGlobalVisualStudioVersionedGenerator.h
@@ -8,6 +8,8 @@
#include <memory>
#include <string>
+#include <cm/optional>
+
#include "cmGlobalVisualStudio14Generator.h"
#include "cmVSSetupHelper.h"
@@ -29,6 +31,8 @@ public:
bool GetVSInstance(std::string& dir) const;
+ cm::optional<std::string> FindMSBuildCommandEarly(cmMakefile* mf) override;
+
cm::optional<std::string> GetVSInstanceVersion() const override;
AuxToolset FindAuxToolset(std::string& version,
@@ -72,4 +76,5 @@ private:
class Factory17;
friend class Factory17;
mutable cmVSSetupAPIHelper vsSetupAPIHelper;
+ cm::optional<std::string> GeneratorInstance;
};
diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h
index 72af4a4..4d7ee90 100644
--- a/Source/cmGlobalXCodeGenerator.h
+++ b/Source/cmGlobalXCodeGenerator.h
@@ -138,11 +138,6 @@ protected:
void AddExtraIDETargets() override;
void Generate() override;
- FindMakeProgramStage GetFindMakeProgramStage() const override
- {
- return FindMakeProgramStage::Early;
- }
-
private:
enum EmbedActionFlags
{
diff --git a/Tests/RunCMake/cmake_host_system_information/RunCMakeTest.cmake b/Tests/RunCMake/cmake_host_system_information/RunCMakeTest.cmake
index 189013f..87b6944 100644
--- a/Tests/RunCMake/cmake_host_system_information/RunCMakeTest.cmake
+++ b/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()
diff --git a/Tests/RunCMake/cmake_host_system_information/VsMSBuild.cmake b/Tests/RunCMake/cmake_host_system_information/VsMSBuild.cmake
new file mode 100644
index 0000000..30e616e
--- /dev/null
+++ b/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()
diff --git a/Tests/RunCMake/cmake_host_system_information/VsMSBuildMissing-result.txt b/Tests/RunCMake/cmake_host_system_information/VsMSBuildMissing-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/cmake_host_system_information/VsMSBuildMissing-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/cmake_host_system_information/VsMSBuildMissing-stderr.txt b/Tests/RunCMake/cmake_host_system_information/VsMSBuildMissing-stderr.txt
new file mode 100644
index 0000000..3a7dfef
--- /dev/null
+++ b/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\)$
diff --git a/Tests/RunCMake/cmake_host_system_information/VsMSBuildMissing.cmake b/Tests/RunCMake/cmake_host_system_information/VsMSBuildMissing.cmake
new file mode 100644
index 0000000..23c0364
--- /dev/null
+++ b/Tests/RunCMake/cmake_host_system_information/VsMSBuildMissing.cmake
@@ -0,0 +1 @@
+cmake_host_system_information(RESULT msbuild QUERY VS_MSBUILD_COMMAND)