From afeb4eb243e01df5c7396dc346f2629b21115e2c Mon Sep 17 00:00:00 2001 From: James Johnston Date: Wed, 5 Aug 2015 21:23:07 +0000 Subject: [PATCH] nmake/jom: Only warn about bad VS environment if compiler not found. nmake and jom generators no longer warn about missing INCLUDE/LIB environment variables unless the C/CXX compiler cannot be found. This is useful if the user does not want to use these generators with the Visual C++ compiler, or they do not want to enable any language. --- Source/cmGlobalGenerator.h | 4 +-- Source/cmGlobalJOMMakefileGenerator.cxx | 28 ++++++++------- Source/cmGlobalJOMMakefileGenerator.h | 3 ++ Source/cmGlobalNMakeMakefileGenerator.cxx | 28 ++++++++------- Source/cmGlobalNMakeMakefileGenerator.h | 3 ++ .../BadCompilerC-stderr-JOM.txt | 17 +++++++++ .../BadCompilerC-stderr-NMake.txt | 17 +++++++++ .../BadCompilerCXX-stderr-JOM.txt | 17 +++++++++ .../BadCompilerCXX-stderr-NMake.txt | 17 +++++++++ .../BadCompilerCandCXX-stderr-JOM.txt | 35 +++++++++++++++++++ .../BadCompilerCandCXX-stderr-NMake.txt | 35 +++++++++++++++++++ .../CompilerNotFound/RunCMakeTest.cmake | 14 ++++++++ 12 files changed, 192 insertions(+), 26 deletions(-) create mode 100644 Tests/RunCMake/CompilerNotFound/BadCompilerC-stderr-JOM.txt create mode 100644 Tests/RunCMake/CompilerNotFound/BadCompilerC-stderr-NMake.txt create mode 100644 Tests/RunCMake/CompilerNotFound/BadCompilerCXX-stderr-JOM.txt create mode 100644 Tests/RunCMake/CompilerNotFound/BadCompilerCXX-stderr-NMake.txt create mode 100644 Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-stderr-JOM.txt create mode 100644 Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-stderr-NMake.txt diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 3402fbcde..ec916aeee 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -374,6 +374,8 @@ protected: void SetLanguageEnabledFlag(const std::string& l, cmMakefile* mf); void SetLanguageEnabledMaps(const std::string& l, cmMakefile* mf); void FillExtensionToLanguageMap(const std::string& l, cmMakefile* mf); + virtual void PrintCompilerAdvice(std::ostream& os, std::string const& lang, + const char* envVar) const; virtual bool ComputeTargetDepends(); @@ -462,8 +464,6 @@ private: virtual void ForceLinkerLanguages(); - virtual void PrintCompilerAdvice(std::ostream& os, std::string const& lang, - const char* envVar) const; void CheckCompilerIdCompatibility(cmMakefile* mf, std::string const& lang) const; diff --git a/Source/cmGlobalJOMMakefileGenerator.cxx b/Source/cmGlobalJOMMakefileGenerator.cxx index 50e70531d..3f33f91fc 100644 --- a/Source/cmGlobalJOMMakefileGenerator.cxx +++ b/Source/cmGlobalJOMMakefileGenerator.cxx @@ -36,18 +36,6 @@ void cmGlobalJOMMakefileGenerator // pick a default mf->AddDefinition("CMAKE_GENERATOR_CC", "cl"); mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl"); - if(!(cmSystemTools::GetEnv("INCLUDE") && - cmSystemTools::GetEnv("LIB")) - ) - { - std::string message = "To use the JOM generator, cmake must be run " - "from a shell that can use the compiler cl from the command line. " - "This environment does not contain INCLUDE, LIB, or LIBPATH, and " - "these must be set for the cl compiler to work. "; - mf->IssueMessage(cmake::WARNING, - message); - } - this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional); } @@ -58,3 +46,19 @@ void cmGlobalJOMMakefileGenerator entry.Name = cmGlobalJOMMakefileGenerator::GetActualName(); entry.Brief = "Generates JOM makefiles."; } + +//---------------------------------------------------------------------------- +void cmGlobalJOMMakefileGenerator::PrintCompilerAdvice(std::ostream& os, + std::string const& lang, + const char* envVar) const +{ + if(lang == "CXX" || lang == "C") + { + os << + "To use the JOM generator with Visual C++, cmake must be run from a " + "shell that can use the compiler cl from the command line. This " + "environment is unable to invoke the cl compiler. To fix this problem, " + "run cmake from the Visual Studio Command Prompt (vcvarsall.bat).\n"; + } + this->cmGlobalUnixMakefileGenerator3::PrintCompilerAdvice(os, lang, envVar); +} diff --git a/Source/cmGlobalJOMMakefileGenerator.h b/Source/cmGlobalJOMMakefileGenerator.h index 2185b23c0..1869fed79 100644 --- a/Source/cmGlobalJOMMakefileGenerator.h +++ b/Source/cmGlobalJOMMakefileGenerator.h @@ -42,6 +42,9 @@ public: */ virtual void EnableLanguage(std::vectorconst& languages, cmMakefile *, bool optional); +private: + void PrintCompilerAdvice(std::ostream& os, std::string const& lang, + const char* envVar) const; }; #endif diff --git a/Source/cmGlobalNMakeMakefileGenerator.cxx b/Source/cmGlobalNMakeMakefileGenerator.cxx index 4219c3404..7c570a627 100644 --- a/Source/cmGlobalNMakeMakefileGenerator.cxx +++ b/Source/cmGlobalNMakeMakefileGenerator.cxx @@ -36,18 +36,6 @@ void cmGlobalNMakeMakefileGenerator // pick a default mf->AddDefinition("CMAKE_GENERATOR_CC", "cl"); mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl"); - if(!(cmSystemTools::GetEnv("INCLUDE") && - cmSystemTools::GetEnv("LIB")) - ) - { - std::string message = "To use the NMake generator, cmake must be run " - "from a shell that can use the compiler cl from the command line. " - "This environment does not contain INCLUDE, LIB, or LIBPATH, and " - "these must be set for the cl compiler to work. "; - mf->IssueMessage(cmake::WARNING, - message); - } - this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional); } @@ -58,3 +46,19 @@ void cmGlobalNMakeMakefileGenerator entry.Name = cmGlobalNMakeMakefileGenerator::GetActualName(); entry.Brief = "Generates NMake makefiles."; } + +//---------------------------------------------------------------------------- +void cmGlobalNMakeMakefileGenerator::PrintCompilerAdvice(std::ostream& os, + std::string const& lang, + const char* envVar) const +{ + if(lang == "CXX" || lang == "C") + { + os << + "To use the NMake generator with Visual C++, cmake must be run from a " + "shell that can use the compiler cl from the command line. This " + "environment is unable to invoke the cl compiler. To fix this problem, " + "run cmake from the Visual Studio Command Prompt (vcvarsall.bat).\n"; + } + this->cmGlobalUnixMakefileGenerator3::PrintCompilerAdvice(os, lang, envVar); +} diff --git a/Source/cmGlobalNMakeMakefileGenerator.h b/Source/cmGlobalNMakeMakefileGenerator.h index dd72c4989..3c8375aed 100644 --- a/Source/cmGlobalNMakeMakefileGenerator.h +++ b/Source/cmGlobalNMakeMakefileGenerator.h @@ -40,6 +40,9 @@ public: */ virtual void EnableLanguage(std::vectorconst& languages, cmMakefile *, bool optional); +private: + void PrintCompilerAdvice(std::ostream& os, std::string const& lang, + const char* envVar) const; }; #endif diff --git a/Tests/RunCMake/CompilerNotFound/BadCompilerC-stderr-JOM.txt b/Tests/RunCMake/CompilerNotFound/BadCompilerC-stderr-JOM.txt new file mode 100644 index 000000000..b7db7eb58 --- /dev/null +++ b/Tests/RunCMake/CompilerNotFound/BadCompilerC-stderr-JOM.txt @@ -0,0 +1,17 @@ +CMake Error at BadCompilerC.cmake:2 \(enable_language\): + The CMAKE_C_COMPILER: + + no-C-compiler + + is not a full path and was not found in the PATH. + + To use the JOM generator with Visual C\+\+, cmake must be run from a shell + that can use the compiler cl from the command line. This environment is + unable to invoke the cl compiler. To fix this problem, run cmake from the + Visual Studio Command Prompt \(vcvarsall.bat\). + + Tell CMake where to find the compiler by setting either the environment + variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to + the compiler, or to the compiler name if it is in the PATH. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/CompilerNotFound/BadCompilerC-stderr-NMake.txt b/Tests/RunCMake/CompilerNotFound/BadCompilerC-stderr-NMake.txt new file mode 100644 index 000000000..03c593340 --- /dev/null +++ b/Tests/RunCMake/CompilerNotFound/BadCompilerC-stderr-NMake.txt @@ -0,0 +1,17 @@ +CMake Error at BadCompilerC.cmake:2 \(enable_language\): + The CMAKE_C_COMPILER: + + no-C-compiler + + is not a full path and was not found in the PATH. + + To use the NMake generator with Visual C\+\+, cmake must be run from a shell + that can use the compiler cl from the command line. This environment is + unable to invoke the cl compiler. To fix this problem, run cmake from the + Visual Studio Command Prompt \(vcvarsall.bat\). + + Tell CMake where to find the compiler by setting either the environment + variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to + the compiler, or to the compiler name if it is in the PATH. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/CompilerNotFound/BadCompilerCXX-stderr-JOM.txt b/Tests/RunCMake/CompilerNotFound/BadCompilerCXX-stderr-JOM.txt new file mode 100644 index 000000000..4b42ea6ff --- /dev/null +++ b/Tests/RunCMake/CompilerNotFound/BadCompilerCXX-stderr-JOM.txt @@ -0,0 +1,17 @@ +CMake Error at BadCompilerCXX.cmake:2 \(enable_language\): + The CMAKE_CXX_COMPILER: + + no-CXX-compiler + + is not a full path and was not found in the PATH. + + To use the JOM generator with Visual C\+\+, cmake must be run from a shell + that can use the compiler cl from the command line. This environment is + unable to invoke the cl compiler. To fix this problem, run cmake from the + Visual Studio Command Prompt \(vcvarsall.bat\). + + Tell CMake where to find the compiler by setting either the environment + variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path + to the compiler, or to the compiler name if it is in the PATH. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/CompilerNotFound/BadCompilerCXX-stderr-NMake.txt b/Tests/RunCMake/CompilerNotFound/BadCompilerCXX-stderr-NMake.txt new file mode 100644 index 000000000..1bfcdcc41 --- /dev/null +++ b/Tests/RunCMake/CompilerNotFound/BadCompilerCXX-stderr-NMake.txt @@ -0,0 +1,17 @@ +CMake Error at BadCompilerCXX.cmake:2 \(enable_language\): + The CMAKE_CXX_COMPILER: + + no-CXX-compiler + + is not a full path and was not found in the PATH. + + To use the NMake generator with Visual C\+\+, cmake must be run from a shell + that can use the compiler cl from the command line. This environment is + unable to invoke the cl compiler. To fix this problem, run cmake from the + Visual Studio Command Prompt \(vcvarsall.bat\). + + Tell CMake where to find the compiler by setting either the environment + variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path + to the compiler, or to the compiler name if it is in the PATH. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-stderr-JOM.txt b/Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-stderr-JOM.txt new file mode 100644 index 000000000..f25a267a6 --- /dev/null +++ b/Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-stderr-JOM.txt @@ -0,0 +1,35 @@ +CMake Error at BadCompilerCandCXX.cmake:3 \(project\): + The CMAKE_C_COMPILER: + + no-C-compiler + + is not a full path and was not found in the PATH. + + To use the JOM generator with Visual C\+\+, cmake must be run from a shell + that can use the compiler cl from the command line. This environment is + unable to invoke the cl compiler. To fix this problem, run cmake from the + Visual Studio Command Prompt \(vcvarsall.bat\). + + Tell CMake where to find the compiler by setting either the environment + variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to + the compiler, or to the compiler name if it is in the PATH. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) ++ +CMake Error at BadCompilerCandCXX.cmake:3 \(project\): + The CMAKE_CXX_COMPILER: + + no-CXX-compiler + + is not a full path and was not found in the PATH. + + To use the JOM generator with Visual C\+\+, cmake must be run from a shell + that can use the compiler cl from the command line. This environment is + unable to invoke the cl compiler. To fix this problem, run cmake from the + Visual Studio Command Prompt \(vcvarsall.bat\). + + Tell CMake where to find the compiler by setting either the environment + variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path + to the compiler, or to the compiler name if it is in the PATH. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-stderr-NMake.txt b/Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-stderr-NMake.txt new file mode 100644 index 000000000..ffcdce868 --- /dev/null +++ b/Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-stderr-NMake.txt @@ -0,0 +1,35 @@ +CMake Error at BadCompilerCandCXX.cmake:3 \(project\): + The CMAKE_C_COMPILER: + + no-C-compiler + + is not a full path and was not found in the PATH. + + To use the NMake generator with Visual C\+\+, cmake must be run from a shell + that can use the compiler cl from the command line. This environment is + unable to invoke the cl compiler. To fix this problem, run cmake from the + Visual Studio Command Prompt \(vcvarsall.bat\). + + Tell CMake where to find the compiler by setting either the environment + variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to + the compiler, or to the compiler name if it is in the PATH. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) ++ +CMake Error at BadCompilerCandCXX.cmake:3 \(project\): + The CMAKE_CXX_COMPILER: + + no-CXX-compiler + + is not a full path and was not found in the PATH. + + To use the NMake generator with Visual C\+\+, cmake must be run from a shell + that can use the compiler cl from the command line. This environment is + unable to invoke the cl compiler. To fix this problem, run cmake from the + Visual Studio Command Prompt \(vcvarsall.bat\). + + Tell CMake where to find the compiler by setting either the environment + variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path + to the compiler, or to the compiler name if it is in the PATH. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/CompilerNotFound/RunCMakeTest.cmake b/Tests/RunCMake/CompilerNotFound/RunCMakeTest.cmake index 8b84f39dd..19d149c11 100644 --- a/Tests/RunCMake/CompilerNotFound/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompilerNotFound/RunCMakeTest.cmake @@ -4,6 +4,20 @@ if("${RunCMake_GENERATOR}" MATCHES "Visual Studio|Xcode") run_cmake(NoCompilerC-IDE) run_cmake(NoCompilerCXX-IDE) run_cmake(NoCompilerCandCXX-IDE) +elseif(RunCMake_GENERATOR STREQUAL "NMake Makefiles") + set(RunCMake-stderr-file BadCompilerC-stderr-NMake.txt) + run_cmake(BadCompilerC) + set(RunCMake-stderr-file BadCompilerCXX-stderr-NMake.txt) + run_cmake(BadCompilerCXX) + set(RunCMake-stderr-file BadCompilerCandCXX-stderr-NMake.txt) + run_cmake(BadCompilerCandCXX) +elseif(RunCMake_GENERATOR STREQUAL "NMake Makefiles JOM") + set(RunCMake-stderr-file BadCompilerC-stderr-JOM.txt) + run_cmake(BadCompilerC) + set(RunCMake-stderr-file BadCompilerCXX-stderr-JOM.txt) + run_cmake(BadCompilerCXX) + set(RunCMake-stderr-file BadCompilerCandCXX-stderr-JOM.txt) + run_cmake(BadCompilerCandCXX) else() run_cmake(BadCompilerC) run_cmake(BadCompilerCXX)