Browse Source

Make --strict-mode option, and integrate with cmake-gui

Bill Hoffman 15 years ago
parent
commit
f794d589a4

+ 12 - 2
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)

+ 3 - 1
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)

+ 8 - 1
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())

+ 1 - 0
Source/QtDialog/CMakeSetupDialog.h

@@ -93,6 +93,7 @@ protected:
   QAction* ConfigureAction;
   QAction* GenerateAction;
   QAction* SuppressDevWarningsAction;
+  QAction* StrictModeAction;
   QAction* InstallForCommandLineAction;
   State CurrentState;
 

+ 8 - 0
Source/QtDialog/QCMake.cxx

@@ -28,6 +28,7 @@ QCMake::QCMake(QObject* p)
   : QObject(p)
 {
   this->SuppressDevWarnings = false;
+  this->StrictMode = false;
   qRegisterMetaType<QCMakeProperty>();
   qRegisterMetaType<QCMakePropertyList>();
   
@@ -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;
+}

+ 3 - 0
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;

+ 10 - 3
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)

+ 1 - 0
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;

+ 6 - 0
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<std::string>& 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);

+ 3 - 0
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;

+ 3 - 0
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 "