#
# 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
#
# -*-mode: makefile;-*-
#------------------------------------------------------------------------
# Standard compiler flags
#------------------------------------------------------------------------

#========================================================================
# Construction of libraries
#========================================================================

#------------------------------------------------------------------------
# 2:0:0 -- 2010.01.25
#   In preperation for 1.18.0 release of ldas
# 3:0:1 -- 2015.05.08
#   Modified Logging code.
#   Added Daemon class
# 3:1:1 -- 2015.07.06
#   Use new SignalHandler class
# 3:2:1 -- 2016.09.26
#   Expanded information reported for failed stat and lstat calls
# 3:3:1 -- 2016.10.10
#   Made it so daemon servers can reconnect to socket upon restarts.
#   Fixed some minor issues with outputing of logging messages
#   Update to support Debian Sketch
# 3:4:1 - 2017.11.06 (ldas-tools-ldasgen-2.5.5)
#   Corrections for GCC 7.2.0 and XCode 9.0
# 4:0:0 - 2018.05.11 ( ldas-tools-ldasgen-2.6.0 )
#   Removed hand rolled smart pointers in favor of boost smart pointers
# 5:0:0 - 2019.08.14
#   Removed close() from socket stream.
#   Removed IsLogging( int, int, std::string const& ) from Logging.
#   Removed LogFileDefault() from Logging.
# 5:1:0 - NEXT
#   Set default logging debug level
#------------------------------------------------------------------------
# form: <(c)urrent>:<(r)elease>:<(a)ge
#
# 1. Update the version information only immediately before a public
#    release of your software. More frequent updates are unnecessary,
#    and only guarantee that the current interface number gets larger
#    faster.
# 2. If the library source code has changed at all since the last
#    update, then increment revision (c:r:a becomes c:r+1:a).
# 3. If any interfaces [exported functions or data] have been added,
#    removed, or changed since the last update, increment current,
#    and set revision to 0.
# 4. If any interfaces have been added since the last public
#    release, then increment age.
# 5. If any interfaces have been removed since the last public
#    release, then set age to 0.
#------------------------------------------------------------------------

set( libldasgen_la_CURRENT 5 )
set( libldasgen_la_REVISION 2 )
set( libldasgen_la_AGE 0 )

#------------------------------------------------------------------------
# => 2:0:0 -- 2010.01.25
#   In preperation for 1.18.0 release of ldas
# 2:1:0 -- 2016.09.09
#   Increased default line rotation count to 10000
# 2:2:0 -- 2016.09.26
#   Expanded information reported for failed stat and lstat calls
# 2:3:0 - 2017.11.06 (ldas-tools-ldasgen-2.5.5)
#   Corrections for GCC 7.2.0 and XCode 9.0
# 3:0:0 - 2019.08.14
#   Removed stat( char const*, struct stat* ) from Stat.
#------------------------------------------------------------------------

set( libStat_la_CURRENT 3 )
set( libStat_la_REVISION 1 )
set( libStat_la_AGE 0 )

#------------------------------------------------------------------------
# Header
#------------------------------------------------------------------------

set( HHDIR genericAPI )
set( ldasgenhhdir ${CMAKE_INSTALL_INCLUDEDIR}/${HHDIR} )
set( ldasgenhh_HEADERS
	ChannelNameLexer.hh
	Daemon.hh
	file.hh
	FileLock.hh
	inputfile.hh
	LDASplatform.hh
	Logging.hh
	LogLDAS.hh
	LogHTML.hh
	LogText.hh
	MonitorMemory.hh
	MountPointStatus.hh
	outputfile.hh
	SocketStream.hh
	Stat.hh
	Status.hh
	StatBase.hh
	StatFork.hh
	StatDirect.hh
	StatPool.hh
	StatPoolT.hh
	StatStream.hh
	StatVFS.hh
	swigexception.hh
	Symbols.hh
	SymbolMapper.hh
	SymbolMapperTCL.hh
  swigexception.hh
	TCL.hh
  )

cx_link_headers( ${HHDIR} ${ldasgenhh_HEADERS} )
install(
  FILES ${ldasgenhh_HEADERS}
  DESTINATION "${ldasgenhhdir}"
  )

#------------------------------------------------------------------------
# Aux programs
#------------------------------------------------------------------------

set( ldaslibexecdir ${CMAKE_INSTALL_LIBEXECDIR}/ldas )

#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

set( libChannelName_la_SOURCES
	ChannelNameLexer.cc
  )

set( libChannelName_la_CXXFLAGS
  HAVE_CONFIG_H=1
  CORE_API=1
  )

cx_target_library(
  TARGET ChannelName
  CONVENIENCE
  DEFINES ${libChannelName_la_CXXFLAGS}
  SOURCES ${libChannelName_la_SOURCES}
  INCLUDE_DIRECTORIES BEFORE PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_BINARY_DIR}/include
    ${CMAKE_BINARY_DIR}
    ${LDASTOOLS_INCLUDE_DIRS}
    )

# add_dependencies( ChannelName ChannelScanner )

#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set( libSymbols_la_SOURCES
	SymbolMapper.cc
	Symbols.cc
  )

set( libSymbols_la_CXXFLAGS
  HAVE_CONFIG_H=1
  )

cx_target_library(
  TARGET Symbols
  CONVENIENCE
  DEFINES ${libSymbols_la_CXXFLAGS}
  SOURCES ${libSymbols_la_SOURCES}
  INCLUDE_DIRECTORIES BEFORE PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_BINARY_DIR}/include
    ${CMAKE_BINARY_DIR}
    ${LDASTOOLS_INCLUDE_DIRS}
    )

#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set( libldasgen_la_SOURCES
	Daemon.cc
	file.cc
	FileLock.cc
	inputfile.cc
	LDASplatform.cc
	Logging.cc
	LogHTML.cc
	LogLDAS.cc
	LogText.cc
	MonitorMemory.cc
	MountPointStatus.cc
	outputfile.cc
	Stat.cc
	StatBase.cc
	StatDirect.cc
	StatFork.cc
	StatPool.cc
	StatStream.cc
	StatVFS.cc
	Status.cc
	swigexception.cc
	TCL.cc
  )

set( libldasgen_la_CXXFLAGS
  HAVE_CONFIG_H=1
	CORE_API=1
  )

set( libldasgen_la_LIBADD
  ChannelName
  ${LDASTOOLS_LIBRARIES_FULL_PATH}
  Threads::Threads
  )

# Build static library only if BUILD_STATIC_LIBS is ON
cx_static_libs_arg(_static_arg)

cx_target_library(
  TARGET ldasgen
  CURRENT ${libldasgen_la_CURRENT}
  REVISION ${libldasgen_la_REVISION}
  AGE ${libldasgen_la_AGE}
  ${_static_arg}
  DEFINES ${libldasgen_la_CXXFLAGS}
  SOURCES ${libldasgen_la_SOURCES}
  LIBRARIES ${libldasgen_la_LIBADD}
  PKG_CONFIG_FILE ldastools-ldasgen.pc.in
  INCLUDE_DIRECTORIES BEFORE PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_BINARY_DIR}/include
    ${CMAKE_BINARY_DIR}
    ${LDASTOOLS_INCLUDE_DIRS}
  ABI_MESSAGE "LDAS Generic Library"
  ABI_HEADER_DIR ${HHDIR}
  ABI_LOCAL_INCLUDE_DIR ${CMAKE_BINARY_DIR}/include/${HHDIR}
  ABI_HEADERS ${ldasgenhh_HEADERS}
  )



#=========================================================================
# Do not install these headers
#=========================================================================

#------------------------------------------------------------------------
# Building of the aux. programs
#------------------------------------------------------------------------

set( lstat_SOURCES
	lstat.cc )

set( lstat_LDADD
  Threads::Threads
  )

cx_target_executable( lstat
  SOURCES ${lstat_SOURCES}
  LDADD ${lstat_LDADD}
  INSTALL_DIR ${ldaslibexecdir}
  INCLUDE_DIRECTORIES BEFORE PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_BINARY_DIR}/include
    ${CMAKE_BINARY_DIR}
    ${LDASTOOLS_INCLUDE_DIRS}
  )

#------------------------------------------------------------------------
# Building of libStat
#------------------------------------------------------------------------

set( libStat_la_LIBADD
	ldasgen )

set( libStat_la_SOURCES
	MountPointStatus.cc
	Stat.cc
	StatBase.cc
	StatDirect.cc
	StatFork.cc
	StatPool.cc
	StatStream.cc
	StatVFS.cc
  )

set( libStat_la_LDFLAGS
	${STAT_LIBTOOL_VERSION_FLAG}
	${libStat_la_DEPENDENCIES} )

# Build static library only if BUILD_STATIC_LIBS is ON
cx_static_libs_arg(_static_arg_stat)

cx_target_library(
  TARGET Stat
  CURRENT ${libStat_la_CURRENT}
  REVISION ${libStat_la_REVISION}
  AGE ${libStat_la_AGE}
  ${_static_arg_stat}
  DEFINES ${libStat_la_CXXFLAGS}
  SOURCES ${libStat_la_SOURCES}
  LIBRARIES ${libStat_la_LIBADD}
  PKG_CONFIG_FILE ldastools-stat.pc.in
  INCLUDE_DIRECTORIES BEFORE PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_BINARY_DIR}/include
    ${CMAKE_BINARY_DIR}
    ${LDASTOOLS_INCLUDE_DIRS}
  ABI_MESSAGE "LDAS Stat File Library"
  ABI_HEADER_DIR ${HHDIR}
  ABI_LOCAL_INCLUDE_DIR ${CMAKE_BINARY_DIR}/include/${HHDIR}
  ABI_HEADERS ${ldasgenhh_HEADERS}
  )
