#
# Copyright (c) 2019 Vinnie Falco (vinnie dot falco at gmail dot com)
# Copyright (c) 2021 Dmitry Arkhipov (grisumbras@gmail.com)
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
# Official repository: https://github.com/boostorg/json
#

import-search /boost/config/checks ;

import boost-pretty-printers ;
import config ;
import message ;
import modules ;

local args = [ modules.peek : ARGV ] ;
local var = [ modules.peek project-config : libraries ] ;
if json in [ MATCH ^--with-(json) : $(args) $(var) ]
{
    message warn-if-requested
        : "warning:" Boost.Json was explicitly requested, but will not be
          built, because it requires C++11.
        : "note:" To enable C++11 support, use the 'cxxstd=11' command line
          argument.
        ;
}
else
{
    alias warn-if-requested ;
}

# disabling has to be done via a separate target because b2 eagerly disables
# targets with <build>no in requirements, so warn-if-requested would never be
# built and thus would never warn
alias disable : : <build>no ;

explicit warn-if-requested disable ;

rule requires ( tests + )
{
    local m = [ modules.binding config ] ;
    local result ;
    for test in $(tests)
    {
        result += [ check-target-builds $(m:D)//$(test) $(test)
            : : <source>warn-if-requested <source>disable
        ] ;
    }
    return $(result) ;
}

project
    : common-requirements
      <include>../include
      <use>$(boost_dependencies)/<warnings-as-errors>off
      <link>shared:<define>BOOST_JSON_DYN_LINK=1
      <link>static:<define>BOOST_JSON_STATIC_LINK=1
    : requirements
      [ requires
        cxx11_constexpr
        cxx11_decltype
        cxx11_hdr_tuple
        cxx11_template_aliases
        cxx11_variadic_templates
        cxx11_alignas
        cxx11_std_align
      ]
      <toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
    : usage-requirements
      <library>/boost/container//boost_container/<warnings-as-errors>off
      <define>BOOST_JSON_NO_LIB=1
    : source-location ../src
    ;

alias json_deps ;
alias json_sources : src.cpp ;
lib boost_json : json_sources ;

boost-pretty-printers.gdb-python-header gdb_printers.hpp
    : boost_json_gdb_printers.py
    : <location>../include/boost/json/detail
      <flags>--header-guard=BOOST_JSON_DETAIL_GDB_PRINTERS_HPP
      <flags>--disable-macro=
    ;
always gdb_printers.hpp ;
explicit regenerate-printers gdb_printers.hpp ;
alias regenerate-printers : gdb_printers.hpp ;
