summaryrefslogtreecommitdiff
path: root/odb-examples/build/root.build
blob: 80810c7b117c3bf39f51c1c0ec79fc9f8fdef433 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# file      : build/root.build
# license   : GNU GPL v2; see accompanying LICENSE file

cxx.std = latest

using cxx

hxx{*}: extension = hxx
ixx{*}: extension = ixx
txx{*}: extension = txx
cxx{*}: extension = cxx

define sql: file
sql{*}: extension = sql

define xml: file
xml{*}: extension = xml

skeleton = ($build.mode == 'skeleton')

# The identifier of the database to compile and run the examples against. The
# valid identifiers are mysql, sqlite, pgsql, oracle, and mssql.
#
# Note: can be specified by the user but is also conditionally reflected by
#       the libodb-* libraries' examples manifest values.
#
config [string] config.odb_examples.database

database = [string] ($defined(config.odb_examples.database) \
                     ? $config.odb_examples.database        \
                     : '')

mysql  = false
sqlite = false
pgsql  = false
oracle = false
mssql  = false

switch $database
{
  case 'mysql'
    mysql = true

  case 'sqlite'
    sqlite = true

  case 'pgsql'
    pgsql = true

  case 'oracle'
    oracle = true

  case 'mssql'
    mssql = true

  case ''
    assert ($skeleton) \
      'database must be configured via config.odb_examples.database variable'

  default
    fail "invalid database '$database' specified in config.odb_examples.database value"
}

# If true, then this package is enabled as external examples for libodb
# library (see libodb's manifest for details).
#
# Note that this variable is not used in this package itself.
#
config [bool] config.odb_examples.libodb_example ?= false

# If true, then build the boost/ example.
#
config [bool] config.odb_examples.boost ?= false

boost = $config.odb_examples.boost

# If defined, then, depending on the value, build the qt/ example against Qt5
# (5) or Qt6 (6).
#
config [uint64] config.odb_examples.qt

qt = $defined(config.odb_examples.qt)

if $qt
{
  qt_ver = $config.odb_examples.qt

  assert ($qt_ver == 5 || $qt_ver == 6) \
    'config.odb_examples.qt value must be between 5 and 6'
}

# Database connections.
#

# MySQL
#
# The database user.
#
config [string] config.odb_examples.mysql.user ?= 'odb_test'

# The database password.
#
config [string] config.odb_examples.mysql.passwd

# The database name. Note that it WILL BE MODIFIED by the examples.
#
config [string] config.odb_examples.mysql.database ?= 'odb_test'

# The database host.
#
config [string] config.odb_examples.mysql.host

# The database port.
#
config [uint64] config.odb_examples.mysql.port

# The database socket path.
#
config [path] config.odb_examples.mysql.socket

# PostgreSQL
#
# The database user. Note that the named user must be allowed to connect to
# the database server without specifying credentials.
#
config [string] config.odb_examples.pgsql.user ?= 'odb_test'

# The database name. Note that it WILL BE MODIFIED by the examples.
#
config [string] config.odb_examples.pgsql.database ?= 'odb_test'

# The database host or directory of Unix-domain socket. Leaving this variable
# undefined results in using Unix-domain sockets. Machines without Unix-domain
# sockets will connect to localhost.
#
config [string] config.odb_examples.pgsql.host

# The database port or the socket file name extension for Unix-domain
# connections.
#
# For example, specifying:
#
#   config.odb_examples.pgsql.host=/var/run/postgresql
#   config.odb_examples.pgsql.port=5433
#
# Will result in the /var/run/postgresql/.s.PGSQL.5433 socket being used.
#
config [string] config.odb_examples.pgsql.port

# Oracle
#
# The database user.
#
config [string] config.odb_examples.oracle.user ?= 'odb_test'

# The database password.
#
config [string] config.odb_examples.oracle.passwd

# The database host.
#
config [string] config.odb_examples.oracle.host

# The database port.
#
config [uint64] config.odb_examples.oracle.port

# The service name. Note that the database associated with this user on this
# service WILL BE MODIFIED by the examples.
#
config [string] config.odb_examples.oracle.service

# Microsoft SQL Server
#
# The database user.
#
config [string] config.odb_examples.mssql.user ?= 'odb_test'

# The database password.
#
config [string] config.odb_examples.mssql.passwd

# The database name. Note that it WILL BE MODIFIED by the examples.
#
config [string] config.odb_examples.mssql.database ?= 'odb_test'

# The database host.
#
config [string] config.odb_examples.mssql.host

# The database port.
#
config [uint64] config.odb_examples.mssql.port

# The SQL Server instance address.
#
# Note: mutually exclusive with config.odb_examples.mssql.{host,port}.
#
config [string] config.odb_examples.mssql.server

assert (!$defined(config.odb_examples.mssql.server) || \
        !$defined(config.odb_examples.mssql.host))     \
  'variables config.odb_examples.mssql.server and config.odb_examples.mssql.host cannot be specified both'

assert (!$defined(config.odb_examples.mssql.server) || \
        !$defined(config.odb_examples.mssql.port))     \
  'variables config.odb_examples.mssql.server and config.odb_examples.mssql.port cannot be specified both'

# The SQL Server ODBC Driver.
#
config [string, null] config.odb_examples.mssql.driver

if! $skeleton
{
  if ($cxx.target.system == 'win32-msvc')
    cxx.poptions += -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS

  switch $cxx.class
  {
    case 'gcc'
    {
      cxx.coptions += -Wno-unknown-pragmas
    }
    case 'msvc'
    {
      cxx.coptions += /wd4068 /wd4251 /wd4275 /wd4800
    }
  }

  # Import odb that we are using.
  #
  import! [metadata] odb = odb%exe{odb}

  # Import the mysql client for creating the database schemas, etc.
  #
  if $mysql
  {
    import! mysql_client = mysql-client%exe{mysql}
    testscript{*}: mysql_client = $mysql_client
  }
  #
  # Import the psql client for creating the database schemas, etc.
  #
  elif $pgsql
  {
    import! pgsql_client = psql%exe{psql}
    testscript{*}: pgsql_client = $pgsql_client
  }
  #
  # Import the sqlplus client for creating the database schemas, etc.
  #
  # Note: expected to be system-installed.
  #
  elif $oracle
  {
    import! oracle_client = sqlplus%exe{sqlplus}
    testscript{*}: oracle_client = $oracle_client
  }
  #
  # Import the sqlcmd client for creating the database schemas, etc.
  #
  # Note: expected to be system-installed.
  #
  elif $mssql
  {
    import! mssql_client = sqlcmd%exe{sqlcmd}
    testscript{*}: mssql_client = $mssql_client
  }

  # Every exe{} in this project is by default a test.
  #
  exe{*}: test = true

  # Specify the test target for cross-testing.
  #
  test.target = $cxx.target
}

# The helper targets which can be used as prerequisites of test drivers which
# require either a specific database client or multiple clients for all the
# enabled databases.
#
alias{mysql-client}: $mysql_client:
{
  include = $mysql
  clean = false
}

alias{pgsql-client}: $pgsql_client:
{
  include = $pgsql
  clean = false
}

alias{database-client}: alias{mysql-client pgsql-client}