######################################################################
#
# sciFuncsMacros: Various functions and macros used by Tech-X CMake
#
# $Id: sciFuncsMacros.cmake 1245 2012-01-31 21:36:22Z dws $
#
# Copyright 2010-2012 Tech-X Corporation.
# Arbitrary redistribution allowed provided this copyright remains.
#
######################################################################

#
# sciPrintString: print a string in a status message as well as to
#   ${CONFIG_SUMMARY}
# Args:
#   str the string
#
macro(sciPrintString str)
  message(STATUS "${str}")
  if (DEFINED CONFIG_SUMMARY)
    file(APPEND "${CONFIG_SUMMARY}" "${str}\n")
  else ()
    message(WARNING "Variable CONFIG_SUMMARY is not defined, sciPrintString is unable to write to the summary file.")
  endif ()
endmacro()

#
# sciPrintVar: print a variable with standard formatting
# Args:
#   var the name of the variable
#
macro(sciPrintvar var)
  string(LENGTH "${var}" lens)
  math(EXPR lenb "35 - ${lens}")
  if (lenb GREATER 0)
    string(RANDOM LENGTH ${lenb} ALPHABET " " blstr)
  else ()
    set(blstr "")
  endif ()
  sciPrintString("  ${var}${blstr}= ${${var}}")
endmacro()

#
# Print all cmake variables generated by SciFindPackage
# Args:
#   pkg: the name of the package
#
macro(sciPrintCMakeResults pkg)
  # message("--------- RESULTS FOR ${pkg} ---------")
  sciPrintString("")
  sciPrintString("RESULTS FOR ${pkg}:")
  foreach (varsfx DIR EXECUTABLES FILES INCLUDE_DIRS MODULE_DIRS LIBFLAGS LIBRARY_DIRS LIBRARY_NAMES LIBRARIES STLIBS)
    sciPrintVar(${pkg}_${varsfx})
  endforeach ()
  if (WIN32)
    sciPrintVar(${pkg}_DLLS)
  endif ()
endmacro()

#
# Print all autotools variables generated by SciFindPackage
# Args:
#   pkg: the name of the package
#
macro(sciPrintAutotoolsResults pkg)
  # message("--------- RESULTS FOR ${pkg} ---------")
  sciPrintString("")
  sciPrintString("RESULTS FOR ${pkg}:")
  foreach (varsfx DIR INCDIRS MODDIRS LIBS ALIBS)
    sciPrintVar(${pkg}_${varsfx})
  endforeach ()
  if (WIN32)
    sciPrintVar(${pkg}_DLLS)
  endif ()
endmacro()

