2 #-------------------------------------------------------------------------------
4 # | ____| _| |_ / __ \ /\ | \/ |
5 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
6 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
7 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
8 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
10 # FreeFOAM: The Cross-Platform CFD Toolkit
12 # Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
13 # Gerber van der Graaf <gerber_graaf@users.sf.net>
14 #-------------------------------------------------------------------------------
16 # This file is part of FreeFOAM.
18 # FreeFOAM is free software: you can redistribute it and/or modify it
19 # under the terms of the GNU General Public License as published by the
20 # Free Software Foundation, either version 3 of the License, or (at your
21 # option) any later version.
23 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
24 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 # You should have received a copy of the GNU General Public License
29 # along with FreeFOAM. If not, see <http://www.gnu.org/licenses/>.
30 #-------------------------------------------------------------------------------
35 #------------------------------------------------------------------------------
38 freefoam@PY_SCRIPT_SUFFIX@ new [-h|-help]
39 freefoam@PY_SCRIPT_SUFFIX@ new source (H|C|I|IO|app) <name>
40 freefoam@PY_SCRIPT_SUFFIX@ new template (H|C|I|IO) <name>
41 freefoam@PY_SCRIPT_SUFFIX@ new cmake (lib|app)
43 Create new source and CMake files.
47 -d Output-directory, defaults to the current working directory.
49 -help Display this help message
51 In the following the arguments `source', `template' and `cmake' are explained:
54 Creates a new @PROJECT_NAME@ header (H), source (C), included implementation
55 (I), iostream operators (IO) or application (app) file. The last argument
56 specifies the class name and is used to construct the file name.
59 Creates a new @PROJECT_NAME@ header (H), source (C), included implementation
60 (I) or iostream operators (IO) file for a templated class. The next argument
61 specifies the class name and is used to construct the file name. All
62 following arguments are template parameters.
65 This type scans the output directory for sources and creates a suitable
66 CMakeLists.txt file. It takes an argument specifying whether the sources are
67 used to build a library (lib) or an application (app).
71 wmakeToCMake - Converts simple wmake based build system to CMake.
78 sys
.path
.insert(0, '@FOAM_PYTHON_DIR@')
79 from FreeFOAM
.compat
import *
81 def create_source(kind
, name
, outdir
):
83 if kind
== 'C' or kind
== 'H':
84 template
= 'foamTemplate'
87 template
= 'foamTemplateI'
91 template
= 'foamTemplateIO'
94 elif kind
== 'App' or kind
== 'app':
95 template
= 'foamAppTemplate'
98 echo('ERROR: Unknown sub-type "%s"'%kind
, file=sys
.stderr
)
100 template
= os
.path
.join(
101 os
.path
.normpath('@FOAM_DATA_DIR@'),
102 'templates', template
+ext
)
103 outname
= os
.path
.join(outdir
, name
+suffix
+ext
)
105 if not os
.path
.isdir(outdir
):
106 echo('ERROR: "%s" is not a directory'%dir, file=sys
.stderr
)
108 if os
.path
.exists(outname
):
109 echo("ERROR: Cannot make %s, file exists"%outname
, file=sys
.stderr
)
111 outfile
= open(outname
, 'wt')
112 for l
in open(template
):
113 outfile
.write(l
.replace('className', name
))
116 def create_template(kind
, name
, tArgs
, outdir
):
118 if kind
== 'C' or kind
== 'H':
119 template
= 'foamTemplateTemplate'
122 template
= 'foamTemplateTemplateI'
126 template
= 'foamTemplateTemplateIO'
130 echo('ERROR: Unknown sub-type "%s"'%kind
, file=sys
.stderr
)
132 template
= os
.path
.join(
133 os
.path
.normpath('@FOAM_DATA_DIR@'),
134 'templates', template
+ext
)
135 outname
= os
.path
.join(outdir
, name
+suffix
+ext
)
137 if not os
.path
.isdir(outdir
):
138 echo('ERROR: "%s" is not a directory'%dir, file=sys
.stderr
)
140 if os
.path
.exists(outname
):
141 echo("ERROR: Cannot make %s, file exists"%outname
, file=sys
.stderr
)
143 outfile
= open(outname
, 'wt')
144 for l
in open(template
):
146 'className', name
).replace(
147 'TemplateClassArgument', 'class '+', class '.join(tArgs
)).replace(
148 'TemplateArgument', ', '.join(tArgs
))
152 def create_cmakelists(kind
, outdir
):
153 cml
= os
.path
.join(outdir
, 'CMakeLists.txt')
156 if not os
.path
.isdir(outdir
):
157 echo('ERROR: "%s" is not a directory'%outdir
, file=sys
.stderr
)
160 if os
.path
.isfile(cml
):
161 echo('ERROR: "%s" already exists, exiting'%cml
, file=sys
.stderr
)
166 for parent
, dirs
, files
in os
.walk(outdir
):
167 d
= os
.path
.relpath(parent
, outdir
)
170 sources
.extend(map(lambda f
: os
.path
.join(d
,f
),
171 filter(lambda f
: os
.path
.splitext(f
)[1] == '.C', files
)))
173 # the name of the application
174 target_name
=os
.path
.basename(outdir
)
176 target_kind
= 'library'
178 target_kind
= 'executable'
180 # configure CMakeLists.txt
181 open(cml
, 'wt').write(
183 cmake_minimum_required(VERSION 2.8)
184 project(%(target_name)s)
186 find_package(@PROJECT_NAME@ REQUIRED)
187 include(${FOAM_USE_FILE})
189 foam_add_%(target_kind)s(%(target_name)s
193 target_link_libraries(%(target_name)s FOAM_finiteVolume)
195 # ------------------------- vim: set sw=2 sts=2 et: --------------- end-of-file
197 'target_kind': target_kind
,
198 'target_name': target_name
,
199 'sources': '\n '.join(sources
),
211 if a
== '-h' or a
== '-help':
217 elif re
.match(r
'(?i)(class|template)', a
) :
222 if f_type
== 'class':
223 create_source(f_sub_type
, class_name
, f_dir
)
225 create_template(f_sub_type
, class_name
, args
, f_dir
)
230 create_cmakelists(f_type
, f_dir
)
233 # ------------------------- vim: set sw=3 sts=3 et: --------------- end-of-file