1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
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"
15 #include <cmsys/Directory.hxx>
17 // cmAuxSourceDirectoryCommand
18 bool cmAuxSourceDirectoryCommand::InitialPass
19 (std::vector<std::string> const& args, cmExecutionStatus &)
21 if(args.size() < 2 || args.size() > 2)
23 this->SetError("called with incorrect number of arguments");
27 std::string sourceListValue;
28 std::string templateDirectory = args[0];
29 this->Makefile->AddExtraDirectory(templateDirectory.c_str());
31 if(!cmSystemTools::FileIsFullPath(templateDirectory.c_str()))
33 tdir = this->Makefile->GetCurrentDirectory();
35 tdir += templateDirectory;
39 tdir = templateDirectory;
42 // was the list already populated
43 const char *def = this->Makefile->GetDefinition(args[1].c_str());
46 sourceListValue = def;
49 // Load all the files in the directory
51 if(dir.Load(tdir.c_str()))
53 size_t numfiles = dir.GetNumberOfFiles();
54 for(size_t i =0; i < numfiles; ++i)
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 )
61 std::string ext = file.substr(dotpos+1);
62 std::string base = file.substr(0, dotpos);
63 // Process only source files
65 && std::find( this->Makefile->GetSourceExtensions().begin(),
66 this->Makefile->GetSourceExtensions().end(), ext )
67 != this->Makefile->GetSourceExtensions().end() )
69 std::string fullname = templateDirectory;
72 // add the file as a class file so
73 // depends can be done
75 this->Makefile->GetOrCreateSource(fullname.c_str());
76 sf->SetProperty("ABSTRACT","0");
77 if(!sourceListValue.empty())
79 sourceListValue += ";";
81 sourceListValue += fullname;
86 this->Makefile->AddDefinition(args[1].c_str(), sourceListValue.c_str());