1 /*!
2  * \file   CMakeGenerator.cxx
3  * \brief
4  * \author Thomas Helfer
5  * \date   11 juil. 2017
6  * \copyright Copyright (C) 2006-2018 CEA/DEN, EDF R&D. All rights
7  * reserved.
8  * This project is publicly released under either the GNU GPL Licence
9  * or the CECILL-A licence. A copy of thoses licences are delivered
10  * with the sources of TFEL. CEA or EDF may also distribute this
11  * project under specific licensing conditions.
12  */
13 
14 #include<boost/python.hpp>
15 #include"MFront/TargetsDescription.hxx"
16 #include"MFront/GeneratorOptions.hxx"
17 #include"MFront/CMakeGenerator.hxx"
18 
19 /*!
20  * \brief a wrapper structure created for the python bindings.
21  */
22 struct CMakeGenerator
23 {
24   /*!
25    * \param[in] t: target description
26    */
27   void exe0(const mfront::TargetsDescription&);
28   /*!
29    * \param[in] t: target description
30    * \param[in] o: generator options
31    */
32   void exe1(const mfront::TargetsDescription&,
33 	    const mfront::GeneratorOptions&);
34   /*!
35    * \param[in] t: target description
36    * \param[in] tn: target to be build
37    */
38   void exe2(const mfront::TargetsDescription&,
39 	    const std::string&);
40   /*!
41    * \param[in] t: target description
42    * \param[in] o: generator options
43    * \param[in] tn: target to be build
44    */
45   void exe3(const mfront::TargetsDescription&,
46 	    const mfront::GeneratorOptions&,
47 	    const std::string&);
48   /*!
49    * \param[in] t: target description
50    */
51   void generate0(const mfront::TargetsDescription&);
52   /*!
53    * \param[in] t: target description
54    * \param[in] o: generator options
55    */
56   void generate1(const mfront::TargetsDescription&,
57 		 const mfront::GeneratorOptions&);
58   //!
59   void callCMake0();
60   /*!
61    * \param[in] tn: target to be build
62    */
63   void callCMake1(const std::string&);
64 }; // end of CMakeGenerator
65 
exe0(const mfront::TargetsDescription & t)66 void CMakeGenerator::exe0(const mfront::TargetsDescription& t)
67 {
68   this->exe3(t,mfront::GeneratorOptions(),"all");
69 }
70 
exe1(const mfront::TargetsDescription & t,const mfront::GeneratorOptions & o)71 void CMakeGenerator::exe1(const mfront::TargetsDescription& t,
72 			     const mfront::GeneratorOptions& o)
73 {
74   this->exe3(t,o,"all");
75 }
76 
exe2(const mfront::TargetsDescription & t,const std::string & tn)77 void CMakeGenerator::exe2(const mfront::TargetsDescription& t,
78 			     const std::string& tn)
79 {
80   this->exe3(t,mfront::GeneratorOptions(),tn);
81 }
82 
exe3(const mfront::TargetsDescription & t,const mfront::GeneratorOptions & o,const std::string & tn)83 void CMakeGenerator::exe3(const mfront::TargetsDescription& t,
84 			     const mfront::GeneratorOptions& o,
85 			     const std::string& tn)
86 {
87   mfront::generateCMakeListsFile(t,o);
88   mfront::callCMake(tn);
89 }
90 
generate0(const mfront::TargetsDescription & t)91 void CMakeGenerator::generate0(const mfront::TargetsDescription& t)
92 {
93   this->generate1(t,mfront::GeneratorOptions());
94 }
95 
generate1(const mfront::TargetsDescription & t,const mfront::GeneratorOptions & o)96 void CMakeGenerator::generate1(const mfront::TargetsDescription& t,
97 			       const mfront::GeneratorOptions& o)
98 {
99   mfront::generateCMakeListsFile(t,o);
100 }
101 
callCMake0()102 void CMakeGenerator::callCMake0()
103 {
104   this->callCMake1("all");
105 }
106 
callCMake1(const std::string & tn)107 void CMakeGenerator::callCMake1(const std::string& tn)
108 {
109   mfront::callCMake(tn);
110 }
111 
112 void declareCMakeGenerator();
113 
declareCMakeGenerator()114 void declareCMakeGenerator()
115 {
116   using namespace boost::python;
117   using namespace mfront;
118 
119   class_<CMakeGenerator>("CMakeGenerator")
120     .def("generate",&CMakeGenerator::generate0,
121 	 "generate the `CMake.mfront` file")
122     .def("generate",&CMakeGenerator::generate1,
123 	 "generate the `CMake.mfront` file "
124 	 "using the provided options")
125     .def("callCMake",&CMakeGenerator::callCMake0,
126 	 "call the `make` utility")
127     .def("callCMake",&CMakeGenerator::callCMake1,
128 	 "call the `make` utility for the specified target")
129     .def("exe",&CMakeGenerator::exe0,
130 	 "This methods generates the `CMake.mfront` "
131 	 "file in the `src` subdirectory and "
132 	 "calls `make` to generate the target "
133 	 "named `all`.")
134     .def("exe",&CMakeGenerator::exe1,
135 	 "This methods generates the `CMake.mfront` "
136 	 "file in the `src` subdirectory "
137 	 "using the provided options and "
138 	 "calls `make` to generate the target "
139 	 "named `all`.")
140     .def("exe",&CMakeGenerator::exe2,
141 	 "This methods generates the `CMake.mfront` "
142 	 "file in the `src` subdirectory and "
143 	 "calls `make` to generate the given target.")
144     .def("exe",&CMakeGenerator::exe3,
145 	 "This methods generates the `CMake.mfront` "
146 	 "file in the `src` subdirectory "
147 	 "using the provided options and "
148 	 "calls `make` to generate the given target.");
149 
150 } // end of declareCMakeGenerator
151