FIX: stupid pb fixed (close to being medieval'ed by The Ken)
[cmake.git] / Source / cmSourceFile.cxx
blob822ef4882d1db0dee21b48d2472464bdf77a21f7
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmSourceFile.cxx,v $
5 Language: C++
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;
33 m_SourceName = name;
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] == ':')))
41 pathname = "";
43 if(pathname != "")
45 pathname += "/";
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);
64 else
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;
73 else
74 m_HeaderFileOnly = true;
75 m_FullPath = hname;
76 return;
79 // Next, try the various source extensions
80 for( std::vector<std::string>::const_iterator ext = sourceExts.begin();
81 ext != sourceExts.end(); ++ext )
83 hname = pathname;
84 hname += ".";
85 hname += *ext;
86 if(cmSystemTools::FileExists(hname.c_str()))
88 m_SourceExtension = *ext;
89 m_HeaderFileOnly = false;
90 m_FullPath = hname;
91 return;
95 // Finally, try the various header extensions
96 for( std::vector<std::string>::const_iterator ext = headerExts.begin();
97 ext != headerExts.end(); ++ext )
99 hname = pathname;
100 hname += ".";
101 hname += *ext;
102 if(cmSystemTools::FileExists(hname.c_str()))
104 m_SourceExtension = *ext;
105 m_FullPath = hname;
106 return;
110 std::string errorMsg = "\n\nTried";
111 for( std::vector<std::string>::const_iterator ext = sourceExts.begin();
112 ext != sourceExts.end(); ++ext )
114 errorMsg += " .";
115 errorMsg += *ext;
117 for( std::vector<std::string>::const_iterator ext = headerExts.begin();
118 ext != headerExts.end(); ++ext )
120 errorMsg += " .";
121 errorMsg += *ext;
123 cmSystemTools::Error("can not find file ", pathname.c_str(),
124 errorMsg.c_str());
128 void cmSourceFile::SetName(const char* name, const char* dir, const char *ext,
129 bool hfo)
131 m_HeaderFileOnly = hfo;
132 m_SourceName = name;
133 std::string pathname = dir;
134 if(pathname != "")
136 pathname += "/";
139 pathname += m_SourceName;
140 if(ext && strlen(ext))
142 pathname += ".";
143 pathname += ext;
145 m_FullPath = pathname;
146 m_SourceExtension = ext;
147 return;
150 void cmSourceFile::Print() const
152 if(m_AbstractClass)
154 std::cerr << "Abstract ";
156 else
158 std::cerr << "Concrete ";
160 if(m_HeaderFileOnly)
162 std::cerr << "Header file ";
164 else
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";