#
# LDASTools Generic API - A library of general use algorithms for LDASTools Suite
#
# Copyright (C) 2018 California Institute of Technology
#
# LDASTools Generic API is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 (GPLv2) of the
# License or at your discretion, any later version.
#
# LDASTools Generic API is distributed in the hope that it will be useful, but
# without any warranty or even the implied warranty of merchantability
# or fitness for a particular purpose. See the GNU General Public
# License (GPLv2) for more details.
#
# Neither the names of the California Institute of Technology (Caltech),
# The Massachusetts Institute of Technology (M.I.T), The Laser
# Interferometer Gravitational-Wave Observatory (LIGO), nor the names
# of its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# You should have received a copy of the licensing terms for this
# software included in the file LICENSE located in the top-level
# directory of this package. If you did not, you can view a copy at
# http://dcc.ligo.org/M1500244/LICENSE
#

#------------------------------------------------------------------------
# Variable definitions
#------------------------------------------------------------------------

function( ldasgen_target_test target )
  set(options
    )
  set(oneValueArgs
    )
  set(multiValueArgs
    SOURCES
    LDADD
    COMMAND_ARGS
    )

  cmake_parse_arguments( ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

  if ( NOT ARG_LDADD )
    set( ARG_LDADD ${LDADD} )
  endif( )
  if ( NOT ARG_INCLUDES )
    set( ARG_INCLUDES ${AM_CPPFLAGS} )
  endif( )

  cx_target_executable(
    ${target}
    NOINST
    SOURCES ${ARG_SOURCES}
    LDADD ${ARG_LDADD}
    INCLUDE_DIRECTORIES BEFORE PRIVATE
    ${ARG_INCLUDES}
    )
  add_dependencies( ${target} ldasgen )
  cx_target_test( ${target}
    COMMAND ${target} ${ARG_COMMAND_ARGS}
    ENVIRONMENT ${TESTS_ENVIRONMENT}
    )
endfunction( )

#........................................................................
# tChannelName
#........................................................................

set( tChannelName_SOURCES
	tChannelName.cc
  )

set( tChannelName_LDADD
	Stat
	ldasgen
  )

cx_target_executable(
  tChannelName
  NOINST
  SOURCES ${tChannelName_SOURCES}
  LDADD ${tChannelName_LDADD}
  INCLUDE_DIRECTORIES BEFORE PRIVATE
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_BINARY_DIR}/include
  ${CMAKE_SOURCE_DIR}/src
  ${CMAKE_BINARY_DIR}
  ${LDASTOOLS_INCLUDE_DIRS}
  )

cx_target_test( tChannelName
  COMMAND tChannelName
  ENVIRONMENT
  ABS_BUILDDIR=${CMAKE_CURRENT_BINARY_DIR}
  )

#........................................................................
# tlstat
#........................................................................

set( tlstat_SOURCES
	tlstat.cc
  )

set( tlstat_LDADD
	Stat
	ldasgen
  )

cx_target_executable(
  tlstat
  NOINST
  SOURCES ${tlstat_SOURCES}
  LDADD ${tlstat_LDADD}
  INCLUDE_DIRECTORIES BEFORE PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_BINARY_DIR}/include
    ${CMAKE_SOURCE_DIR}/src
    ${CMAKE_BINARY_DIR}
    ${LDASTOOLS_INCLUDE_DIRS}
  )

cx_target_test( tlstat
  COMMAND tlstat
  ENVIRONMENT
  ABS_BUILDDIR=${CMAKE_CURRENT_BINARY_DIR}
  )

#........................................................................
# tMountPointStatus
#........................................................................

set( tMountPointStatus_SOURCES
	tMountPointStatus.cc
  )

set( tMountPointStatus_LDADD
	ldasgen
  )

cx_target_executable(
  tMountPointStatus
  NOINST
  SOURCES ${tMountPointStatus_SOURCES}
  LDADD ${tMountPointStatus_LDADD}
  INCLUDE_DIRECTORIES BEFORE PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_BINARY_DIR}/include
    ${CMAKE_SOURCE_DIR}/src
    ${CMAKE_BINARY_DIR}
    ${LDASTOOLS_INCLUDE_DIRS}
  )

cx_target_test( tMountPointStatus COMMAND tMountPointStatus )

#........................................................................
# test_TCL
#........................................................................

set( test_TCL_SOURCES
  test_TCL.cc
)

set( test_TCL_LDADD
  ldasgen
)

ldasgen_target_test( test_TCL
  NOINST
  SOURCES ${test_TCL_SOURCES}
  LDADD ${test_TCL_LDADD}
  INCLUDE_DIRECTORIES BEFORE PRIVATE
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_BINARY_DIR}/include
  ${CMAKE_SOURCE_DIR}/src
  ${CMAKE_BINARY_DIR}
  ${LDASTOOLS_INCLUDE_DIRS}
)

#------------------------------------------------------------------------

cx_scheme_sanitizer_set_environment( )
