openETCS
case study for the European Train Control System developed for the authors dissertation
BuildGenerator.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010-2012
3  Johannes Feuser <feuser@uni-bremen.de>
4  This file is part of the openETCS library.
5 
6  The openETCS library is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  any later version.
10 
11  The openETCS library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with the openETCS library. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 
21 
22 #include "BuildGenerator.h"
23 #include "../../DSM/SyntaxTree.h"
24 
25 
26 
27 
28 namespace oETCS {
29 
30 namespace GEN {
31 
32 
33 void CBuildGenerator::Generate(::DSM::CSyntaxTree * const pSyntaxTree, ::std::ostream & OutStream) throw(::oETCS::GEN::Error::CException)
34 {
35  // Bouml preserved body begin 00097302
36  ::std::time_t Now = ::std::chrono::system_clock::to_time_t(::std::chrono::system_clock::now());
37  ::std::string SourceFile;
38  ::GOPPRR::CGraph* pRootGraph(0);
39  ::DSM::CGOPPRRSyntaxTree* pGOPPRR(0);
40 
41 
42 
43  // convert plain syntax tree into GOPPRR
44  pGOPPRR = dynamic_cast< ::DSM::CGOPPRRSyntaxTree* >(pSyntaxTree);
45 
46  // check, if tree could be converted
47  if (pGOPPRR == 0)
48  {
49  // throw exception
50  throw (::oETCS::GEN::Error::CParameter("unknown syntax tree format not supported"));
51 
52  } // if (pGOPPRR == 0)
53 
54  // get root graph from syntax tree
55  pRootGraph = pGOPPRR->GetRootGraph();
56 
57  // set file name from root graph ID
58  SourceFile = pRootGraph->m_ID;
59  SourceFile += ".cpp";
60 
61  // remove all white spaces from prefix
62  while (SourceFile.find(" ") != std::string::npos)
63  {
64  // replace current white space with _
65  SourceFile.replace(SourceFile.find(" "), 1, "_");
66 
67  } // while (SourceFile.find(" ") != std::string::npos)
68 
69 
70  // generate build configuration
71  OutStream <<
72  "# Copyright (C) 2010-2012\n"
73  "# Johannes Feuser <feuser@uni-bremen.de>\n"
74  "# This file is part of the openETCS project\n"
75  "#\n"
76  "# The openETCS library is free software: you can redistribute it and/or modify\n"
77  "# it under the terms of the GNU General Public License as published by\n"
78  "# the Free Software Foundation, either version 3 of the License, or\n"
79  "# any later version.\n"
80  "#\n"
81  "# The openETCS library is distributed in the hope that it will be useful,\n"
82  "# but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
83  "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
84  "# GNU General Public License for more details.\n"
85  "#\n"
86  "# You should have received a copy of the GNU General Public License\n"
87  "# along with the openETCS library. If not, see <http://www.gnu.org/licenses/>.\n"
88  "#\n"
89  "# cmake file for the EVC binary\n"
90  "# generated for openETCS EVC by build configuration generator\n"
91  "# time point (UTC) of generation: " << ::std::asctime(::std::gmtime(&Now)) << "\n"
92  "\n"
93  ""
94  "# set project settings\n"
95  "cmake_minimum_required(VERSION 2.8)\n"
96  "project(openETCS-EVC)\n"
97  "\n"
98  "# append flags for compiling\n"
99  "set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -O3 -Wall -pthread -std=c++0x\")\n"
100  "set(CMAKE_CXX_FLAGS_DEBUG \"${CMAKE_CXX_FLAGS_DEBUG} -O0 -Wall -pthread -std=c++0x -D__DEBUG_OUTPUT__\")\n"
101  "set(CMAKE_CXX_FLAGS_MINSIZEREL \"${CMAKE_CXX_FLAGS_MINSIZEREL} -0s -Wall -pthread -std=c++0x\")\n"
102  "set(CMAKE_CXX_FLAGS_RELEASE \"${CMAKE_CXX_FLAGS_RELEASE} -O3 -Wall -pthread -std=c++0x\")\n"
103  "\n"
104  "# release ist default type if not set\n"
105  "if(NOT CMAKE_BUILD_TYPE)\n"
106  "set(CMAKE_BUILD_TYPE Release)\n"
107  "endif(NOT CMAKE_BUILD_TYPE)\n"
108  "\n"
109  "# verbose makefile is disabled if not explicitly set\n"
110  "if(NOT CMAKE_VERBOSE_MAKEFILE)\n"
111  "set(CMAKE_VERBOSE_MAKEFILE OFF)\n"
112  "endif(NOT CMAKE_VERBOSE_MAKEFILE)\n"
113  "\n"
114  "# add Qt4 package\n"
115  "find_package(Qt4 COMPONENTS QtCore QtGui QtDBus QtGui REQUIRED)\n"
116  "include(${QT_USE_FILE})\n"
117  "\n"
118  "# init compile flag\n"
119  "set(COMPILE_OKAY \"TRUE\")\n"
120  "\n"
121  "\n"
122  "# try to find path to domain framework headers\n"
123  "find_path(OPEN_ETCS_DF_DIR oETCS/DF/EVCStateMachine.h PATHS ../src/ ../src/oETCS ../src/oETCS/DF /usr/inlude /usr/include/oETCS)\n"
124  "\n"
125  "# check if path was found\n"
126  "if (OPEN_ETCS_DF_DIR STREQUAL \"OPEN_ETCS_DF_DIR-NOTFOUND\")\n"
127  "\n"
128  "# print warning\n"
129  "message(SEND_ERROR \"openETCS domain framework header not found!\")\n"
130  "\n"
131  "# set compile flag to false\n"
132  "set(COMPILE_OKAY \"FALSE\")\n"
133  "\n"
134  "else (OPEN_ETCS_DF_DIR STREQUAL \"OPEN_ETCS_DF_DIR-NOTFOUND\")\n"
135  "\n"
136  "# print found message\n"
137  "message (STATUS \"Found openETCS domain framework include directory: ${OPEN_ETCS_DF_DIR}\")\n"
138  "\n"
139  "endif (OPEN_ETCS_DF_DIR STREQUAL \"OPEN_ETCS_DF_DIR-NOTFOUND\")\n"
140  "\n"
141  "\n"
142  "\n"
143  "# try to find path to domain framework libraries\n"
144  "find_library(OPEN_ETCS_DF_LIB openETCSPIM PATHS ../release/src ../debug/src ../src ../lib /usr/lib HINTS ${OPEN_ETCS_DF_DIR}/../release/src ${OPEN_ETCS_DF_DIR}/../debug/src ../src ${OPEN_ETCS_DF_DIR})\n"
145  "\n"
146  "# check if library was found\n"
147  "if (OPEN_ETCS_DF_LIB STREQUAL \"OPEN_ETCS_DF_LIB-NOTFOUND\")\n"
148  "\n"
149  "# print warning\n"
150  "message(SEND_ERROR \"openETCS domain framework shared library not found!\")\n"
151  "\n"
152  "# set compile flag to false\n"
153  "set(COMPILE_OKAY \"FALSE\")\n"
154  "\n"
155  "else (OPEN_ETCS_DF_LIB STREQUAL \"OPEN_ETCS_DF_LIB-NOTFOUND\")\n"
156  "\n"
157  "# print found message\n"
158  "message (STATUS \"Found openETCS domain framework shared library: ${OPEN_ETCS_DF_LIB}\")\n"
159  "\n"
160  "# get path of domain framework library\n"
161  "get_filename_component(OPEN_ETCS_DF_LIB_DIR ${OPEN_ETCS_DF_LIB} PATH)\n"
162  "\n"
163  "endif (OPEN_ETCS_DF_LIB STREQUAL \"OPEN_ETCS_DF_LIB-NOTFOUND\")\n"
164  "\n"
165  "\n"
166  "# check if all preconditions were met\n"
167  "if (COMPILE_OKAY STREQUAL \"TRUE\")\n"
168  "\n"
169  "# add domain framework directories to include\n"
170  "include_directories(${OPEN_ETCS_DF_DIR} ${OPEN_ETCS_DF_LIB_DIR})\n"
171  "\n"
172  "# add EVC binary as target\n"
173  "add_executable(EVC \"" << SourceFile << "\")\n"
174  "target_link_libraries(EVC ${OPEN_ETCS_DF_LIB} ${QT_LIBRARIES})\n"
175  "\n"
176  "endif (COMPILE_OKAY STREQUAL \"TRUE\")\n"
177  "\n"
178  "\n"
179  "# add custom target to remove all generated files\n"
180  "set(GENERATED_FILES CMakeFiles/ CMakeCache.txt Makefile cmake_install.cmake)\n"
181  "add_custom_target(distribclean COMMAND cmake -E remove -f ${GENERATED_FILES})";
182 
183  // Bouml preserved body end 00097302
184 
185 } // void CBuildGenerator::Generate() throw(::oETCS::GEN::Error::CException)
186 
187 
188 
189 
190 
191 
192 } // namespace oETCS::GEN
193 
194 } // namespace oETCS

Copyright (C) 2010-2012 Johannes Feuser (feuser@uni-bremen.de)
The openETCS library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
The openETCS library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with the openETCS library. If not, see "http://www.gnu.org/licenses/.