aboutsummaryrefslogtreecommitdiff
path: root/libbutl/buildfile
blob: a7b20f3a9b99d1116324a98d080f56ccf8912df2 (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
# file      : libbutl/buildfile
# license   : MIT; see accompanying LICENSE file

lib{butl}: {hxx ixx txx cxx}{** -uuid-* +uuid-io         \
                                -win32-utility           \
                                -mingw-*                 \
                                -version                 \
                                -builtin-options}        \
           {hxx}{version} {hxx ixx cxx}{builtin-options}

tclass = $cxx.target.class
tsys   = $cxx.target.system

windows = ($tclass == 'windows')

# Whether to use our own implementation of C++14 threads on MinGW (note:
# requires Windows 7 or later).
#
# Note that for now we use built-in POSIX thread support during bootstrap
# (which, as a side effect, verifies we still use MinGW GCC configured with
# POSIX support, which we still need for TLS, exceptions, and thread-safe
# static locals).
#
mingw_stdthread = ($tsys == 'mingw32')

# Exclude these from compilation on targets where does not apply.
#
lib{butl}: {hxx ixx cxx}{win32-utility}: include = $windows
lib{butl}: hxx{mingw-*}: include = $mingw_stdthread

# Our C-files are always included into C++-files that wrap the corresponding
# API so treat them as files exclude from the compilation.
#
lib{butl}: file{*.c *.h}

# Platform-specific UUID implementations.
#
lib{butl}: cxx{uuid-linux}:   include = ($tclass == 'linux')
lib{butl}: cxx{uuid-macos}:   include = ($tclass == 'macos')
lib{butl}: cxx{uuid-windows}: include = $windows
lib{butl}: cxx{uuid-freebsd}: include = ($tsys == 'freebsd' || $tsys == 'netbsd')

# GCC prior to version 6 has flaky `#pragma GCC diagnostic` so we have to
# disable certain warnings outright.
#
if ($cxx.id == 'gcc' && $cxx.version.major < 6)
  cc.coptions += -Wno-unused-function

# Additional system libraries.
#
switch $tclass, $tsys
{
  case 'linux'
    cxx.libs += -ldl

  case 'macos'
    cxx.libs += -framework CoreFoundation

  case 'windows', 'mingw32'
    cxx.libs += -lrpcrt4 -limagehlp

  case 'windows'
    cxx.libs += rpcrt4.lib imagehlp.lib

  case 'bsd', 'freebsd' | 'netbsd'
    cxx.libs += -lexecinfo
}

if! $windows
  cxx.libs += -lpthread

# Include the generated version header into the distribution (so that we don't
# pick up an installed one) and don't remove it when cleaning in src (so that
# clean results in a state identical to distributed).
#
hxx{version}: in{version} $src_root/manifest
hxx{version}:
{
  dist  = true
  clean = ($src_root != $out_root)
}

# Build options.
#
cxx.poptions =+ "-I$out_root" "-I$src_root"

if $mingw_stdthread
  cxx.poptions += -D_WIN32_WINNT=0x0601 -DLIBBUTL_MINGW_STDTHREAD

obja{*} bmia{*}: cxx.poptions += -DLIBBUTL_STATIC_BUILD
objs{*} bmis{*}: cxx.poptions += -DLIBBUTL_SHARED_BUILD

# Export options.
#
lib{butl}: cxx.export.poptions = "-I$out_root" "-I$src_root"

if $mingw_stdthread
  lib{butl}: cxx.export.poptions += -D_WIN32_WINNT=0x0601 -DLIBBUTL_MINGW_STDTHREAD

liba{butl}: cxx.export.poptions += -DLIBBUTL_STATIC
libs{butl}: cxx.export.poptions += -DLIBBUTL_SHARED

# For pre-releases use the complete version to make sure they cannot be used
# in place of another pre-release or the final version. See the version module
# for details on the version.* variable values.
#
if $version.pre_release
  lib{butl}: bin.lib.version = @"-$version.project_id"
else
  lib{butl}: bin.lib.version = @"-$version.major.$version.minor"

# Generated options parser.
#
if $cli.configured
{
  cli.cxx{builtin-options}: cli{builtin}

  cli.options += --std c++11 -I $src_root --include-with-brackets \
--include-prefix libbutl --guard-prefix LIBBUTL --cli-namespace butl::cli \
--generate-vector-scanner --generate-parse --keep-separator \
--generate-specifier --suppress-usage

  cli.cxx{*}:
  {
    # Include the generated cli files into the distribution and don't remove
    # them when cleaning in src (so that clean results in a state identical to
    # distributed). But don't install their headers since they are only used
    # internally in the builtins implementation.
    #
    dist  = true
    clean = ($src_root != $out_root)
    install = false

    # We keep the generated code in the repository so copy it back to src in
    # case of a forwarded configuration.
    #
    backlink = overwrite
  }
}
else
  # No install for the pre-generated case.
  #
  hxx{builtin-options}@./ ixx{builtin-options}@./: install = false

# Install into the libbutl/ subdirectory of, say, /usr/include/
# recreating subdirectories.
#
{hxx ixx txx}{*}:
{
  install         = include/libbutl/
  install.subdirs = true
}