1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmAuxSourceDirectoryCommand.cxx,v $
6 Date: $Date: 2002-06-28 13:21:30 $
7 Version: $Revision: 1.13 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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 "cmDirectory.h"
20 // cmAuxSourceDirectoryCommand
21 bool cmAuxSourceDirectoryCommand::InitialPass(std::vector
<std::string
> const& args
)
23 if(args
.size() < 2 || args
.size() > 2)
25 this->SetError("called with incorrect number of arguments");
29 std::string sourceListValue
;
30 std::string templateDirectory
= args
[0];
31 m_Makefile
->AddExtraDirectory(templateDirectory
.c_str());
32 std::string tdir
= m_Makefile
->GetCurrentDirectory();
34 tdir
+= templateDirectory
;
36 // was the list already populated
37 const char *def
= m_Makefile
->GetDefinition(args
[1].c_str());
40 sourceListValue
= def
;
43 // Load all the files in the directory
45 if(dir
.Load(tdir
.c_str()))
47 size_t numfiles
= dir
.GetNumberOfFiles();
48 for(size_t i
=0; i
< numfiles
; ++i
)
50 std::string file
= dir
.GetFile(i
);
51 // Split the filename into base and extension
52 std::string::size_type dotpos
= file
.rfind(".");
53 if( dotpos
!= std::string::npos
)
55 std::string ext
= file
.substr(dotpos
+1);
56 file
= file
.substr(0, dotpos
);
57 // Process only source files
59 && std::find( m_Makefile
->GetSourceExtensions().begin(),
60 m_Makefile
->GetSourceExtensions().end(), ext
)
61 != m_Makefile
->GetSourceExtensions().end() )
63 std::string fullname
= templateDirectory
;
66 // add the file as a class file so
67 // depends can be done
69 cmfile
.SetName(fullname
.c_str(), m_Makefile
->GetCurrentDirectory(),
70 m_Makefile
->GetSourceExtensions(),
71 m_Makefile
->GetHeaderExtensions());
72 cmfile
.SetIsAnAbstractClass(false);
73 m_Makefile
->AddSource(cmfile
);
74 if (sourceListValue
.size() > 0)
76 sourceListValue
+= ";";
78 sourceListValue
+= cmfile
.GetSourceName();
83 m_Makefile
->AddDefinition(args
[1].c_str(), sourceListValue
.c_str());