packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmAuxSourceDirectoryCommand.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmAuxSourceDirectoryCommand.h"
13 #include "cmSourceFile.h"
14
15 #include <cmsys/Directory.hxx>
16
17 // cmAuxSourceDirectoryCommand
18 bool cmAuxSourceDirectoryCommand::InitialPass
19 (std::vector<std::string> const& args, cmExecutionStatus &)
20 {
21   if(args.size() < 2 || args.size() > 2)
22     {
23     this->SetError("called with incorrect number of arguments");
24     return false;
25     }
26
27   std::string sourceListValue;
28   std::string templateDirectory = args[0];
29   this->Makefile->AddExtraDirectory(templateDirectory.c_str());
30   std::string tdir;
31   if(!cmSystemTools::FileIsFullPath(templateDirectory.c_str()))
32     {
33     tdir = this->Makefile->GetCurrentDirectory();
34     tdir += "/";
35     tdir += templateDirectory;
36     }
37   else
38     {
39     tdir = templateDirectory;
40     }
41
42   // was the list already populated
43   const char *def = this->Makefile->GetDefinition(args[1].c_str());
44   if (def)
45     {
46     sourceListValue = def;
47     }
48
49   // Load all the files in the directory
50   cmsys::Directory dir;
51   if(dir.Load(tdir.c_str()))
52     {
53     size_t numfiles = dir.GetNumberOfFiles();
54     for(size_t i =0; i < numfiles; ++i)
55       {
56       std::string file = dir.GetFile(static_cast<unsigned long>(i));
57       // Split the filename into base and extension
58       std::string::size_type dotpos = file.rfind(".");
59       if( dotpos != std::string::npos )
60         {
61         std::string ext = file.substr(dotpos+1);
62         std::string base = file.substr(0, dotpos);
63         // Process only source files
64         if( base.size() != 0
65             && std::find( this->Makefile->GetSourceExtensions().begin(),
66                           this->Makefile->GetSourceExtensions().end(), ext )
67                  != this->Makefile->GetSourceExtensions().end() )
68           {
69           std::string fullname = templateDirectory;
70           fullname += "/";
71           fullname += file;
72           // add the file as a class file so
73           // depends can be done
74           cmSourceFile* sf =
75             this->Makefile->GetOrCreateSource(fullname.c_str());
76           sf->SetProperty("ABSTRACT","0");
77           if(!sourceListValue.empty())
78             {
79             sourceListValue += ";";
80             }
81           sourceListValue += fullname;
82           }
83         }
84       }
85     }
86   this->Makefile->AddDefinition(args[1].c_str(), sourceListValue.c_str());
87   return true;
88 }
89