Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmAuxSourceDirectoryCommand.cxx
blob9944820d1e3057dc594d8a779e2629959148b647
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmAuxSourceDirectoryCommand.cxx,v $
5 Language: C++
6 <<<<<<< cmAuxSourceDirectoryCommand.cxx
7 Date: $Date: 2008/01/23 15:27:59 $
8 Version: $Revision: 1.26 $
9 =======
10 Date: $Date: 2008-04-26 12:39:27 $
11 Version: $Revision: 1.27 $
12 >>>>>>> 1.27
14 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
15 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
17 This software is distributed WITHOUT ANY WARRANTY; without even
18 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 PURPOSE. See the above copyright notices for more information.
21 =========================================================================*/
22 #include "cmAuxSourceDirectoryCommand.h"
23 #include "cmSourceFile.h"
25 #include <cmsys/Directory.hxx>
27 // cmAuxSourceDirectoryCommand
28 bool cmAuxSourceDirectoryCommand::InitialPass
29 (std::vector<std::string> const& args, cmExecutionStatus &)
31 if(args.size() < 2 || args.size() > 2)
33 this->SetError("called with incorrect number of arguments");
34 return false;
37 std::string sourceListValue;
38 std::string templateDirectory = args[0];
39 this->Makefile->AddExtraDirectory(templateDirectory.c_str());
40 std::string tdir;
41 if(!cmSystemTools::FileIsFullPath(templateDirectory.c_str()))
43 tdir = this->Makefile->GetCurrentDirectory();
44 tdir += "/";
45 tdir += templateDirectory;
47 else
49 tdir = templateDirectory;
52 // was the list already populated
53 const char *def = this->Makefile->GetDefinition(args[1].c_str());
54 if (def)
56 sourceListValue = def;
59 // Load all the files in the directory
60 cmsys::Directory dir;
61 if(dir.Load(tdir.c_str()))
63 size_t numfiles = dir.GetNumberOfFiles();
64 for(size_t i =0; i < numfiles; ++i)
66 std::string file = dir.GetFile(static_cast<unsigned long>(i));
67 // Split the filename into base and extension
68 std::string::size_type dotpos = file.rfind(".");
69 if( dotpos != std::string::npos )
71 std::string ext = file.substr(dotpos+1);
72 std::string base = file.substr(0, dotpos);
73 // Process only source files
74 if( base.size() != 0
75 && std::find( this->Makefile->GetSourceExtensions().begin(),
76 this->Makefile->GetSourceExtensions().end(), ext )
77 != this->Makefile->GetSourceExtensions().end() )
79 std::string fullname = templateDirectory;
80 fullname += "/";
81 fullname += file;
82 // add the file as a class file so
83 // depends can be done
84 cmSourceFile* sf =
85 this->Makefile->GetOrCreateSource(fullname.c_str());
86 sf->SetProperty("ABSTRACT","0");
87 if(!sourceListValue.empty())
89 sourceListValue += ";";
91 sourceListValue += fullname;
96 this->Makefile->AddDefinition(args[1].c_str(), sourceListValue.c_str());
97 return true;