| 1 |
#!/usr/bin/env bash |
| 2 |
# -*- indent-tabs-mode: nil; sh-basic-offset: 2; sh-indentation: 2 -*- |
| 3 |
# vi: set et sw=2: |
| 4 |
# SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 5 |
# SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception |
| 6 |
|
| 7 |
# The sh-indentation in the emacs mode-line is needed for emacs <26, see |
| 8 |
# https://debbugs.gnu.org/21751 |
| 9 |
|
| 10 |
# |
| 11 |
# TODO: |
| 12 |
# |
| 13 |
# * Check module names entered as dependencies. |
| 14 |
|
| 15 |
set -e |
| 16 |
|
| 17 |
canonicalname(){ |
| 18 |
if test $# -ne 1; then |
| 19 |
echo Usage: canonicalname path >&2 |
| 20 |
return 1 |
| 21 |
fi |
| 22 |
file="`eval echo $1`" # expand ~ |
| 23 |
if test ! -e "$file"; then |
| 24 |
echo $file: file not found >&2 |
| 25 |
return 1 |
| 26 |
fi |
| 27 |
# if this is a symlink, then follow the symlink |
| 28 |
if test -L "$file"; then |
| 29 |
fdir="`dirname \"$file\"`" |
| 30 |
flink="`readlink \"$file\"`" |
| 31 |
if test -e "$flink"; then |
| 32 |
# these are absolute links, or links in the CWD |
| 33 |
canonicalname "$flink" |
| 34 |
else |
| 35 |
canonicalname "$fdir/$flink" |
| 36 |
fi |
| 37 |
else |
| 38 |
# if this is a file, then remember the filename and |
| 39 |
# canonicalize the directory name |
| 40 |
if test -f "$file"; then |
| 41 |
fdir="`dirname \"$file\"`" |
| 42 |
fname="`basename \"$file\"`" |
| 43 |
fdir="`canonicalname \"$fdir\"`" |
| 44 |
echo "$fdir/$fname" |
| 45 |
fi |
| 46 |
# if this is a directory, then create an absolute |
| 47 |
# directory name and we are done |
| 48 |
if test -d "$file"; then |
| 49 |
(cd "$file"; pwd) |
| 50 |
fi |
| 51 |
fi |
| 52 |
} |
| 53 |
|
| 54 |
canonicalpath(){ |
| 55 |
if test $# -ne 1; then |
| 56 |
echo Usage: canonicalpath path >&2 |
| 57 |
return 1 |
| 58 |
fi |
| 59 |
dirname "$(canonicalname "$1")" |
| 60 |
} |
| 61 |
|
| 62 |
pkg_config_dependencies(){ |
| 63 |
if test $# -ne 1; then |
| 64 |
echo Usage: pkg_config_dependencies name >&2 |
| 65 |
return 1 |
| 66 |
fi |
| 67 |
name="$1" |
| 68 |
depends="`pkg-config --variable=DEPENDENCIES $name| sed -e 's/,/ /g'`" |
| 69 |
for pkg in $depends; do |
| 70 |
depends="$depends `pkg_config_dependencies $pkg`" |
| 71 |
done |
| 72 |
echo $depends |
| 73 |
} |
| 74 |
|
| 75 |
# modulesexist DEPS MODULES |
| 76 |
# |
| 77 |
# DEPS is a space-separated list of modules the new module should depend on. |
| 78 |
# MODULES is a space-separated list of modules that are known to be present. |
| 79 |
# |
| 80 |
# Each name in DEPS is checked to see whether it is present in MODULES. If |
| 81 |
# not, is is checked whether it can be found with pkg-config. If still no, an |
| 82 |
# error message is issued and modulesexist will return with an exit status |
| 83 |
# indicating failure. |
| 84 |
modulesexist(){ |
| 85 |
local status dep found |
| 86 |
status=0 |
| 87 |
|
| 88 |
for dep in $1; do |
| 89 |
found=false |
| 90 |
if [[ " $2 " == *" $dep "* ]]; then |
| 91 |
found=true |
| 92 |
fi |
| 93 |
# If module not found in list, try pkg-config |
| 94 |
if ! $found && pkg-config $dep &> /dev/null; then |
| 95 |
found=true |
| 96 |
fi |
| 97 |
if ! $found; then |
| 98 |
echo "ERROR:">&2 |
| 99 |
echo "Module with name $dep was not found" >&2 |
| 100 |
echo "Did you forget to specify its location" >&2 |
| 101 |
echo "in the DUNE_CONTROL_PATH variable?">&2 |
| 102 |
echo >&2 |
| 103 |
status=1 |
| 104 |
fi |
| 105 |
done |
| 106 |
|
| 107 |
return $status |
| 108 |
} |
| 109 |
|
| 110 |
make_unique(){ |
| 111 |
if [ "$#" = "1" ]; then |
| 112 |
# take first word |
| 113 |
for exclude_word in $1; do |
| 114 |
break; |
| 115 |
done |
| 116 |
make_unique $exclude_word "$1" 0 |
| 117 |
else |
| 118 |
local exclude_word="$1" |
| 119 |
local words="$2" |
| 120 |
local pos="$3" |
| 121 |
local length=0 |
| 122 |
local i=0 |
| 123 |
local new_words="" |
| 124 |
local cur=0 |
| 125 |
for word in $words; do |
| 126 |
if [ $i -le $pos ]; then |
| 127 |
i=$((i+1)) |
| 128 |
length=$((length+1)) |
| 129 |
new_words="$new_words $word" |
| 130 |
continue |
| 131 |
fi |
| 132 |
if [ "$word" != "$exclude_word" ]; then |
| 133 |
new_words="$new_words $word" |
| 134 |
if [ "$((length-1))" = "$pos" ]; then |
| 135 |
next_word="$word" |
| 136 |
fi |
| 137 |
length=$((length+1)) |
| 138 |
fi |
| 139 |
done |
| 140 |
if [ "$pos" -lt "$length" ]; then |
| 141 |
# process next word |
| 142 |
make_unique "$next_word" "$new_words" $((pos+1)) |
| 143 |
else |
| 144 |
export UNIQUE_WORDS="$new_words" |
| 145 |
fi |
| 146 |
fi |
| 147 |
} |
| 148 |
|
| 149 |
echo |
| 150 |
echo == Dune project/module generator == |
| 151 |
echo |
| 152 |
echo duneproject will assist you in the creation of a new Dune application. |
| 153 |
echo During this process a new directory with the name of your project will be |
| 154 |
echo created. This directory will hold all configuration and Makefiles and a |
| 155 |
echo simple example application. |
| 156 |
echo |
| 157 |
|
| 158 |
################## FIND AVAILABLE MODULES ################## |
| 159 |
|
| 160 |
. "$(canonicalpath $0)/../lib/dunemodules.lib" |
| 161 |
|
| 162 |
export PREFIX_DIR="`canonicalpath "$0"`/.." |
| 163 |
|
| 164 |
extract_multiarch_pkg_config_path |
| 165 |
|
| 166 |
# search for modules, both installed and src modules |
| 167 |
find_modules_in_path |
| 168 |
|
| 169 |
# sort modules to remove duplicates |
| 170 |
sort_modules $FOUND_MODULES |
| 171 |
FOUND_MODULES=$MODULES |
| 172 |
|
| 173 |
# get the real module names |
| 174 |
MODULES="" |
| 175 |
for i in $FOUND_MODULES; do |
| 176 |
mod=$(eval echo \$NAME_$i) |
| 177 |
MODULES="$MODULES$mod " |
| 178 |
done |
| 179 |
|
| 180 |
if [ "$MODULES" = "" ]; then |
| 181 |
echo "ERROR:">&2 |
| 182 |
echo " No dune modules were found!">&2 |
| 183 |
echo " Did you forget to specify the places where ">&2 |
| 184 |
echo " you installed your modules in the ">&2 |
| 185 |
echo " DUNE_CONTROL_PATH environment variable">&2 |
| 186 |
echo " and adjusted the PKG_CONFIG_PATH environment">&2 |
| 187 |
echo " accordingly?" >&2 |
| 188 |
exit 1; |
| 189 |
fi |
| 190 |
|
| 191 |
################## READ CMDLINE OPTIONS ########## |
| 192 |
PROJECT="$1" |
| 193 |
DEPENDENCIES="$2" |
| 194 |
VERSION="$3" |
| 195 |
MAINTAINER="$4" |
| 196 |
|
| 197 |
################## READ OPTIONS ################## |
| 198 |
|
| 199 |
while [ "$DATACORRECT" != "y" -a "$DATACORRECT" != "Y" ]; do |
| 200 |
|
| 201 |
while [ -z $PROJECT ]; do |
| 202 |
read -p "1) Name of your new Project? (e.g.: dune-grid): " PROJECT |
| 203 |
if echo "$MODULES" | grep -q ^$PROJECT$; then |
| 204 |
read -p " A module named $PROJECT already exists. Continue anyway? [y/N] " CONT |
| 205 |
if test x$DELETE = xy -o x$DELETE = xY; then |
| 206 |
PROJECT="" |
| 207 |
fi |
| 208 |
elif echo "$PROJECT" | grep -q "\."; then |
| 209 |
echo "The Name contains a dot (.) which is not allowed." |
| 210 |
PROJECT="" |
| 211 |
fi |
| 212 |
done |
| 213 |
MODULE="$PROJECT" |
| 214 |
|
| 215 |
DEPOK=1 |
| 216 |
|
| 217 |
while [ "$DEPOK" != 0 ]; do |
| 218 |
echo "2) Which modules should this module depend on?" |
| 219 |
echo " The following modules have been found:" |
| 220 |
echo " $MODULES" |
| 221 |
# for i in $MODULES; do echo -n " $i"; done |
| 222 |
# echo "" |
| 223 |
while [ -z "$DEPENDENCIES" ]; do |
| 224 |
read -p " Enter space-separated list: " DEPENDENCIES |
| 225 |
done |
| 226 |
set +e |
| 227 |
modulesexist "$DEPENDENCIES" "$MODULES" |
| 228 |
DEPOK=$? |
| 229 |
set -e |
| 230 |
if [ "$DEPOK" != 0 ]; then |
| 231 |
DEPENDENCIES="" |
| 232 |
fi |
| 233 |
done |
| 234 |
|
| 235 |
while [ -z $VERSION ]; do |
| 236 |
read -p "3) Project/Module version? " VERSION |
| 237 |
done |
| 238 |
while [ -z "$MAINTAINER" ]; do |
| 239 |
read -p "4) Maintainer's email address? " MAINTAINER |
| 240 |
done |
| 241 |
|
| 242 |
echo |
| 243 |
echo "creating Project \"$PROJECT\", version $VERSION " |
| 244 |
echo "which depends on \"$DEPENDENCIES\"" |
| 245 |
echo "with maintainer \"$MAINTAINER\"" |
| 246 |
read -p "Is this information correct? [y/N] " DATACORRECT |
| 247 |
|
| 248 |
# reset data if necessary |
| 249 |
if [ "$DATACORRECT" != "y" -a "$DATACORRECT" != "Y" ]; then |
| 250 |
PROJECT="" |
| 251 |
DEPENDENCIES="" |
| 252 |
VERSION="" |
| 253 |
MAINTAINER="" |
| 254 |
fi |
| 255 |
|
| 256 |
done |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
echo |
| 261 |
echo "A sample code $MODULE.cc is generated in the \"$PROJECT\" directory." |
| 262 |
echo "Look at the README and dune.module files there." |
| 263 |
echo "Now you can run the dunecontrol script which will setup the new module." |
| 264 |
echo "Sometimes you may have to tweak CMakeLists.txt a bit." |
| 265 |
|
| 266 |
if test -d $PROJECT; then |
| 267 |
echo WARNING: |
| 268 |
echo "A directory with the name $PROJECT already exists." |
| 269 |
echo "Do you want to continue anyway?" |
| 270 |
read -p "Type Y to overwrite the old directory, N to abort. [y/N] " DELETE |
| 271 |
if test x$DELETE != xy -a x$DELETE != xY; then |
| 272 |
echo Abort... |
| 273 |
exit 1 |
| 274 |
fi |
| 275 |
rm -rf "$PROJECT" |
| 276 |
fi |
| 277 |
mkdir "$PROJECT" |
| 278 |
|
| 279 |
################## dune.module ################## |
| 280 |
cat > "$PROJECT/dune.module" <<C_DELIM |
| 281 |
################################ |
| 282 |
# Dune module information file # |
| 283 |
################################ |
| 284 |
|
| 285 |
# Name of the module |
| 286 |
Module: $MODULE |
| 287 |
Version: $VERSION |
| 288 |
Maintainer: $MAINTAINER |
| 289 |
# Required build dependencies |
| 290 |
Depends: $DEPENDENCIES |
| 291 |
# Optional build dependencies |
| 292 |
#Suggests: |
| 293 |
C_DELIM |
| 294 |
|
| 295 |
## Create the parameters passed to DUNE_CHECK_ALL |
| 296 |
|
| 297 |
# save module list of dunemodules.inc |
| 298 |
save_MODULES=$MODULES |
| 299 |
for name in $DEPENDENCIES; do |
| 300 |
mod="`fix_variable_name $name`" |
| 301 |
if test "x$(eval echo \$HAVE_$mod)" != "x"; then |
| 302 |
# found via dunemodules.inc |
| 303 |
sort_modules "$mod" |
| 304 |
for mod in $MODULES; do |
| 305 |
M_DEPS="$M_DEPS $(eval echo \$NAME_$mod)" |
| 306 |
done |
| 307 |
MODULES=$save_MODULES |
| 308 |
else |
| 309 |
# found via pkg-config |
| 310 |
M_DEPS="`pkg_config_dependencies $name` $name" |
| 311 |
fi |
| 312 |
for dep in $M_DEPS; do |
| 313 |
CHECK="$CHECK [$dep]" |
| 314 |
done |
| 315 |
done |
| 316 |
set +x |
| 317 |
make_unique "$CHECK" |
| 318 |
|
| 319 |
# insert , between modules |
| 320 |
j=0 |
| 321 |
for dep in $UNIQUE_WORDS; do |
| 322 |
if [ "$j" = "0" ]; then |
| 323 |
CHECK="$dep" |
| 324 |
j=1 |
| 325 |
else |
| 326 |
CHECK="$CHECK, $dep" |
| 327 |
fi |
| 328 |
done |
| 329 |
|
| 330 |
echo "------------------------------------------" |
| 331 |
echo "writing initial files:" |
| 332 |
|
| 333 |
# complete module name with _ instead of - to not confuse automake |
| 334 |
fix_and_assign CMODULE $MODULE |
| 335 |
# module name without prefix "dune-" |
| 336 |
NAME=`echo $PROJECT | sed -e 's/dune[_-]//'` |
| 337 |
# $NAME with _ instead of - to not confuse automake |
| 338 |
NAME_=`echo $NAME | tr '-' '_'` |
| 339 |
# module name in uppercase with _ instead of - |
| 340 |
UNAME=`echo $PROJECT | tr '-' '_' | sed 's/\(.*\)/\U\1/'` |
| 341 |
|
| 342 |
################## README ################## |
| 343 |
echo "- $PROJECT/README" |
| 344 |
cat > "$PROJECT/README" <<R_DELIM |
| 345 |
Preparing the Sources |
| 346 |
========================= |
| 347 |
|
| 348 |
Additional to the software mentioned in README you'll need the |
| 349 |
following programs installed on your system: |
| 350 |
|
| 351 |
cmake >= 3.16 |
| 352 |
|
| 353 |
Getting started |
| 354 |
--------------- |
| 355 |
|
| 356 |
If these preliminaries are met, you should run |
| 357 |
|
| 358 |
dunecontrol all |
| 359 |
|
| 360 |
which will find all installed dune modules as well as all dune modules |
| 361 |
(not installed) which sources reside in a subdirectory of the current |
| 362 |
directory. Note that if dune is not installed properly you will either |
| 363 |
have to add the directory where the dunecontrol script resides (probably |
| 364 |
./dune-common/bin) to your path or specify the relative path of the script. |
| 365 |
|
| 366 |
Most probably you'll have to provide additional information to dunecontrol |
| 367 |
(e. g. compilers, configure options) and/or make options. |
| 368 |
|
| 369 |
The most convenient way is to use options files in this case. The files |
| 370 |
define four variables: |
| 371 |
|
| 372 |
CMAKE_FLAGS flags passed to cmake (during configure) |
| 373 |
|
| 374 |
An example options file might look like this: |
| 375 |
|
| 376 |
#use this options to configure and make if no other options are given |
| 377 |
CMAKE_FLAGS=" \\ |
| 378 |
-DCMAKE_CXX_COMPILER=g++-14 \\ |
| 379 |
-DCMAKE_CXX_FLAGS='-Wall -pedantic' \\ |
| 380 |
-DCMAKE_INSTALL_PREFIX=/install/path" #Force g++-14 and set compiler flags |
| 381 |
|
| 382 |
If you save this information into example.opts you can pass the opts file to |
| 383 |
dunecontrol via the --opts option, e. g. |
| 384 |
|
| 385 |
dunecontrol --opts=example.opts all |
| 386 |
|
| 387 |
More info |
| 388 |
--------- |
| 389 |
|
| 390 |
See |
| 391 |
|
| 392 |
dunecontrol --help |
| 393 |
|
| 394 |
for further options. |
| 395 |
|
| 396 |
|
| 397 |
The full build system is described in the dune-common/doc/buildsystem (Git version) or under share/doc/dune-common/buildsystem if you installed DUNE! |
| 398 |
R_DELIM |
| 399 |
|
| 400 |
################## CMakeLists.txt ################## |
| 401 |
echo "- $PROJECT/CMakeLists.txt" |
| 402 |
cat> "$PROJECT/CMakeLists.txt" << M_DELIM |
| 403 |
cmake_minimum_required(VERSION 3.16) |
| 404 |
project($PROJECT CXX) |
| 405 |
|
| 406 |
if(NOT (dune-common_DIR OR dune-common_ROOT OR |
| 407 |
"\${CMAKE_PREFIX_PATH}" MATCHES ".*dune-common.*")) |
| 408 |
string(REPLACE \${PROJECT_NAME} dune-common dune-common_DIR |
| 409 |
\${PROJECT_BINARY_DIR}) |
| 410 |
endif() |
| 411 |
|
| 412 |
#find dune-common and set the module path |
| 413 |
find_package(dune-common REQUIRED) |
| 414 |
list(APPEND CMAKE_MODULE_PATH "\${PROJECT_SOURCE_DIR}/cmake/modules" |
| 415 |
\${dune-common_MODULE_PATH}) |
| 416 |
|
| 417 |
#include the dune macros |
| 418 |
include(DuneMacros) |
| 419 |
|
| 420 |
# deactivate global include-directories (old versions of dune used to need the OLD policy to work) |
| 421 |
dune_policy(SET DP_DEFAULT_INCLUDE_DIRS NEW) |
| 422 |
|
| 423 |
# start a dune project with information from dune.module |
| 424 |
dune_project() |
| 425 |
|
| 426 |
add_subdirectory(src) |
| 427 |
add_subdirectory(dune) |
| 428 |
add_subdirectory(doc) |
| 429 |
add_subdirectory(cmake/modules) |
| 430 |
|
| 431 |
# finalize the dune project, e.g. generating config.h etc. |
| 432 |
finalize_dune_project() |
| 433 |
M_DELIM |
| 434 |
|
| 435 |
################## PROJECT.PC.IN ################## |
| 436 |
echo "- $PROJECT/$MODULE.pc.in" |
| 437 |
cat> "$PROJECT/$MODULE.pc.in" << CC_DELIM |
| 438 |
prefix=@prefix@ |
| 439 |
exec_prefix=@exec_prefix@ |
| 440 |
libdir=@libdir@ |
| 441 |
includedir=@includedir@ |
| 442 |
CXX=@CXX@ |
| 443 |
CC=@CC@ |
| 444 |
DEPENDENCIES=@REQUIRES@ |
| 445 |
|
| 446 |
Name: @PACKAGE_NAME@ |
| 447 |
Version: @VERSION@ |
| 448 |
Description: $MODULE module |
| 449 |
URL: http://dune-project.org/ |
| 450 |
Requires: ${DEPENDENCIES} |
| 451 |
Libs: -L\${libdir} |
| 452 |
Cflags: -I\${includedir} |
| 453 |
CC_DELIM |
| 454 |
echo " Please remember to update your $PROJECT/$MODULE.pc.in," |
| 455 |
echo " Description and URL are missing right now." |
| 456 |
|
| 457 |
################# config.h.cmake ##################### |
| 458 |
|
| 459 |
echo "- $PROJECT/config.h.cmake" |
| 460 |
cat> "$PROJECT/config.h.cmake" <<EOF |
| 461 |
/* begin $PROJECT |
| 462 |
put the definitions for config.h specific to |
| 463 |
your project here. Everything above will be |
| 464 |
overwritten |
| 465 |
*/ |
| 466 |
|
| 467 |
/* begin private */ |
| 468 |
/* Name of package */ |
| 469 |
#define PACKAGE "@DUNE_MOD_NAME@" |
| 470 |
|
| 471 |
/* Define to the address where bug reports for this package should be sent. */ |
| 472 |
#define PACKAGE_BUGREPORT "@DUNE_MAINTAINER@" |
| 473 |
|
| 474 |
/* Define to the full name of this package. */ |
| 475 |
#define PACKAGE_NAME "@DUNE_MOD_NAME@" |
| 476 |
|
| 477 |
/* Define to the full name and version of this package. */ |
| 478 |
#define PACKAGE_STRING "@DUNE_MOD_NAME@ @DUNE_MOD_VERSION@" |
| 479 |
|
| 480 |
/* Define to the one symbol short name of this package. */ |
| 481 |
#define PACKAGE_TARNAME "@DUNE_MOD_NAME@" |
| 482 |
|
| 483 |
/* Define to the home page for this package. */ |
| 484 |
#define PACKAGE_URL "@DUNE_MOD_URL@" |
| 485 |
|
| 486 |
/* Define to the version of this package. */ |
| 487 |
#define PACKAGE_VERSION "@DUNE_MOD_VERSION@" |
| 488 |
|
| 489 |
/* end private */ |
| 490 |
|
| 491 |
/* Define to the version of $PROJECT */ |
| 492 |
#define ${UNAME}_VERSION "@${UNAME}_VERSION@" |
| 493 |
|
| 494 |
/* Define to the major version of $PROJECT */ |
| 495 |
#define ${UNAME}_VERSION_MAJOR @${UNAME}_VERSION_MAJOR@ |
| 496 |
|
| 497 |
/* Define to the minor version of $PROJECT */ |
| 498 |
#define ${UNAME}_VERSION_MINOR @${UNAME}_VERSION_MINOR@ |
| 499 |
|
| 500 |
/* Define to the revision of $PROJECT */ |
| 501 |
#define ${UNAME}_VERSION_REVISION @${UNAME}_VERSION_REVISION@ |
| 502 |
|
| 503 |
/* end $PROJECT |
| 504 |
Everything below here will be overwritten |
| 505 |
*/ |
| 506 |
EOF |
| 507 |
## done |
| 508 |
|
| 509 |
############################################################### |
| 510 |
################## The source subdirectory #################### |
| 511 |
############################################################### |
| 512 |
|
| 513 |
mkdir "$PROJECT/src" |
| 514 |
|
| 515 |
################## src/CMakeLists.txt ################## |
| 516 |
|
| 517 |
echo "- $PROJECT/src/CMakeLists.txt" |
| 518 |
cat> "$PROJECT/src/CMakeLists.txt" << M_DELIM |
| 519 |
# create custom target |
| 520 |
add_executable(${MODULE} ${MODULE}.cc) |
| 521 |
|
| 522 |
# link target against found dune libraries (e.g. dune-common) |
| 523 |
target_link_dune_default_libraries(${MODULE}) |
| 524 |
|
| 525 |
# set include directories for the target |
| 526 |
dune_default_include_directories(${MODULE} PRIVATE) |
| 527 |
|
| 528 |
# link target against other dune registered packages (e.g. TBB, METIS, etc.) |
| 529 |
dune_target_enable_all_packages(${MODULE}) |
| 530 |
M_DELIM |
| 531 |
|
| 532 |
################## PROJECT.CC ################## |
| 533 |
echo "- $PROJECT/src/$MODULE.cc" |
| 534 |
cat> "$PROJECT/src/$MODULE.cc" << CC_DELIM |
| 535 |
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 536 |
// vi: set et ts=4 sw=2 sts=2: |
| 537 |
|
| 538 |
#ifdef HAVE_CONFIG_H |
| 539 |
# include "config.h" |
| 540 |
#endif |
| 541 |
#include <iostream> |
| 542 |
#include <dune/common/parallel/mpihelper.hh> // An initializer of MPI |
| 543 |
#include <dune/common/exceptions.hh> // We use exceptions |
| 544 |
|
| 545 |
int main(int argc, char** argv) |
| 546 |
{ |
| 547 |
try{ |
| 548 |
// Maybe initialize MPI |
| 549 |
Dune::MPIHelper& helper = Dune::MPIHelper::instance(argc, argv); |
| 550 |
std::cout << "Hello World! This is ${PROJECT}." << std::endl; |
| 551 |
if(Dune::MPIHelper::isFake) |
| 552 |
std::cout<< "This is a sequential program." << std::endl; |
| 553 |
else |
| 554 |
std::cout<<"I am rank "<<helper.rank()<<" of "<<helper.size() |
| 555 |
<<" processes!"<<std::endl; |
| 556 |
return 0; |
| 557 |
} |
| 558 |
catch (Dune::Exception &e){ |
| 559 |
std::cerr << "Dune reported error: " << e << std::endl; |
| 560 |
} |
| 561 |
catch (...){ |
| 562 |
std::cerr << "Unknown exception thrown!" << std::endl; |
| 563 |
} |
| 564 |
} |
| 565 |
CC_DELIM |
| 566 |
|
| 567 |
################################################################ |
| 568 |
################## The headers subdirectory #################### |
| 569 |
################################################################ |
| 570 |
|
| 571 |
echo "- $PROJECT/dune/$NAME" |
| 572 |
mkdir "$PROJECT/dune" |
| 573 |
mkdir "$PROJECT/dune/$NAME" |
| 574 |
|
| 575 |
################## dune/CMakeLists.txt ################# |
| 576 |
echo "- $PROJECT/dune/CMakeLists.txt" |
| 577 |
cat> $PROJECT/dune/CMakeLists.txt <<EOF |
| 578 |
add_subdirectory($NAME) |
| 579 |
EOF |
| 580 |
|
| 581 |
################## dune/$NAME/CMakeLists.txt ########### |
| 582 |
echo "- $PROJECT/dune/$NAME/CMakeLists.txt" |
| 583 |
cat> $PROJECT/dune/$NAME/CMakeLists.txt <<EOF |
| 584 |
#install headers |
| 585 |
install(FILES ${NAME}.hh DESTINATION \${CMAKE_INSTALL_INCLUDEDIR}/dune/$NAME) |
| 586 |
EOF |
| 587 |
|
| 588 |
################## dune/$NAME/$NAME.hh ################# |
| 589 |
echo "- $PROJECT/dune/$NAME/$NAME.hh" |
| 590 |
cat> $PROJECT/dune/$NAME/$NAME.hh <<EOF |
| 591 |
#ifndef ${UNAME}_HH |
| 592 |
#define ${UNAME}_HH |
| 593 |
|
| 594 |
// add your classes here |
| 595 |
|
| 596 |
#endif // ${UNAME}_HH |
| 597 |
EOF |
| 598 |
|
| 599 |
|
| 600 |
############################################################### |
| 601 |
################## The doc subdirectory ####################### |
| 602 |
############################################################### |
| 603 |
|
| 604 |
mkdir "$PROJECT/doc" |
| 605 |
|
| 606 |
################## doc/CMakeLists.txt ################# |
| 607 |
echo "- $PROJECT/doc/CMakeLists.txt" |
| 608 |
cat> "$PROJECT/doc/CMakeLists.txt" << CC_DELIM |
| 609 |
add_subdirectory("doxygen") |
| 610 |
CC_DELIM |
| 611 |
|
| 612 |
############################################################### |
| 613 |
############### The doc/doxygen subdirectory ################## |
| 614 |
############################################################### |
| 615 |
|
| 616 |
mkdir "$PROJECT/doc/doxygen" |
| 617 |
|
| 618 |
#################### basic Doxylocal ########################## |
| 619 |
|
| 620 |
echo "- $PROJECT/doc/doxygen/Doxylocal" |
| 621 |
if [ "x`which doxygen`" == "x" ]; then |
| 622 |
echo "Doxygen is not installed! Your documentation will not work without it." |
| 623 |
fi |
| 624 |
# Where to search and which files to use |
| 625 |
cat> $PROJECT/doc/doxygen/Doxylocal << CC_DELIM |
| 626 |
# This file contains local changes to the doxygen configuration |
| 627 |
# please use '+=' to add files/directories to the lists |
| 628 |
|
| 629 |
# The INPUT tag can be used to specify the files and/or directories that contain |
| 630 |
# documented source files. You may enter file names like "myfile.cpp" or |
| 631 |
# directories like "/usr/src/myproject". Separate the files or directories |
| 632 |
# with spaces. |
| 633 |
|
| 634 |
INPUT += @top_srcdir@/dune/ |
| 635 |
# see e.g. dune-grid for the examples of mainpage and modules |
| 636 |
# INPUT += @srcdir@/mainpage \\ |
| 637 |
# @srcdir@/modules |
| 638 |
|
| 639 |
# The EXCLUDE tag can be used to specify files and/or directories that should |
| 640 |
# be excluded from the INPUT source files. This way you can easily exclude a |
| 641 |
# subdirectory from a directory tree whose root is specified with the INPUT tag. |
| 642 |
|
| 643 |
# EXCLUDE += @top_srcdir@/dune/$NAME/test |
| 644 |
|
| 645 |
# The EXAMPLE_PATH tag can be used to specify one or more files or |
| 646 |
# directories that contain example code fragments that are included (see |
| 647 |
# the \include command). |
| 648 |
|
| 649 |
# EXAMPLE_PATH += @top_srcdir@/src |
| 650 |
|
| 651 |
# The IMAGE_PATH tag can be used to specify one or more files or |
| 652 |
# directories that contain image that are included in the documentation (see |
| 653 |
# the \image command). |
| 654 |
|
| 655 |
# IMAGE_PATH += @top_srcdir@/dune/$NAME/pics |
| 656 |
CC_DELIM |
| 657 |
|
| 658 |
################# doc/doxygen/CMakeLists.txt ##################### |
| 659 |
|
| 660 |
echo "- $PROJECT/doc/doxygen/CMakeLists.txt" |
| 661 |
cat> "$PROJECT/doc/doxygen/CMakeLists.txt" << CC_DELIM |
| 662 |
# shortcut for creating the Doxyfile.in and Doxyfile |
| 663 |
add_doxygen_target() |
| 664 |
CC_DELIM |
| 665 |
|
| 666 |
######################################################### |
| 667 |
############### The cmake subdirectory ################## |
| 668 |
######################################################### |
| 669 |
|
| 670 |
mkdir "$PROJECT/cmake" |
| 671 |
|
| 672 |
######################################################### |
| 673 |
############### The cmake/modules subdirectory ########## |
| 674 |
######################################################### |
| 675 |
|
| 676 |
mkdir "$PROJECT/cmake/modules" |
| 677 |
|
| 678 |
macroname="" |
| 679 |
for i in $(echo $PROJECT| sed 's/-/ /g'); do |
| 680 |
firstchar=$(echo $i | sed 's/\(.\).*/\1/') |
| 681 |
macroname=$macroname$(echo $firstchar | tr '[a-z]' '[A-Z]')$(echo $i | sed 's/.\(.*\)/\1/') |
| 682 |
done |
| 683 |
macroname="$macroname""Macros.cmake" |
| 684 |
|
| 685 |
################# cmake/modules/CMakeLists.txt ##################### |
| 686 |
|
| 687 |
echo "- $PROJECT/cmake/modules/CMakeLists.txt" |
| 688 |
cat> "$PROJECT/cmake/modules/CMakeLists.txt" <<EOF |
| 689 |
set(modules "$macroname") |
| 690 |
|
| 691 |
install(FILES \${modules} DESTINATION \${DUNE_INSTALL_MODULEDIR}) |
| 692 |
EOF |
| 693 |
|
| 694 |
################# cmake/modules/$macroname ##################### |
| 695 |
|
| 696 |
echo "- $PROJECT/cmake/modules/$macroname" |
| 697 |
cat> "$PROJECT/cmake/modules/$macroname" <<EOF |
| 698 |
# File for module specific CMake tests. |
| 699 |
EOF |
| 700 |
|
| 701 |
|
| 702 |
################# done ##################### |
| 703 |
|
| 704 |
echo |
| 705 |
echo "done." |
| 706 |
echo "------------------------------------------" |
| 707 |
echo "For further details read the Dune build system documentation at" |
| 708 |
echo "https://www.dune-project.org/buildsystem/" |