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 
40 
41 void te::qt::widgets::PluginCMakeWriter::createCmakeFile(const std::string& buildPath, const std::string& sourcePath, const std::string& projName,
42  const std::string exportMacro, const std::string& cmakePath, const te::core::PluginInfo& pi)
43 {
44  std::ofstream file;
45 
46  std::string fileName = buildPath;
47  fileName += "/";
48  fileName += CMAKE_FILE_NAME;
49 
50  file.open(fileName.c_str());
51 
52  //insert default header
53  insertDefaultHeader(file);
54 
55  //cmake version required
56  file << "cmake_minimum_required(VERSION 2.8)\n";
57 
58  //source build tree location
59  file << "\n";
60  file << "# Controls for the source and build tree locations\n";
61  file << "set(SRCDIR " + sourcePath + ")\n";
62  file << "set(INCLDIR ${SRCDIR}) \n";
63 
64  //project name
65  file << "\n";
66  file << "# Set the project name\n";
67  file << "set(PROJ_NAME \"" + projName + "\")\n";
68  file << "project(${PROJ_NAME})\n";
69  file << "set(LIB_NAME ${PROJ_NAME})\n";
70 
71  //find packages
72  file << "\n";
73  file << "# If this plugin has dependencies with any package\n";
74  file << "# you should set it here\n";
75 
76  findTerralib(file, cmakePath, pi);
77 
78  findBoost(file);
79 
80  //UI Files
81  file << "\n";
82  file << "# If this plugin has UI files\n";
83  file << "# you should set it here\n";
84  file << "# qt4_wrap_ui...\n\n";
85 
86  //add header and sources
87  file << "\n";
88  file << "# Add files\n";
89  file << "file(GLOB SRCS ${SRCDIR}/*.cpp)\n";
90  file << "file(GLOB HDRS ${INCLDIR}/*.h)\n";
91 
92  //win32 definitions
93  file << "\n";
94  file << "# WIN32 Definitions\n";
95  file << "if(WIN32)\n";
96  file << " add_definitions(-D_CRT_SECURE_NO_WARNINGS)\n";
97  file << "endif(WIN32)\n";
98 
99  //general definitions
100  file << "\n";
101  file << "# General Definitions\n";
102  file << "add_definitions(-D" + exportMacro + ")\n";
103 
104  //adding extra files
105  file << "\n";
106  file << "# Append extra files (used in case project has UI forms)\n";
107  file << "#source_group(\"Form Files\" FILES ${FORMS})\n";
108  file << "#source_group(\"Generated Files\" FILES ${MOC} ${UI})\n";
109 
110  //set configure file
111  file << "\n";
112  file << "# Configure file\n";
113  file << "configure_file(\"${CMAKE_CURRENT_SOURCE_DIR}/plugin_info.xml.in\" ";
114  file << "\"${CMAKE_CURRENT_BINARY_DIR}/" + projName + ".xml\")\n";
115 
116  //lib properties
117  file << "\n";
118  file << "# Lib properties\n";
119  file << "include_directories( ${DEP_INCLUDES} )\n";
120  file << "add_library (${PROJ_NAME} SHARED ${HDRS} ${SRCS}) # ${UI} ${MOC}\n";
121  file << "set_target_properties(${PROJ_NAME} PROPERTIES DEBUG_POSTFIX _d)\n";
122  file << "target_link_libraries(${PROJ_NAME} ${DEP_LIBS})\n";
123 
124  file.close();
125 }
126 
128  const std::string& /*buildPath*/, const te::core::PluginInfo& /*pi*/)
129 {
130 // std::ofstream file;
131 
132 // std::string fileName = buildPath;
133 // fileName += "/";
134 // fileName += PLUGIN_INFO_XML_FILE_NAME;
135 
136 // file.open(fileName.c_str());
137 
138  //insert default header
139  //insertDefaultXMLHeader(file);
140 
141  //insert plugin info
142 // file << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n";
143 // file << "<PluginInfo xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n";
144 // file << " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
145 // file << " xmlns=\"http://www.terralib.org/schemas/plugin\"\n";
146 // file << " xsd:schemaLocation=\"http://www.terralib.org/schemas/plugin ${TERRALIB_SCHEMA_LOCATION}/plugin/plugin_info.xsd\"\n";
147 // file << " version=\"" + pi.m_version + "\"\n";
148 // file << " release=\"" + pi.m_release + "\"\n";
149 // file << " engine=\"" + pi.m_engine + "\">\n";
150 // file << " <Name>" + pi.m_name + "</Name>\n";
151 // file << " <DisplayName>" + pi.m_displayName + "</DisplayName>\n";
152 // file << " <Description>" + pi.m_description + "</Description>\n";
153 // file << " <TerraLibVersion>" + pi.m_terralibVersion + "</TerraLibVersion>\n";
154 // file << " <License xlink:href=\"" + pi.m_licenseURL + "\">" + pi.m_licenseDescription + "</License>\n";
155 // file << " <Category>" + pi.m_category + "</Category>\n";
156 // file << " <Site xlink:href=\"" + pi.m_site + "\"/>\n";
157 // file << " <Provider>\n";
158 // file << " <Name>" + pi.provider.name + "</Name>\n";
159 // file << " <Site xlink:href=\"" + pi.provider.site + "\"/>\n";
160 // file << " <Email>" + p.m_email + "</Email>\n";
161 // file << " </Provider>\n";
162 
163 // if(pi.m_requiredPlugins.empty() == false)
164 // {
165 // file << " <RequiredPlugins>\n";
166 // for(size_t t = 0; t < pi.m_requiredPlugins.size(); ++t)
167 // {
168 // file << " <PluginId>" + pi.m_requiredPlugins[t] + "</PluginId>\n";
169 // }
170 // file << " </RequiredPlugins>\n";
171 // }
172 
173 // if(pi.m_requiredModules.empty() == false)
174 // {
175 // file << " <RequiredModules>\n";
176 // for(size_t t = 0; t < pi.m_requiredModules.size(); ++t)
177 // {
178 // file << " <ModuleId>" + pi.m_requiredModules[t] + "</ModuleId>\n";
179 // }
180 // file << " </RequiredModules>\n";
181 // }
182 
183 
184 // if(pi.m_resources.empty() == false)
185 // {
186 // file << " <Resources>\n";
187 // for(size_t t = 0; t < pi.m_resources.size(); ++t)
188 // {
189 // file << " <Resource name=\"" + pi.m_resources[t].first + "\" xlink:href=\"" + pi.m_resources[t].second + "\"/>\n";
190 // }
191 // file << " </Resources>\n";
192 // }
193 
194 
195 // if(pi.m_parameters.empty() == false)
196 // {
197 // file << " <Parameters>\n";
198 // for(size_t t = 0; t < pi.m_parameters.size(); ++t)
199 // {
200 // file << " <Parameter>\n";
201 // file << " <Name>" + pi.m_parameters[t].first + "</Name>\n";
202 // file << " <Value>" + pi.m_parameters[t].second + "</Value>\n";
203 // file << " </Parameter>\n";
204 // }
205 // file << " </Parameters>\n";
206 // }
207 
208 
209 // file << "</PluginInfo>\n";
210 
211 // file.close();
212 }
213 
215 {
216  time_t now = time(nullptr);
217  char* dt = ctime(&now);
218  std::string currentTime = dt;
219  std::string fileName = CMAKE_FILE_NAME;
220  std::string teVersion = te::common::Version::asString();
221 
222  std::string defaultHeader;
223 
224  defaultHeader += "#######################################################################\n";
225  defaultHeader += "## This file was automatically generated by TerraView - Plugin Builder\n";
226  defaultHeader += "## TerraLib Version: " + teVersion + " \n";
227  defaultHeader += "## File: " + fileName + "\n";
228  defaultHeader += "## Date: " + currentTime;
229  defaultHeader += "#######################################################################\n";
230 
231  stream << defaultHeader.c_str();
232  stream << "\n";
233 }
234 
236 {
237  time_t now = time(nullptr);
238  char* dt = ctime(&now);
239  std::string currentTime = dt;
240  std::string fileName = CMAKE_FILE_NAME;
241  std::string teVersion = te::common::Version::asString();
242 
243  std::string defaultHeader;
244 
245  defaultHeader += "<!--###################################################################\n";
246  defaultHeader += "## This file was automatically generated by TerraView - Plugin Builder\n";
247  defaultHeader += "## TerraLib Version: " + teVersion + "\n";
248  defaultHeader += "## File: " + fileName + "\n";
249  defaultHeader += "## Date: " + currentTime;
250  defaultHeader += "####################################################################-->\n";
251 
252  stream << defaultHeader.c_str();
253 }
254 
255 void te::qt::widgets::PluginCMakeWriter::findTerralib(std::ofstream& stream, const std::string& teCmakePath, const te::core::PluginInfo& pi)
256 {
257  std::string componentList;
258 
259  for(size_t t = 0; t < pi.linked_libraries.size(); ++t)
260  {
261  size_t pos = pi.linked_libraries[t].rfind(".");
262 
263  std::string componentName = pi.linked_libraries[t].substr(pos + 1, pi.linked_libraries[t].size() - 1);
264  componentList += componentName + " ";
265  }
266 
267  stream << "list (APPEND CMAKE_PREFIX_PATH \"" + teCmakePath + "\")\n";
268  stream << "list (APPEND CMAKE_FIND_ROOT_PATH \"" + teCmakePath + "\")\n";
269 
270  stream << "find_package(terralib 5 REQUIRED COMPONENTS " + componentList + ")\n";
271  stream << "if(terralib_FOUND)\n";
272  stream << " list (APPEND DEP_INCLUDES ${TE_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})\n";
273  stream << " list (APPEND DEP_LIBS ${TE_LIBRARIES})\n";
274  stream << "endif()\n";
275 }
276 
278 {
279  stream << "find_package(Boost ${_Boost_VERSION} REQUIRED COMPONENTS system filesystem)\n";
280  stream << "if(Boost_FOUND)\n";
281  stream << " list (APPEND DEP_INCLUDES ${Boost_INCLUDE_DIRS})\n";
282  stream << "endif()\n";
283 }
#define CMAKE_FILE_NAME
void createCmakeFile(const std::string &buildPath, const std::string &sourcePath, const std::string &projName, const std::string exportMacro, const std::string &cmakePath, const te::core::PluginInfo &pi)
static std::string asString()
Definition: Version.cpp:60
Basic information about a plugin.
void insertDefaultHeader(std::ofstream &stream)
void insertDefaultXMLHeader(std::ofstream &stream)
This class is used to create the cmake file for the new plugin builded.
static te::dt::TimeDuration dt(20, 30, 50, 11)
std::vector< std::string > linked_libraries
The list of linked libraries.
void createPluginInfoFile(const std::string &buildPath, const te::core::PluginInfo &pi)
void findTerralib(std::ofstream &stream, const std::string &teCmakePath, const te::core::PluginInfo &pi)
void findBoost(std::ofstream &stream)
file(WRITE ${CMAKE_BINARY_DIR}/config_qhelp.cmake"configure_file (${TERRALIB_ABSOLUTE_ROOT_DIR}/doc/qhelp/help.qhcp.in ${CMAKE_BINARY_DIR}/share/terraview/help/help.qhcp @ONLY)") add_custom_command(OUTPUT del_dir COMMAND $