OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Functions
version-config.cpp File Reference
#include <ctime>
#include <fstream>
#include <string>
#include <iostream>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 main application for getting version / date and generating the ossimVersion.h file. More...
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

main application for getting version / date and generating the ossimVersion.h file.

Parameters
argv[1]Path to ossim/include/ossim/ossimVersion.h
argv[2]Version number string like "1.7.11"

Definition at line 30 of file version-config.cpp.

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 }
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47