Преглед на файлове

ENH: Add support for importing modules without specifying path

Andy Cedilnik преди 21 години
родител
ревизия
451522381d
променени са 4 файла, в които са добавени 23 реда и са изтрити 5 реда
  1. 17 2
      Source/cmIncludeCommand.cxx
  2. 4 1
      Source/cmIncludeCommand.h
  3. 1 1
      Tests/LoadCommand/CMakeLists.txt
  4. 1 1
      Tests/LoadCommandOneConfig/CMakeLists.txt

+ 17 - 2
Source/cmIncludeCommand.cxx

@@ -27,17 +27,32 @@ bool cmIncludeCommand::InitialPass(std::vector<std::string> const& args)
       return false;
     }
   bool optional = false;
+
+  std::string fname = args[0].c_str();
+
   if(args.size() == 2)
     {
     optional = args[1] == "OPTIONAL";
     }
   
+  if(fname.find("/") == fname.npos)
+    {
+    // Not a path. Maybe module.
+    std::string module = fname;
+    module += ".cmake";
+    std::string mfile = m_Makefile->GetModulesFile(module.c_str());
+    if ( mfile.size() )
+      {
+      std::cout << "Module found: " << mfile.c_str() << std::endl;
+      fname = mfile.c_str();
+      }
+    }
   bool readit = m_Makefile->ReadListFile( m_Makefile->GetCurrentListFile(), 
-                                          args[0].c_str());
+                                          fname.c_str() );
   if(!optional && !readit)
     {
     std::string m = "Could not find include file: ";
-    m += args[0];
+    m += fname;
     this->SetError(m.c_str());
     return false;
     }

+ 4 - 1
Source/cmIncludeCommand.h

@@ -75,10 +75,13 @@ public:
     {
     return
       "  INCLUDE(file1 [OPTIONAL])\n"
+      "  INCLUDE(module [OPTIONAL])\n"
       "Reads CMake listfile code from the given file.  Commands in the file "
       "are processed immediately as if they were written in place of the "
       "INCLUDE command.  If OPTIONAL is present, then no error "
-      "is raised if the file does not exist.";
+      "is raised if the file does not exist.\n"
+      "If module is specified instead of file, the file with name "
+      "module.cmake is searched in the CMAKE_MODULE_PATH.";
     }
   
   cmTypeMacro(cmIncludeCommand, cmCommand);

+ 1 - 1
Tests/LoadCommand/CMakeLists.txt

@@ -6,7 +6,7 @@ SET (TEST_COMMAND_TEST1 1)
 INCLUDE (${CMAKE_ROOT}/Modules/CheckTypeSize.cmake)
 CHECK_TYPE_SIZE(char  SIZEOF_CHAR)
 
-INCLUDE (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
+INCLUDE (CheckFunctionExists)
 CHECK_FUNCTION_EXISTS(printf        HAVE_PRINTF)
 CHECK_FUNCTION_EXISTS(vsblabla      HAVE_VSBLABLA)
 

+ 1 - 1
Tests/LoadCommandOneConfig/CMakeLists.txt

@@ -6,7 +6,7 @@ SET (TEST_COMMAND_TEST1 1)
 INCLUDE (${CMAKE_ROOT}/Modules/CheckTypeSize.cmake)
 CHECK_TYPE_SIZE(char  SIZEOF_CHAR)
 
-INCLUDE (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
+INCLUDE (CheckFunctionExists)
 CHECK_FUNCTION_EXISTS(printf        HAVE_PRINTF)
 CHECK_FUNCTION_EXISTS(vsblabla      HAVE_VSBLABLA)