All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PluginCMakeWriter.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/widgets/plugin/builder/PluginCMakeWriter.cpp
22 
23  \brief This class is used to create the cmake file for the new plugin builded.
24 */
25 
26 #include "PluginCMakeWriter.h"
27 #include "../../../../common/Version.h"
28 
29 // STL Includes
30 #include <cstdlib>
31 #include <iostream>
32 #include <ctime>
33 
34 #define CMAKE_FILE_NAME "CMakeLists.txt"
35 #define PLUGIN_INFO_XML_FILE_NAME "plugin_info.xml.in"
36 
38 {
39 }
40 
42 {
43 }
44 
45 void te::qt::widgets::PluginCMakeWriter::createCmakeFile(const std::string& buildPath, const std::string& sourcePath, const std::string& projName,
46  const std::string exportMacro, const std::string& cmakePath, const te::plugin::PluginInfo& pi)
47 {
48  std::ofstream file;
49 
50  std::string fileName = buildPath;
51  fileName += "/";
52  fileName += CMAKE_FILE_NAME;
53 
54  file.open(fileName.c_str());
55 
56  //insert default header
57  insertDefaultHeader(file);
58 
59  //cmake version required
60  file << "cmake_minimum_required(VERSION 2.8)\n";
61 
62  //source build tree location
63  file << "\n";
64  file << "# Controls for the source and build tree locations\n";
65  file << "set(SRCDIR " + sourcePath + ")\n";
66  file << "set(INCLDIR ${SRCDIR}) \n";
67 
68  //project name
69  file << "\n";
70  file << "# Set the project name\n";
71  file << "set(PROJ_NAME \"" + projName + "\")\n";
72  file << "project(${PROJ_NAME})\n";
73  file << "set(LIB_NAME ${PROJ_NAME})\n";
74 
75  //find packages
76  file << "\n";
77  file << "# If this plugin has dependencies with any package\n";
78  file << "# you should set it here\n";
79 
80  findTerralib(file, cmakePath, pi);
81 
82  findBoost(file);
83 
84  //UI Files
85  file << "\n";
86  file << "# If this plugin has UI files\n";
87  file << "# you should set it here\n";
88  file << "# qt4_wrap_ui...\n\n";
89 
90  //add header and sources
91  file << "\n";
92  file << "# Add files\n";
93  file << "file(GLOB SRCS ${SRCDIR}/*.cpp)\n";
94  file << "file(GLOB HDRS ${INCLDIR}/*.h)\n";
95 
96  //win32 definitions
97  file << "\n";
98  file << "# WIN32 Definitions\n";
99  file << "if(WIN32)\n";
100  file << " add_definitions(-D_CRT_SECURE_NO_WARNINGS)\n";
101  file << "endif(WIN32)\n";
102 
103  //general definitions
104  file << "\n";
105  file << "# General Definitions\n";
106  file << "add_definitions(-D" + exportMacro + ")\n";
107 
108  //adding extra files
109  file << "\n";
110  file << "# Append extra files (used in case project has UI forms)\n";
111  file << "#source_group(\"Form Files\" FILES ${FORMS})\n";
112  file << "#source_group(\"Generated Files\" FILES ${MOC} ${UI})\n";
113 
114  //set configure file
115  file << "\n";
116  file << "# Configure file\n";
117  file << "configure_file(\"${CMAKE_CURRENT_SOURCE_DIR}/plugin_info.xml.in\" ";
118  file << "\"${CMAKE_CURRENT_BINARY_DIR}/" + projName + ".xml\")\n";
119 
120  //lib properties
121  file << "\n";
122  file << "# Lib properties\n";
123  file << "include_directories( ${DEP_INCLUDES} )\n";
124  file << "add_library (${PROJ_NAME} SHARED ${HDRS} ${SRCS}) # ${UI} ${MOC}\n";
125  file << "set_target_properties(${PROJ_NAME} PROPERTIES DEBUG_POSTFIX _d)\n";
126  file << "target_link_libraries(${PROJ_NAME} ${DEP_LIBS})\n";
127 
128  file.close();
129 }
130 
132 {
133  std::ofstream file;
134 
135  std::string fileName = buildPath;
136  fileName += "/";
137  fileName += PLUGIN_INFO_XML_FILE_NAME;
138 
139  file.open(fileName.c_str());
140 
141  //insert default header
142  //insertDefaultXMLHeader(file);
143 
144  //insert plugin info
145  file << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n";
146  file << "<PluginInfo xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n";
147  file << " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
148  file << " xmlns=\"http://www.terralib.org/schemas/plugin\"\n";
149  file << " xsd:schemaLocation=\"http://www.terralib.org/schemas/plugin ${TERRALIB_SCHEMA_LOCATION}/plugin/plugin_info.xsd\"\n";
150  file << " version=\"" + pi.m_version + "\"\n";
151  file << " release=\"" + pi.m_release + "\"\n";
152  file << " engine=\"" + pi.m_engine + "\">\n";
153  file << " <Name>" + pi.m_name + "</Name>\n";
154  file << " <DisplayName>" + pi.m_displayName + "</DisplayName>\n";
155  file << " <Description>" + pi.m_description + "</Description>\n";
156  file << " <TerraLibVersion>" + pi.m_terralibVersion + "</TerraLibVersion>\n";
157  file << " <License xlink:href=\"" + pi.m_licenseURL + "\">" + pi.m_licenseDescription + "</License>\n";
158  file << " <Category>" + pi.m_category + "</Category>\n";
159  file << " <Site xlink:href=\"" + pi.m_site + "\"/>\n";
160  file << " <Provider>\n";
161  file << " <Name>" + p.m_name + "</Name>\n";
162  file << " <Site xlink:href=\"" + p.m_site + "\"/>\n";
163  file << " <Email>" + p.m_email + "</Email>\n";
164  file << " </Provider>\n";
165 
166  if(pi.m_requiredPlugins.empty() == false)
167  {
168  file << " <RequiredPlugins>\n";
169  for(size_t t = 0; t < pi.m_requiredPlugins.size(); ++t)
170  {
171  file << " <PluginId>" + pi.m_requiredPlugins[t] + "</PluginId>\n";
172  }
173  file << " </RequiredPlugins>\n";
174  }
175 
176  if(pi.m_requiredModules.empty() == false)
177  {
178  file << " <RequiredModules>\n";
179  for(size_t t = 0; t < pi.m_requiredModules.size(); ++t)
180  {
181  file << " <ModuleId>" + pi.m_requiredModules[t] + "</ModuleId>\n";
182  }
183  file << " </RequiredModules>\n";
184  }
185 
186 
187  if(pi.m_resources.empty() == false)
188  {
189  file << " <Resources>\n";
190  for(size_t t = 0; t < pi.m_resources.size(); ++t)
191  {
192  file << " <Resource name=\"" + pi.m_resources[t].first + "\" xlink:href=\"" + pi.m_resources[t].second + "\"/>\n";
193  }
194  file << " </Resources>\n";
195  }
196 
197 
198  if(pi.m_parameters.empty() == false)
199  {
200  file << " <Parameters>\n";
201  for(size_t t = 0; t < pi.m_parameters.size(); ++t)
202  {
203  file << " <Parameter>\n";
204  file << " <Name>" + pi.m_parameters[t].first + "</Name>\n";
205  file << " <Value>" + pi.m_parameters[t].second + "</Value>\n";
206  file << " </Parameter>\n";
207  }
208  file << " </Parameters>\n";
209  }
210 
211 
212  file << "</PluginInfo>\n";
213 
214  file.close();
215 }
216 
218 {
219  time_t now = time(0);
220  char* dt = ctime(&now);
221  std::string currentTime = dt;
222  std::string fileName = CMAKE_FILE_NAME;
223  std::string teVersion = te::common::Version::asString();
224 
225  std::string defaultHeader = "";
226 
227  defaultHeader += "#######################################################################\n";
228  defaultHeader += "## This file was automatically generated by TerraView - Plugin Builder\n";
229  defaultHeader += "## TerraLib Version: " + teVersion + " \n";
230  defaultHeader += "## File: " + fileName + "\n";
231  defaultHeader += "## Date: " + currentTime;
232  defaultHeader += "#######################################################################\n";
233 
234  stream << defaultHeader.c_str();
235  stream << "\n";
236 }
237 
239 {
240  time_t now = time(0);
241  char* dt = ctime(&now);
242  std::string currentTime = dt;
243  std::string fileName = CMAKE_FILE_NAME;
244  std::string teVersion = te::common::Version::asString();
245 
246  std::string defaultHeader = "";
247 
248  defaultHeader += "<!--###################################################################\n";
249  defaultHeader += "## This file was automatically generated by TerraView - Plugin Builder\n";
250  defaultHeader += "## TerraLib Version: " + teVersion + "\n";
251  defaultHeader += "## File: " + fileName + "\n";
252  defaultHeader += "## Date: " + currentTime;
253  defaultHeader += "####################################################################-->\n";
254 
255  stream << defaultHeader.c_str();
256 }
257 
258 void te::qt::widgets::PluginCMakeWriter::findTerralib(std::ofstream& stream, const std::string& teCmakePath, const te::plugin::PluginInfo& pi)
259 {
260  std::string componentList = "";
261 
262  for(size_t t = 0; t < pi.m_requiredModules.size(); ++t)
263  {
264  int pos = pi.m_requiredModules[t].rfind(".");
265 
266  std::string componentName = pi.m_requiredModules[t].substr(pos + 1, pi.m_requiredModules[t].size() - 1);
267  componentList += componentName + " ";
268  }
269 
270  stream << "list (APPEND CMAKE_PREFIX_PATH \"" + teCmakePath + "\")\n";
271  stream << "list (APPEND CMAKE_FIND_ROOT_PATH \"" + teCmakePath + "\")\n";
272 
273  stream << "find_package(terralib 5 REQUIRED COMPONENTS " + componentList + ")\n";
274  stream << "if(terralib_FOUND)\n";
275  stream << " list (APPEND DEP_INCLUDES ${TE_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})\n";
276  stream << " list (APPEND DEP_LIBS ${TE_LIBRARIES})\n";
277  stream << "endif()\n";
278 }
279 
281 {
282  stream << "find_package(Boost ${_Boost_VERSION} REQUIRED COMPONENTS system filesystem)\n";
283  stream << "if(Boost_FOUND)\n";
284  stream << " list (APPEND DEP_INCLUDES ${Boost_INCLUDE_DIRS})\n";
285  stream << "endif()\n";
286 }
#define CMAKE_FILE_NAME
std::string m_name
The plugin name: an internal value used to identify the plugin in the system. Must be a unique value...
Definition: PluginInfo.h:66
std::vector< std::string > m_requiredPlugins
The list of required plugins in order to lunch the plugin.
Definition: PluginInfo.h:78
std::vector< std::string > m_requiredModules
The list of required category of plugins in order to lunch the plugin.
Definition: PluginInfo.h:80
std::string m_site
The provider home page.
Definition: Provider.h:48
void findTerralib(std::ofstream &stream, const std::string &teCmakePath, const te::plugin::PluginInfo &pi)
This struct can be used to describe a given plugin provider.
Definition: Provider.h:45
std::string m_licenseDescription
A brief description about the plugin license.
Definition: PluginInfo.h:73
std::string m_displayName
The plugin name to be displayed in a graphical interface.
Definition: PluginInfo.h:67
static std::string asString()
Definition: Version.cpp:60
std::string m_terralibVersion
The TerraLib version this plugin depends on.
Definition: PluginInfo.h:72
void insertDefaultHeader(std::ofstream &stream)
void insertDefaultXMLHeader(std::ofstream &stream)
This class is used to create the cmake file for the new plugin builded.
std::string m_engine
The type of plugin execution engine: C++, JAVA.
Definition: PluginInfo.h:71
std::string m_version
The plugin version.
Definition: PluginInfo.h:69
std::string m_site
An URL pointing to the plugin site.
Definition: PluginInfo.h:76
#define PLUGIN_INFO_XML_FILE_NAME
std::string m_email
The provider contact e-mail.
Definition: Provider.h:49
std::string m_release
The release date of the plugin. This may be used to identify new versions of a given plugin...
Definition: PluginInfo.h:70
void createPluginInfoFile(const std::string &buildPath, const te::plugin::PluginInfo &pi, const te::plugin::Provider &p)
std::vector< Resource > m_resources
The list of resources used by plugin.
Definition: PluginInfo.h:81
std::vector< Parameter > m_parameters
Any configuration parameter that can be informed to plugin (map: parameter-name -> parameter-value)...
Definition: PluginInfo.h:82
std::string m_description
A brief explanation about the plugin.
Definition: PluginInfo.h:68
std::string m_name
Provider name: may be a person or a company.
Definition: Provider.h:47
The basic information about a plugin.
Definition: PluginInfo.h:61
void createCmakeFile(const std::string &buildPath, const std::string &sourcePath, const std::string &projName, const std::string exportMacro, const std::string &cmakePath, const te::plugin::PluginInfo &pi)
std::string m_category
The plugin category.
Definition: PluginInfo.h:75
void findBoost(std::ofstream &stream)
std::string m_licenseURL
An URL where someone can find more information on the license.
Definition: PluginInfo.h:74