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