OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
version-config.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: David Burken
6 //
7 // Description:
8 // Application to generate ossim/include/ossim/ossimVersion.h file.
9 // This should be ran after generation of ossim/include/ossim/ossimConfig.h
10 // file but before anything else.
11 //
12 // Returns 0 on success, 1 on error. Currently does not set error msg.
13 //
14 // $Id$
15 //----------------------------------------------------------------------------
16 
17 #include <ctime>
18 #include <fstream>
19 #include <string>
20 #include <iostream>
21 
30 int main(int argc, char* argv[])
31 {
32  enum
33  {
34  OK=0,
35  ERROR=1
36  };
37 
38  if (argc != 3)
39  {
40  return ERROR;
41  }
42 
43  std::ofstream os(argv[1]);
44  if (!os)
45  {
46  return ERROR;
47  }
48 
49  // Get the version. This is now passed in from the make file.
50  std::string versionString = "Version ";
51  versionString += argv[2];
52  std::string versionNumber = argv[2];
53  std::string majorVersion;
54  std::string minorVersion = "0";
55  std::string releaseVersion = "0";
56  std::string::size_type pos1 = std::string::npos;
57  std::string::size_type pos2 = std::string::npos;
58 
59  pos1 = versionNumber.find(".", 0);
60  if(pos1 != std::string::npos)
61  {
62  majorVersion = std::string(versionNumber.begin(),
63  versionNumber.begin()+pos1);
64  pos2 = versionNumber.find(".", pos1+1);
65  if(pos2 != std::string::npos)
66  {
67  minorVersion = std::string(versionNumber.begin()+pos1+1,
68  versionNumber.begin()+pos2);
69  releaseVersion = std::string(versionNumber.begin()+pos2+1,
70  versionNumber.end());
71  }
72  }
73  else
74  {
75  majorVersion = versionNumber;
76  }
77  // Get the build date in the format of (yyyymmdd).
78  char s[11];
79  s[10] = '\0';
80  time_t t;
81  time(&t);
82  tm* lt = localtime(&t);
83  strftime(s, 11, "(%Y%m%d)", lt);
84  std::string date = s;
85 
86  // Write the header file.
87  os << "// Auto generated by version-config - DO NOT EDIT\n"
88  << "#ifndef ossimVersion_HEADER\n"
89  << "#define ossimVersion_HEADER\n"
90  << "\n"
91  << "#include <ossim/ossimConfig.h>\n"
92  << "\n"
93  << "#ifndef OSSIM_VERSION\n"
94  << "# define OSSIM_VERSION " << "\"" << versionString << "\"\n"
95  << "# define OSSIM_VERSION_NUMBER " << "\"" << versionNumber << "\"\n"
96  << "# define OSSIM_MAJOR_VERSION_NUMBER " << majorVersion << "\n"
97  << "# define OSSIM_MINOR_VERSION_NUMBER " << minorVersion << "\n"
98  << "# define OSSIM_RELEASE_NUMBER " << releaseVersion << "\n"
99  << "#endif\n"
100  << "\n"
101  << "// date format = (yyyymmdd)\n"
102  << "#ifndef OSSIM_BUILD_DATE\n"
103  << "# define OSSIM_BUILD_DATE " << "\"" << date << "\"\n"
104  << "#endif\n"
105  << "\n"
106  << "#endif /* End of #ifndef ossimVersion_HEADER */"
107  << std::endl;
108 
109  os.close();
110 
111  std::cout << "wrote file: " << argv[1] << std::endl;
112 
113  return OK;
114 }
int main(int argc, char *argv[])
main application for getting version / date and generating the ossimVersion.h file.
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47