# file      : build/root.build
# license   : MIT; see accompanying LICENSE file

# Default C and C++ compilers. These are used as the default values for
# config.c and config.cxx, respectively, if not specified explicitly by the
# user.
#
# If not specified, the C and C++ compilers used to build the build system
# are used as the defaults.
#
# Note: should include compiler mode, if required (thus strings).
#
config [strings] config.build2.default_c
config [strings] config.build2.default_cxx

# Host C and C++ compilers. These are used as the values for config.c and
# config.cxx, respectively, in embedded ~host and ~build2 configurations.
#
# If not specified, the C and C++ compilers used to build the build system are
# used as the defaults. Note that if specified, they should be compatible with
# the rest of the ~host/~build2 configuration (compiler options, etc) and
# ABI-compatible with the build system build. Normally you would specify these
# values only to change the paths/names of the compilers, not their types.
#
# Note: should include compiler mode, if required (thus strings).
#
config [strings] config.build2.host_c
config [strings] config.build2.host_cxx

# Host preprocess/compile/link options for C and C++ compilers. These are used
# as the values for config.c.[pcl]options and config.cxx.[pcl]options,
# respectively, in embedded ~host and ~build2 configurations.
#
# If not specified, the options used to build the build system are used as the
# defaults. Note that if specified, they should be compatible with the rest of
# the ~host/~build2 configuration (compiler, etc) and ABI-compatible with the
# build system build.
#
# Note: overriding these is normally only necessary when building binary
# distribution packages. Note also that currently we assume config.cc.*
# variants are not used (as is the case for bpkg-pkg-bindist).
#
config [strings] config.build2.host_c_poptions
config [strings] config.build2.host_c_coptions
config [strings] config.build2.host_c_loptions
config [strings] config.build2.host_cxx_poptions
config [strings] config.build2.host_cxx_coptions
config [strings] config.build2.host_cxx_loptions

# Host rpaths. These are used as the value for config.bin.rpath in embedded
# ~host (but not ~build2) configuration. If not specified, the ~host rpath
# is set to [null] (even if the build system itself is built with rpath).
#
config [dir_paths] config.build2.host_rpath

# Temporary ability to build with now deprecated libpkgconf instead of
# libpkg-config. Note that libpkgconf is known to have issues on Windows and
# Mac OS so this should only be used on Linux and maybe BSDs. Also note that
# we will only keep this until upstream (again) breaks backwards compatibility
# at which point we will drop this support.
#
config [bool, config.report=false] config.build2.libpkgconf ?= false

using in

cxx.std = latest

using cxx

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

# Note that we bundle some C headers (see the LICENSE file for details).
#
h{*}: extension = h

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

if ($cxx.class == 'msvc')
  cxx.coptions += /wd4251 /wd4275 /wd4800
elif ($cxx.id == 'gcc')
{
  cxx.coptions += -Wno-maybe-uninitialized -Wno-free-nonheap-object \
-Wno-stringop-overread # libbutl

  if ($cxx.version.major >= 13)
    cxx.coptions += -Wno-dangling-reference
}
elif ($cxx.id.type == 'clang' && $cxx.version.major >= 15)
  cxx.coptions += -Wno-unqualified-std-cast-call

cxx.poptions =+ "-I$out_root" "-I$src_root"

# While we don't have any C sources to compile, we need to get the C compiler
# path to use as native/default.
#
using c.config

# Imports for build2/ (or any subdirectory other than libbuild2/) should be
# done here in order to get stable order in the host build configuration that
# we embed into libbuild2.
#
import libbutl = libbutl%lib{butl}

# Load the cli module but only if it's available. This way a distribution
# that includes pre-generated files can be built without installing cli.
# This is also the reason why we need to explicitly spell out individual
# source file prerequisites instead of using the cli.cxx{} group (it won't
# be there unless the module is configured).
#
using? cli

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