1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmSourceFile.cxx,v $
6 Date: $Date: 2002-06-19 17:28:39 $
7 Version: $Revision: 1.15 $
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 "cmSourceFile.h"
18 #include "cmStandardIncludes.h"
19 #include "cmSystemTools.h"
23 // Set the name of the class and the full path to the file.
24 // The class must be found in dir and end in name.cxx, name.txx,
25 // name.c or it will be considered a header file only class
26 // and not included in the build process
27 void cmSourceFile::SetName(const char* name
, const char* dir
,
28 const std::vector
<std::string
>& sourceExts
,
29 const std::vector
<std::string
>& headerExts
)
31 m_HeaderFileOnly
= true;
34 std::string pathname
= dir
;
36 // the name might include the full path already, so
37 // check for this case
38 if (name
&& (name
[0] == '/' ||
39 (name
[0] != '\0' && name
[1] == ':')))
49 // First try and see whether the listed file can be found
50 // as is without extensions added on.
51 pathname
+= m_SourceName
;
52 std::string hname
= pathname
;
53 if(cmSystemTools::FileExists(hname
.c_str()))
55 std::string::size_type pos
= hname
.rfind('.');
56 if(pos
!= std::string::npos
)
58 m_SourceExtension
= hname
.substr(pos
+1, hname
.size()-pos
);
59 std::string::size_type pos2
= hname
.rfind('/');
60 if(pos2
!= std::string::npos
)
62 m_SourceName
= hname
.substr(pos2
+1, pos
- pos2
-1);
66 m_SourceName
= hname
.substr(0, pos
);
70 // See if the file is a header file
71 if(std::find( headerExts
.begin(), headerExts
.end(), m_SourceExtension
) == headerExts
.end())
72 m_HeaderFileOnly
= false;
74 m_HeaderFileOnly
= true;
79 // Next, try the various source extensions
80 for( std::vector
<std::string
>::const_iterator ext
= sourceExts
.begin();
81 ext
!= sourceExts
.end(); ++ext
)
86 if(cmSystemTools::FileExists(hname
.c_str()))
88 m_SourceExtension
= *ext
;
89 m_HeaderFileOnly
= false;
95 // Finally, try the various header extensions
96 for( std::vector
<std::string
>::const_iterator ext
= headerExts
.begin();
97 ext
!= headerExts
.end(); ++ext
)
102 if(cmSystemTools::FileExists(hname
.c_str()))
104 m_SourceExtension
= *ext
;
110 std::string errorMsg
= "\n\nTried";
111 for( std::vector
<std::string
>::const_iterator ext
= sourceExts
.begin();
112 ext
!= sourceExts
.end(); ++ext
)
117 for( std::vector
<std::string
>::const_iterator ext
= headerExts
.begin();
118 ext
!= headerExts
.end(); ++ext
)
123 cmSystemTools::Error("can not find file ", pathname
.c_str(),
128 void cmSourceFile::SetName(const char* name
, const char* dir
, const char *ext
,
131 m_HeaderFileOnly
= hfo
;
133 std::string pathname
= dir
;
139 pathname
+= m_SourceName
;
140 if(ext
&& strlen(ext
))
145 m_FullPath
= pathname
;
146 m_SourceExtension
= ext
;
150 void cmSourceFile::Print() const
154 std::cerr
<< "Abstract ";
158 std::cerr
<< "Concrete ";
162 std::cerr
<< "Header file ";
166 std::cerr
<< "CXX file ";
168 std::cerr
<< "m_CompileFlags: " << m_CompileFlags
<< "\n";
169 std::cerr
<< "m_FullPath: " << m_FullPath
<< "\n";
170 std::cerr
<< "m_SourceName: " << m_SourceName
<< std::endl
;
171 std::cerr
<< "m_SourceExtension: " << m_SourceExtension
<< "\n";