From f794d589a44918c905911eb7688d69350922c6b3 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Mon, 12 Jul 2010 15:48:51 -0400 Subject: [PATCH] Make --strict-mode option, and integrate with cmake-gui --- Modules/CMakeDetermineCompilerABI.cmake | 14 ++++++++++++-- Modules/CMakeDetermineCompilerId.cmake | 4 +++- Source/QtDialog/CMakeSetupDialog.cxx | 9 ++++++++- Source/QtDialog/CMakeSetupDialog.h | 1 + Source/QtDialog/QCMake.cxx | 8 ++++++++ Source/QtDialog/QCMake.h | 3 +++ Source/cmCommandArgumentParserHelper.cxx | 13 ++++++++++--- Source/cmCommandArgumentParserHelper.h | 1 + Source/cmake.cxx | 6 ++++++ Source/cmake.h | 3 +++ Source/cmakemain.cxx | 3 +++ 11 files changed, 58 insertions(+), 7 deletions(-) diff --git a/Modules/CMakeDetermineCompilerABI.cmake b/Modules/CMakeDetermineCompilerABI.cmake index d6df30590..aa21c3127 100644 --- a/Modules/CMakeDetermineCompilerABI.cmake +++ b/Modules/CMakeDetermineCompilerABI.cmake @@ -24,9 +24,13 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ABI lang src) # Compile the ABI identification source. SET(BIN "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeDetermineCompilerABI_${lang}.bin") + SET(CMAKE_FLAGS ) + IF(DEFINED CMAKE_${lang}_VERBOSE_FLAG) + SET(CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_${lang}_VERBOSE_FLAG}") + ENDIF() TRY_COMPILE(CMAKE_DETERMINE_${lang}_ABI_COMPILED ${CMAKE_BINARY_DIR} ${src} - CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_${lang}_VERBOSE_FLAG}" + CMAKE_FLAGS "${CMAKE_FLAGS}" "-DCMAKE_${lang}_STANDARD_LIBRARIES=" OUTPUT_VARIABLE OUTPUT COPY_FILE "${BIN}" @@ -58,10 +62,16 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ABI lang src) # Parse implicit linker information for this language, if available. SET(implicit_dirs "") SET(implicit_libs "") + SET(MULTI_ARCH FALSE) + IF(DEFINED CMAKE_OSX_ARCHITECTURES) + IF( "${CMAKE_OSX_ARCHITECTURES}" MATCHES ";" ) + SET(MULTI_ARCH TRUE) + ENDIF() + ENDIF() IF(CMAKE_${lang}_VERBOSE_FLAG # Implicit link information cannot be used explicitly for # multiple OS X architectures, so we skip it. - AND NOT "${CMAKE_OSX_ARCHITECTURES}" MATCHES ";" + AND NOT MULTI_ARCH # Skip this with Xcode for now. AND NOT "${CMAKE_GENERATOR}" MATCHES Xcode) CMAKE_PARSE_IMPLICIT_LINK_INFO("${OUTPUT}" implicit_libs implicit_dirs log) diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index bf78a5ba3..9a3884af9 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -243,7 +243,9 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file) # ENDIF("${CMAKE_EXECUTABLE_MAGIC}" MATCHES "feedface") ENDIF(NOT CMAKE_EXECUTABLE_FORMAT) - + IF(NOT DEFINED CMAKE_EXECUTABLE_FORMAT) + SET(CMAKE_EXECUTABLE_FORMAT) + ENDIF() # Return the information extracted. SET(CMAKE_${lang}_COMPILER_ID "${CMAKE_${lang}_COMPILER_ID}" PARENT_SCOPE) SET(CMAKE_${lang}_PLATFORM_ID "${CMAKE_${lang}_PLATFORM_ID}" PARENT_SCOPE) diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 74a3d3594..7600897bd 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -114,8 +114,12 @@ CMakeSetupDialog::CMakeSetupDialog() this, SLOT(doInstallForCommandLine())); #endif QMenu* OptionsMenu = this->menuBar()->addMenu(tr("&Options")); - this->SuppressDevWarningsAction = OptionsMenu->addAction(tr("&Suppress dev Warnings (-Wno-dev)")); + this->SuppressDevWarningsAction = + OptionsMenu->addAction(tr("&Suppress dev Warnings (-Wno-dev)")); this->SuppressDevWarningsAction->setCheckable(true); + this->StrictModeAction = + OptionsMenu->addAction(tr("&Strict Mode (--strict-mode)")); + this->StrictModeAction->setCheckable(true); QAction* debugAction = OptionsMenu->addAction(tr("&Debug Output")); debugAction->setCheckable(true); @@ -240,6 +244,9 @@ void CMakeSetupDialog::initialize() QObject::connect(this->SuppressDevWarningsAction, SIGNAL(triggered(bool)), this->CMakeThread->cmakeInstance(), SLOT(setSuppressDevWarnings(bool))); + QObject::connect(this->StrictModeAction, SIGNAL(triggered(bool)), + this->CMakeThread->cmakeInstance(), + SLOT(setStrictMode(bool))); if(!this->SourceDirectory->text().isEmpty() || !this->BinaryDirectory->lineEdit()->text().isEmpty()) diff --git a/Source/QtDialog/CMakeSetupDialog.h b/Source/QtDialog/CMakeSetupDialog.h index 0e3caec44..cd2be6e5f 100644 --- a/Source/QtDialog/CMakeSetupDialog.h +++ b/Source/QtDialog/CMakeSetupDialog.h @@ -93,6 +93,7 @@ protected: QAction* ConfigureAction; QAction* GenerateAction; QAction* SuppressDevWarningsAction; + QAction* StrictModeAction; QAction* InstallForCommandLineAction; State CurrentState; diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index dc31fad44..31daf3c86 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -28,6 +28,7 @@ QCMake::QCMake(QObject* p) : QObject(p) { this->SuppressDevWarnings = false; + this->StrictMode = false; qRegisterMetaType(); qRegisterMetaType(); @@ -164,6 +165,8 @@ void QCMake::configure() this->CMakeInstance->CreateGlobalGenerator(this->Generator.toAscii().data())); this->CMakeInstance->LoadCache(); this->CMakeInstance->SetSuppressDevWarnings(this->SuppressDevWarnings); + std::cerr << "set strict " << this->StrictMode << "\n"; + this->CMakeInstance->SetStrictMode(this->StrictMode); this->CMakeInstance->PreLoadCMakeFiles(); cmSystemTools::ResetErrorOccuredFlag(); @@ -417,3 +420,8 @@ void QCMake::setSuppressDevWarnings(bool value) { this->SuppressDevWarnings = value; } + +void QCMake::setStrictMode(bool value) +{ + this->StrictMode = value; +} diff --git a/Source/QtDialog/QCMake.h b/Source/QtDialog/QCMake.h index bbfb3d7c5..f20893f22 100644 --- a/Source/QtDialog/QCMake.h +++ b/Source/QtDialog/QCMake.h @@ -88,6 +88,8 @@ public slots: void setDebugOutput(bool); /// set whether to do suppress dev warnings void setSuppressDevWarnings(bool value); + /// set whether to run cmake in strict mode + void setStrictMode(bool value); public: /// get the list of cache properties @@ -133,6 +135,7 @@ protected: static void errorCallback(const char* msg, const char* title, bool&, void* cd); bool SuppressDevWarnings; + bool StrictMode; QString SourceDirectory; QString BinaryDirectory; QString Generator; diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx index 027a2ba78..410058f1c 100644 --- a/Source/cmCommandArgumentParserHelper.cxx +++ b/Source/cmCommandArgumentParserHelper.cxx @@ -20,6 +20,7 @@ int cmCommandArgument_yyparse( yyscan_t yyscanner ); // cmCommandArgumentParserHelper::cmCommandArgumentParserHelper() { + this->StrictMode = false; this->FileLine = -1; this->FileName = 0; this->RemoveEmpty = true; @@ -123,10 +124,15 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var) const char* value = this->Makefile->GetDefinition(var); if(!value && !this->RemoveEmpty) { - if(!this->Makefile->VariableCleared(var)) + // check to see if we need to print a warning + // if strict mode is on and the variable has + // not been "cleared"/initialized with a set(foo ) call + if(this->StrictMode && !this->Makefile->VariableCleared(var)) { - std::cerr << this->FileName << ":" << this->FileLine << ":" << - " warning: uninitialized variable \'" << var << "\'\n"; + cmOStringStream msg; + msg << this->FileName << ":" << this->FileLine << ":" << + " warning: uninitialized variable \'" << var << "\'"; + cmSystemTools::Message(msg.str().c_str()); } return 0; } @@ -324,6 +330,7 @@ void cmCommandArgumentParserHelper::Error(const char* str) void cmCommandArgumentParserHelper::SetMakefile(const cmMakefile* mf) { this->Makefile = mf; + this->StrictMode = mf->GetCMakeInstance()->GetStrictMode(); } void cmCommandArgumentParserHelper::SetResult(const char* value) diff --git a/Source/cmCommandArgumentParserHelper.h b/Source/cmCommandArgumentParserHelper.h index 62cbc80ba..d7206ee97 100644 --- a/Source/cmCommandArgumentParserHelper.h +++ b/Source/cmCommandArgumentParserHelper.h @@ -96,6 +96,7 @@ private: const cmMakefile* Makefile; std::string Result; const char* FileName; + bool StrictMode; long FileLine; bool EscapeQuotes; std::string ErrorString; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 0f9ef1bb3..2e777483d 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -140,6 +140,7 @@ void cmNeedBackwardsCompatibility(const std::string& variable, cmake::cmake() { this->Trace = false; + this->StrictMode = false; this->SuppressDevWarnings = false; this->DoSuppressDevWarnings = false; this->DebugOutput = false; @@ -613,6 +614,11 @@ void cmake::SetArgs(const std::vector& args) std::cout << "Running with trace output on.\n"; this->SetTrace(true); } + else if(arg.find("--strict-mode",0) == 0) + { + std::cout << "Running in strict mode.\n"; + this->SetStrictMode(true); + } else if(arg.find("-G",0) == 0) { std::string value = arg.substr(2); diff --git a/Source/cmake.h b/Source/cmake.h index 8312795eb..5c2f17ac4 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -306,6 +306,8 @@ class cmake // Do we want trace output during the cmake run. bool GetTrace() { return this->Trace;} void SetTrace(bool b) { this->Trace = b;} + bool GetStrictMode() { return this->StrictMode;} + void SetStrictMode(bool b) { this->StrictMode = b;} // Define a property void DefineProperty(const char *name, cmProperty::ScopeType scope, const char *ShortDescription, @@ -443,6 +445,7 @@ private: bool ScriptMode; bool DebugOutput; bool Trace; + bool StrictMode; std::string CMakeEditCommand; std::string CMakeCommand; std::string CXXEnvironment; diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index ddff71d9e..ac2a33847 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -120,6 +120,9 @@ static const char * cmDocumentationOptions[][3] = {"--trace", "Put cmake in trace mode.", "Print a trace of all calls made and from where with " "message(send_error ) calls."}, + {"--strict-mode", "Put cmake in strict mode.", + "In strict mode cmake will print a warning when an uninitialized variable " + "is used."}, {"--help-command cmd [file]", "Print help for a single command and exit.", "Full documentation specific to the given command is displayed. " "If a file is specified, the documentation is written into and the output "