#---------------------------------------------------------------
# Copyright (c) 2006--2017, National Technology & Engineering Solutions
# of Sandia, LLC (NTESS).  Under the terms of Contract DE-NA0003525 with
# NTESS, the U.S. Government retains certain rights in this software.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of NTESS nor the names of its contributors may
#       be used to endorse or promote products derived from this
#       software without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#---------------------------------------------------------------

#
# The signature for Boost.build rules is described here:
#
# http://www.boost.org/build/doc/html/bbv2/overview/targets.html
#
#function-name main-target-name
#    : sources
#    : requirements
#    : default-build
#    : usage-requirements
#    ;
#
#    * "main-target-name" is the name used to request the target
#            on command line and to use it from other main targets.
#            Main target name may contain alphanumeric characters and symbols '-' and '_';
#    * "sources" is the list of source files and other main targets that must be combined.
#    * "requirements" is the list of properties that must always be present
#            when this main target is built.
#    * "default-build" is the list of properties that will be used unless
#            some other value of the same feature is already specified.
#    * "usage-requirements" is the list of properties that will be propagated
#            to all main targets that use this one, i.e. to all dependedents.
#
#
# SECTION 1: Project definition
#

import set ;
import path ;

import os ;

project votd
  : requirements
    $(sierra-warnings)
    <include>$(stk_emend-root)
    <address-model>64:<define>Build64
  : usage-requirements
    <include>$(stk_emend-root)
    <address-model>64:<define>Build64
  : build-dir $(stk_emend-builddir)
  ;

# This variable should contain the applications and associated files that
# must be installed for both developers and end users. Unless they need to
# be visible to end users, unittests should not be placed here.
local installed-end-user-files = 
  ;

# This variable should contain the applications and associated files that will
# only be installed for and visible to developers.
# Note that if the --install-developer-files option is passed to bjam these will also
# be installed for end-users. (This is only intended to be used for testing.)
local installed-developer-files = 
  stk_emend_independent_set_utest
  ;

explicit install-targets ;
alias install-targets
  : $(installed-end-user-files)
    $(installed-developer-files)
  ;

#
# SECTION 3: End-user install
#
explicit install-user-env ;
alias install-user-env : install-user-jamfile
                         install-user-bin install-user-include ;

# Dependencies listed in this target are always installed for end users.
# This should include only those executables and any other files needed by end-users.
explicit install-user-bin ;
install install-user-bin
  : $(installed-end-user-files)
    [ if-defined-val $(install-developer-files-arg) :
        # Targets listed here will only be installed if the --install-developer-files option
        # is passed to bjam. This is intended for testing that requires things like 
        # unittests to be installed when they normally would not be.
        $(installed-developer-files)
    ]
  :
  # Note that all Sierra executables are installed in a common bin directory,
  # not in a product-specific bin directory.
  <location>$(install-bin-dir)
  ;

explicit install-user-jamfile ;
install install-user-jamfile
  : [ glob $(stk_emend-root)/Jamfile ]
  : <location>$(install-root)/stk/stk_emend
    <install-source-root>$(stk_emend-root)
  ;

explicit install-user-include ;
install install-user-include
  : [ path.glob-tree $(stk_emend-root) : *.h *.hpp ]
  : <location>$(install-root)/stk/stk_emend/include
  ;

#this was copied from the Salinas Jamfile
rule bjam-features-rule ( properties * )
{
  local toolset ;
  local toolset_version ;
  local variant ;

  # ECHO "in bjam-features-rule" ;
  for local p in $(properties)
  {
    # ECHO " $(p)" ;
    local toolset_match = [ MATCH "<toolset>(.*)" : $(p) ] ;
    if $(toolset_match) { toolset += $(toolset_match) ; }
    else
     { local toolset_version_match = [ MATCH "<toolset.*:version>(.*)" : $(p) ] ;
       if $(toolset_version_match) { toolset_version += $(toolset_version_match) ; }
       else
       { local variant_match = [ MATCH "<variant>(.*)" : $(p) ] ;
         if $(variant_match) { variant += $(variant_match) ; }
       }
     }
  }
  toolset_version ?= UNKNOWN ;
  variant ?= UNKNOWN ;
  local result = "<define>MORPH_BUILD_COMPILER=\"\\\"$(toolset)-$(toolset_version)-$(variant)\\\"\"" ;
  # ECHO " $(result) " ;
  return  $(result) ;
}

alias stk_independent_set_lib
  : 
  : 
  : 
  :
  ;

exe stk_emend_independent_set_utest
  :
    [ glob $(stk_emend-root)/stk_emend/independent_set/unit_tests/*.cpp ]
    stk_independent_set_lib
    /sierra/stk_unit_test_utils//stk_unit_main
    /tpl/googletest//gtest
  : <tag>@sierra-exec-tag
    <include>$(stk_emend-root)/stk_emend/independent_set/unit_tests
    [ ifdevbuild
        <toolset>gcc:<cflags>"-Wextra -Wpedantic -Wshadow -Wno-unused-parameter"
    ]
  ;
  
