#
# Copyright (c) 2019 Vinnie Falco (vinnie.falco@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 boost-json-bench ;
import common ;
import feature ;
import notfile ;
import os ;
import path ;
import property ;
import toolset ;

local has_nlohmann_json = [
    glob lib/nlohmann/single_include/nlohmann/json.hpp ] ;
if $(has_nlohmann_json)
{
    has_nlohmann_json = "" ;
}

local has_rapidjson = [
    glob lib/rapidjson/include/rapidjson/rapidjson.h ] ;
if $(has_rapidjson)
{
    has_rapidjson = "" ;
}

exe bench :
    bench.cpp
    /boost/json//boost_json
    :
    <include>../test
    <include>../example
    $(has_nlohmann_json)<define>BOOST_JSON_HAS_NLOHMANN_JSON
    $(has_rapidjson)<define>BOOST_JSON_HAS_RAPIDJSON
    ;

install bench-local : bench : <location>. <hardcode-dll-paths>true ;
explicit bench-local ;
always bench-local ;

local bench-files = [ glob-tree-ex data : *.json ] ;
notfile run : @run-bench : bench : : <bench.file>$(bench-files) ;
explicit run ;

rule run-bench ( target : sources * : props * )
{
    local launcher = [ property.select bench.launcher : $(props) ] ;
    if $(launcher)
    {
        launcher = "$(launcher:G=) " ;
        launcher = "$(launcher:J=) " ;
    }
    else
    {
        launcher = "" ;
    }
    LAUNCHER on $(target) = $(launcher) ;
}

actions run-bench bind FILES
{
    $(LAUNCHER) $(>) $(FLAGS) $(FILES)
}

toolset.flags $(__name__).run-bench FLAGS : <flag> ;
toolset.flags $(__name__).run-bench FLAGS : <bench.option> ;
toolset.flags $(__name__).run-bench FILES : <bench.file> ;
