Debian Codegraph @

tools/generate-sandbox-project.sh

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 # (C) Copyright 2022 ECMWF.
4 #
5 # This software is licensed under the terms of the Apache Licence Version 2.0
6 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
7 # In applying this licence, ECMWF does not waive the privileges and immunities
8 # granted to it by virtue of its status as an intergovernmental organisation nor
9 # does it submit to any jurisdiction.
10
11
12 set -e
13
14 function helpscip-shell shell atlas-ecmwf 0.46.0-2 help(). {
15 echoscip-shell system . . echo. "$(basenamescip-shell system . . basename. ${BASH_SOURCE[0]}) --project PROJECT_DIR [--cxx] [--fortran] [--build]"
16 echoscip-shell system . . echo. ""
17 echoscip-shell system . . echo. "DECRIPTION"
18 echoscip-shell system . . echo. " Tool that generates a simple CMake project (not with ecbuild)"
19 echoscip-shell system . . echo. " with a \"main\" program that is linked to atlas."
20 echoscip-shell system . . echo. " Note: It is intended for quickly prototyping or testing atlas features."
21 echoscip-shell system . . echo. " For more complicated projects, please see"
22 echoscip-shell system . . echo. " https://sites.ecmwf.int/docs/atlas/getting_started/linking"
23 echoscip-shell system . . echo. ""
24 echoscip-shell system . . echo. "OPTIONS"
25 echoscip-shell system . . echo. " --help Print this help"
26 echoscip-shell system . . echo. " --project Path of project directory to be generated"
27 echoscip-shell system . . echo. " --c++ , --cxx Create C++ project (default if not specified)"
28 echoscip-shell system . . echo. " --fortran Create Fortran project instead of C++"
29 echoscip-shell system . . echo. " --build Attempt to build template project in 'build'"
30 echoscip-shell system . . echo. " subdirectory of generated project"
31 }
32
33 LANGUAGES=C
34 WITH_CXX=false
35 WITH_Fortran=false
36 WITH_build=false
37
38 if [scip-shell system . . `[`. $# -eq 0 ]; then
39 helpscip-shell shell atlas-ecmwf 0.46.0-2 help().
40 exit 1
41 fi
42
43 while testscip-shell system . . test. $# -gt 0; do
44
45 case "$1" in
46 --project)
47 PROJECT_DIR=$2
48 PROJECT_NAME=$(basenamescip-shell system . . basename. $PROJECT_DIR)
49 shift # past argument
50 shift # past value
51 ;;
52 --c++|--cxx)
53 WITH_CXX=true
54 LANGUAGES="${LANGUAGES} CXX"
55 shift
56 ;;
57 --fortran)
58 WITH_Fortran=true
59 LANGUAGES="${LANGUAGES} Fortran"
60 shift
61 ;;
62 --build)
63 WITH_build=true
64 shift
65 ;;
66 --help|-h)
67 helpscip-shell shell atlas-ecmwf 0.46.0-2 help().
68 shift
69 ;;
70 *)
71 # unknown option
72 helpscip-shell shell atlas-ecmwf 0.46.0-2 help().
73 break
74 ;;
75 esac
76 done
77
78 if ( $WITH_Fortran && $WITH_CXX ) ; then
79 echoscip-shell system . . echo. "ERROR: Both --cxx and --fortran were supplied. Choose one only."
80 exit 1
81 fi
82
83 if ( ! $WITH_Fortran && ! $WITH_CXX ) ; then
84 echoscip-shell system . . echo. "No language specified. Defaulting to use C++."
85 WITH_CXX=true
86 LANGUAGES="${LANGUAGES} CXX"
87 fi
88
89 mkdirscip-shell system . . mkdir. -p $PROJECT_DIR
90 cd $PROJECT_DIR
91 catscip-shell system . . cat. << EOF > CMakeLists.txt
92 cmake_minimum_required( VERSION 3.18 )
93
94 project( ${PROJECT_NAME} VERSION 0.0.0 LANGUAGES ${LANGUAGES} )
95
96 find_package( atlas REQUIRED )
97
98 EOF
99
100 if ( $WITH_CXX ) ; then
101 catscip-shell system . . cat. <<- EOF >> CMakeLists.txt
102 add_executable( main )
103 target_sources( main PUBLIC main.cc )
•104 target_link_libraries( main PUBLIC atlas_ecmwf )
105 EOF
106 catscip-shell system . . cat. <<- EOF > main.cc
107 #include "atlas/library.h"
108 #include "atlas/runtime/Log.h"
109 int main(int argc, char* argv[]) {
110 atlas::initialize(argc,argv);
111 atlas::Log::info() << "Hello from C++" << std::endl;
112 atlas::finalize();
113 return 0;
114 }
115 EOF
116 elif ( $WITH_Fortran ) ; then
117 catscip-shell system . . cat. <<- EOF >> CMakeLists.txt
118 add_executable( main )
119 target_sources( main PUBLIC main.F90 )
•120 target_link_libraries( main PUBLIC atlas_ecmwf_f )
121 EOF
122 catscip-shell system . . cat. <<- EOF > main.F90
123 program main
124 use atlas_module
125 implicit none
126 call atlas_initialize()
127 call atlas_log%info("Hello from Fortran")
128 call atlas_finalize()
129 end program
130 EOF
131 fi
132
133 echoscip-shell system . . echo. "Template project ${PROJECT_NAME} has been created in ${PROJECT_DIR}"
134
135 if ( $WITH_build ) ; then
136 mkdirscip-shell system . . mkdir. -p build
137 cd build
138
139 echoscip-shell system . . echo. ""
140 echoscip-shell system . . echo. "Project ${PROJECT_NAME} is being configured in $(pwdscip-shell system . . pwd.)"
141
142 cmakescip-shell system . . cmake. ..
143
144 echoscip-shell system . . echo. ""
145 echoscip-shell system . . echo. "Project ${PROJECT_NAME} is being built in $(pwdscip-shell system . . pwd.)"
146
147 makescip-shell system . . make. VERBOSE=1
148
149 echoscip-shell system . . echo. ""
150 echoscip-shell system . . echo. "Running program main in $(pwdscip-shell system . . pwd.)"
151 echoscip-shell system . . echo. ""
152 ./main
153 fi