#--------------------------------------------------------------------
#    Copyright 2002 - 2008, 2010, 2011 National Technology &         
#    Engineering Solutions of Sandia, LLC (NTESS). Under the terms   
#    of Contract DE-NA0003525 with NTESS, there is a                 
#    non-exclusive license for use of this work by or on behalf      
#    of the U.S. Government.  Export of this program may require     
#    a license from the United States Government.                    
#--------------------------------------------------------------------

#
# 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 ;

local stk_balance-root-inc ;
if $(RTenv-arg) = "user" {
  stk_balance-root-inc = $(stk_balance-root)/include ;
} else {
  stk_balance-root-inc = $(stk_balance-root) ;
}

project votd
  : requirements
    $(sierra-warnings)
    <include>$(stk_balance-root-inc)
  : usage-requirements
    <include>$(stk_balance-root-inc)
  : build-dir $(stk_balance-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 = 
  stk_balance
  stk_balance_m2n
  ;
#
# 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_balance_unit_tester
  stk_balance_integration_tester
  stk_balance_doc_tester
  ;

#
# SECTION 2: Development install
#

# Dependencies listed in this target are installed in the developer's project.
# This should include all executables and any other files needed for developer use.
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 
                         install-user-lib 
                       ;

# This rule copies build-system related files for this product to the install-root.
explicit install-user-jamfile ;
install install-user-jamfile
  : [ glob $(stk_balance-root)/Jamfile ]
  : <location>$(install-root)/stk/stk_balance
    <install-source-root>$(stk_balance-root)
  ;


explicit install-exe-targets ;
alias install-exe-targets : ;

# 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-include ;
install install-user-include
  : [ path.glob-tree $(stk_balance-root)/stk_balance : *.h *.hpp *.H ]
  : <location>$(install-root)/stk/stk_balance/include/stk_balance <install-source-root>$(stk_balance-root)/stk_balance
  ;

explicit install-user-lib ;
install install-user-lib
  : stk_balance_lib
    search_tolerance_algs
  : <location>$(install-root)/stk/stk_balance/lib
  ;

# This is currently a header-only library, so it must not use the lib rule.
# http://www.boost.org/boost-build2/doc/html/bbv2/faq/header-only-libraries.html
# If sources are added to this library change this target to use the lib rule instead.
alias search_tolerance
  : # No sources defined for header-only libraries.
  : # No build requirements
  : # No default build
  : <include>$(stk_balance-root-inc)/stk_balance/search_tolerance
  ;

lib search_tolerance_algs
  :
    [ ifdevbuild 
      [ glob $(stk_balance-root)/stk_balance/search_tolerance_algs/*.cpp 
      ] 
    ]
    search_tolerance
    /sierra/stk_mesh//stk_mesh_base
  :
    <include>$(stk_balance-root-inc)/stk_balance/search_tolerance_algs/
    [ ifuserbuild <file>$(stk_balance-root)/lib/libsearch_tolerance_algs.a ]
  :
  :
  ;

lib stk_balance_lib
  :
    [ ifdevbuild 
      [ glob 
             $(stk_balance-root)/stk_balance/*.cpp 
             $(stk_balance-root)/stk_balance/internal/*.cpp 
             $(stk_balance-root)/stk_balance/mesh/*.cpp
             $(stk_balance-root)/stk_balance/io/*.cpp
             $(stk_balance-root)/stk_balance/setup/*.cpp
      ]
    ]
    search_tolerance
    search_tolerance_algs
    /sierra/stk_io//stk_io
    /sierra/stk_mesh//stk_mesh_base
    /tpl/trilinos//zoltan2
    # /tpl/trilinos//teuchoscomm
    # /tpl/trilinos//tpetracore
    # /tpl/trilinos//zoltan
    /sierra/stk_tools//stk_transfer_utils_lib
    /sierra/stk_search//stk_search
    /sierra/stk_tools//stk_tools_lib
    /sierra/stk_util//stk_util_command_line
    /sierra/stk_math//stk_math
    /sierra/stk_topology//stk_topology
  :
    <include>$(stk_balance-root-inc)/stk_balance
    [ ifuserbuild <file>$(stk_balance-root)/lib/libstk_balance_lib.a
    ]
    [ ifdevbuild
        # Any parameters within this 'ifdevbuild' block apply to development
        # builds only and will not be present for user builds.
        <toolset>gcc:<cflags>"-Wextra -Wpedantic -Wshadow -Wno-unused-parameter -Wno-implicit-fallthrough"
    ]

  :
  :
  ;

#
# SECTION 4: Build configuration
#

exe stk_balance_unit_tester
  :
    [ glob $(stk_balance-root)/../stk_unit_tests/stk_balance/*.cpp ]
    stk_balance_lib
    /sierra/stk_unit_test_utils//stk_unit_test_utils
    /sierra/stk_unit_test_utils//stk_mesh_fixtures
    /sierra/stk_unit_test_utils//stk_unit_main
    /tpl/trilinos//zoltan2
  :
    <tag>@sierra-exec-tag
  ;

exe stk_balance_doc_tester
  :
    [ glob $(stk_balance-root)/../stk_doc_tests/stk_balance/*.cpp ]
    stk_balance_lib
    /sierra/stk_unit_test_utils//stk_unit_test_utils
    /sierra/stk_unit_test_utils//stk_unit_main
  :
    <tag>@sierra-exec-tag
  ;

exe stk_balance_integration_tester
  :
    [
      glob $(stk_balance-root)/../stk_integration_tests/stk_balance/*.cpp
           $(stk_balance-root)/../stk_integration_tests/test_utils/*.cpp
    ]
    stk_balance_lib
    /sierra/seacas//nemesis
    /sierra/stk_unit_test_utils//stk_unit_main
  :
    <include>$(stk_balance-root-inc)/../stk_integration_tests
    <tag>@sierra-exec-tag
  ;

exe stk_balance
  :
    [ glob 
        $(stk_balance-root)/stk_balance/balance_main/*.cpp
    ]
    stk_balance_lib
    /tpl/operating_system//pthread
  :
    <tag>@sierra-exec-tag
  ;

exe stk_balance_m2n
  :
    [ glob 
        $(stk_balance-root)/stk_balance/m2n_main/*.cpp
    ]
    stk_balance_lib
    /tpl/operating_system//pthread
  :
    <tag>@sierra-exec-tag
  ;

