#
#          Copyright Andrey Semashev 2007 - 2015.
# 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)
#

import path ;
import configure ;
import ../../build/log-platform-config ;

rule has-config-flag ( flag : properties * )
{
    if ( "<define>$(flag)" in $(properties) || "<define>$(flag)=1" in $(properties) )
    {
        return 1 ;
    }
    else
    {
        return ;
    }
}

rule check-message-compiler ( properties * )
{
    local result ;

    if <target-os>windows in $(properties)
    {
        if ! [ has-config-flag BOOST_LOG_WITHOUT_EVENT_LOG : $(properties) ]
        {
            local has_mc = [ configure.builds /boost/log/message-compiler//test-availability : $(properties) : message-compiler ] ;
            if ! $(has_mc)
            {
                result = <define>BOOST_LOG_WITHOUT_EVENT_LOG ;
            }
        }
        else
        {
            # This branch is needed to fix building with MinGW
            result = <define>BOOST_LOG_WITHOUT_EVENT_LOG ;
        }
    }
    else
    {
        result = <define>BOOST_LOG_WITHOUT_EVENT_LOG ;
    }

    return $(result) ;
}

project
    : requirements
        <conditional>@log-platform-config.set-platform-defines
        <conditional>@check-message-compiler

        <link>shared:<define>BOOST_ALL_DYN_LINK
        <toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
        <toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE
        <toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS
        <toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE
        <toolset>msvc:<cxxflags>/bigobj
        <toolset>msvc:<cxxflags>/wd4503 # decorated name length exceeded, name was truncated
        <toolset>msvc:<cxxflags>/wd4456 # declaration of 'A' hides previous local declaration
        <toolset>msvc:<cxxflags>/wd4459 # declaration of 'A' hides global declaration
        <toolset>msvc:<cxxflags>/wd4003 # not enough actual parameters for macro 'X' - caused by BOOST_PP_IS_EMPTY and BOOST_PP_IS_BEGIN_PARENS which are used by Fusion
        <toolset>intel-win:<define>_SCL_SECURE_NO_WARNINGS
        <toolset>intel-win:<define>_SCL_SECURE_NO_DEPRECATE
        <toolset>intel-win:<define>_CRT_SECURE_NO_WARNINGS
        <toolset>intel-win:<define>_CRT_SECURE_NO_DEPRECATE
        <toolset>darwin:<cxxflags>-ftemplate-depth-1024
        <toolset>gcc:<cxxflags>-ftemplate-depth-1024
        <toolset>gcc:<cxxflags>-fno-strict-aliasing  # avoids strict aliasing violations in other Boost components

        # Disable Intel warnings:
        # warning #177: function "X" was declared but never referenced
        # warning #780: using-declaration ignored -- it refers to the current namespace
        # warning #2196: routine is both "inline" and "noinline"
        # remark #1782: #pragma once is obsolete. Use #ifndef guard instead.
        # remark #193: zero used for undefined preprocessing identifier "X"
        # remark #304: access control not specified ("public" by default)
        # remark #981: operands are evaluated in unspecified order
        # remark #1418: external function definition with no prior declaration
        # Mostly comes from Boost.Phoenix: warning #411: class "X" defines no constructor to initialize the following: reference member "Y"...
        # warning #734: "X" (declared at line N of "file.hpp"), required for copy that was eliminated, is inaccessible
        # warning #279: controlling expression is constant
        <toolset>intel-win:<cxxflags>"/Qwd177,780,2196,1782,193,304,981,1418,411,734,279"
        <toolset>intel-linux:<cxxflags>"-wd177,780,2196,1782,193,304,981,1418,411,734,279"
        <toolset>intel-darwin:<cxxflags>"-wd177,780,2196,1782,193,304,981,1418,411,734,279"

        # Boost.Interprocess does not compile on Cygwin: https://github.com/boostorg/interprocess/issues/76
        <target-os>cygwin:<define>BOOST_LOG_WITHOUT_IPC

        <library>/boost/log//boost_log
        <library>/boost/log//boost_log_setup
        <library>/boost/date_time//boost_date_time
        <library>/boost/filesystem//boost_filesystem
        <library>/boost/thread//boost_thread
        <threading>multi
    ;

# Compiles each .cpp file in this directory into a separate executable
rule compile_all
{
    #ECHO executing compile_all rule ;
    local all_rules = ;
    for local file in [ glob *.cpp ]
    {
        local exename = [ MATCH "([^.]*).cpp$" : [ path.basename $(file) ] ] ;
        #ECHO "exename = $(exename)" ;
        all_rules += [ exe $(exename) : $(file) ] ;
    }

    #ECHO $(all_rules) ;
    return $(all_rules) ;
}

compile_all ;
