#
# LDASTools frameCPP - A library implementing the LIGO/Virgo frame specification
#
# Copyright (C) 2018 California Institute of Technology
#
# LDASTools frameCPP 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 frameCPP 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
#

set( FRAME_SPEC 9 )

#==========================================================================
# Libraries
#==========================================================================

#------------------------------------------------------------------------
# 2:0:0 -- 2009.12.03
#   In preperation for 1.18.0 release of ldas
#........................................................................
# 3:0:0 -- 2012.02.12 -- RELEASED 1.19.24
#   In preperation for 1.19.21 release of ldas
#........................................................................
# 4:0:1 -- 2012.06.07
#    Added FrameLibraryName() to IFrameStreamWrapper< DECL_PARAMS>
#........................................................................
# 5:0:0 -- 2013.07.01
#    Many changes
# 5:1:0 -- 2013.08.29 (post 1.19.33)
#    Modifications for static building
# 6:0:0 -- 2015.05.08
#    Changes to lower level libraries
# 7:0:0 - 2016.10.10
#    Changes to lower level libraries
# 8:0:0 - 2017.02.13
#    Changed for FrEvent reading
# 9:0:0 - 2017.08.25
#    Extended FrameH interface
# 10:0:0 - 2018.05.11 ( ldas-tools-framecpp-2.6.0 )
#    Removed hand rolled smart pointers in favor of boost smart pointers
# 11:0:1 - ldas-tools-framecpp-2.6.3
#    Added FrEndOfFile::NFrames()
#    Added FrTOC::runs()
# 12:0:0 - ldas-tools-framecpp-2.6.5
#    Change signature of IFrameStream::GetTOC()
# 12:1:0 - ldas-tools-framecpp-2.7.0
#    Updated doxygen
# 13:0:0 - ldas-tools-framecpp-2.7.2
#    Updated because of libframecpp8 changes
# 14:0:1 - ldas-tools-framecpp-2.8.2
#    Updated because of libframecpp8 changes
# 15:0:0 - ldas-tools-framecpp-2.9.0
#    Updated because of libframecpp8 changes
# 16:0:0 - ldas-tools-framecpp-3.0.0
#    Version 9 frame specification implementation
# 16:1:0 - ldas-tools-framecpp-3.0.1
#    Correction to Types.hh (issue #158)
# 17:0:1 - ldas-tools-framecpp-3.0.2
#    Added method GetNDAtaValid()
# 18:0:2 - ldas-tools-framecpp-3.0.4
#------------------------------------------------------------------------
# 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 release (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 release 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( libframecpp_la_CURRENT 18 )
set( libframecpp_la_REVISION 0 )
set( libframecpp_la_AGE 2 )

set( HDR_DIR framecpp )
set( hhdir  ${CMAKE_INSTALL_INCLUDEDIR}/${HDR_DIR} )

#=========================================================================
# General files
#=========================================================================

#=========================================================================
# Generic interface
#=========================================================================

set( built_hdrs
	FrameStream.hh
 )

set( INTERFACE_HDRS
	FrameCPP.hh
  FrameDebugPrint.hh
  FrameCPPDebugManager.hh
  FrameFileInfo.hh
	GPSTime.hh
	IFrameStream.hh
	IFrameStreamPlan.hh
	FrameStreamPlan.hh
	OFrameStream.hh
	STRING.hh
	Time.hh
	Types.hh
  FrSE.hh
  FrSH.hh
	FrameH.hh
  FrHeader.hh
	FrAdcData.hh
	FrDetector.hh
  Dimension.hh
  FrEndOfFile.hh
  FrEndOfFrame.hh
	FrEvent.hh
  FrHistory.hh
  FrMsg.hh
	FrProcData.hh
	FrRawData.hh
	FrSerData.hh
	FrSimData.hh
	FrSimEvent.hh
	FrStatData.hh
	FrSummary.hh
	FrTable.hh
	FrTOC.hh
  FrVect.hh
  )

set( INTERFACE_SRCS
	FrameCPP.cc
  FrameDebugPrint.cc
  FrameCPPDebugManager.cc
  FrameFileInfo.cc
  )

set( non_built_hdrs
	${INTERFACE_HDRS}
  )

list( APPEND libframecpp_la_SOURCES  ${INTERFACE_SRCS} )
list( APPEND hh_HEADERS  ${INTERFACE_HDRS} )
set( nodist_hh_HEADERS ${built_hdrs} )


#==========================================================================
# Documentation
#==========================================================================

list( APPEND EXTRA_DIST 
	CPlusPlusInterface.txt
  )

#=========================================================================
# Generic Rules
#=========================================================================
#=========================================================================
# Build the library
#=========================================================================

set( libframecpp_la_LIBADD
	framecppu
  ${LIBZ}
  ${LIBZSTD}
  )

#if HAVE_LIBZ
#libframecpp_la_LIBADD += -lz
#endif

#=========================================================================
#
#=========================================================================

cx_link_headers( ${HDR_DIR} ${hh_HEADERS} )
cx_link_headers( ${HDR_DIR} ${nodist_hh_HEADERS} BUILT_HEADERS )

framecpp_interface_hdr_builder(
  VERSION ${FRAME_SPEC}
  HEADERS ${built_hdrs}
  )

cx_target_library(
  TARGET framecpp
  CURRENT ${libframecpp_la_CURRENT}
  REVISION ${libframecpp_la_REVISION}
  AGE ${libframecpp_la_AGE}
  STATIC
  SOURCES ${libframecpp_la_SOURCES}
  LIBRARIES ${libframecpp_la_LIBADD}
  INCLUDE_DIRECTORIES BEFORE PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_SOURCE_DIR}/src
    ${CMAKE_BINARY_DIR}/include
    ${CMAKE_BINARY_DIR}
    ${LDASTOOLS_INCLUDE_DIRS}
  ABI_MESSAGE "FrameCPP C++ Library"
  ABI_HEADER_DIR ${HDR_DIR}
  ABI_LOCAL_INCLUDE_DIR ${CMAKE_BINARY_DIR}/include/${HDR_DIR}
  ABI_HEADERS
  ${hh_HEADERS}
  )

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

cx_install_header(
  FILES ${hh_HEADERS}
  DESTINATION "${hhdir}"
  )
cx_install_header(
  FILES ${nodist_hh_HEADERS}
  DESTINATION "${hhdir}"
  WORKINGDIR ${CMAKE_CURRENT_BINARY_DIR}
  )
cx_target_pkgconfig(
  framecpp
  )

#------------------------------------------------------------------------
# Testing
#------------------------------------------------------------------------

cx_target_gtest(
  test_frprocdata
  INCLUDES
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_SOURCE_DIR}/src
  ${CMAKE_BINARY_DIR}/include
  ${CMAKE_BINARY_DIR}
  ${LDASTOOLS_INCLUDE_DIRS}
  ${Boost_INCLUDE_DIRS}
  ${GTEST_INCLUDE_DIRS}
  SOURCES
  FrProcData_test.cc
  DEPENDENCIES
  framecpp
  LDADD
  PUBLIC framecpp
  PUBLIC Boost::serialization
  PUBLIC Boost::system
  PUBLIC ${GTEST_LIBRARIES}
  PRIVATE Threads::Threads
  )

cx_target_gtest(
  test_serialization
  INCLUDES
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_SOURCE_DIR}/src
    ${CMAKE_BINARY_DIR}/include
    ${CMAKE_BINARY_DIR}
    ${LDASTOOLS_INCLUDE_DIRS}
    ${Boost_INCLUDE_DIRS}
    ${GTEST_INCLUDE_DIRS}
  SOURCES
    serialization_test.cc
  EXTRA_GTEST_SOURCES
    FrSE_test.cc
    FrSH_test.cc
    FrDetector_test.cc
    FrEndOfFile_test.cc
    FrEndOfFrame_test.cc
    FrEvent_test.cc
    FrHistory_test.cc
    FrMsg_test.cc
    FrVect_test.cc
    FrTable_test.cc
    FrProcData_serialization_test.cc
    FrAdcData_test.cc
    FrRawData_test.cc
    FrSerData_test.cc
    FrSimData_test.cc
    FrSimEvent_test.cc
    FrSummary_test.cc
    FrameH_test.cc
    FrTOC_test.cc
  DEPENDENCIES
    framecpp
  LDADD
    PUBLIC framecpp
    PUBLIC Boost::serialization
    PUBLIC Boost::system
    PUBLIC ${GTEST_LIBRARIES}
    PRIVATE Threads::Threads
)

cx_target_gtest(
  test_serialization_advanced
  INCLUDES
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_SOURCE_DIR}/src
    ${CMAKE_BINARY_DIR}/include
    ${CMAKE_BINARY_DIR}
    ${LDASTOOLS_INCLUDE_DIRS}
    ${Boost_INCLUDE_DIRS}
    ${GTEST_INCLUDE_DIRS}
  SOURCES
    serialization_advanced_test.cc
  DEPENDENCIES
    framecpp
  LDADD
    PUBLIC framecpp
    PUBLIC Boost::serialization
    PUBLIC Boost::system
    PUBLIC ${GTEST_LIBRARIES}
    PRIVATE Threads::Threads
)

cx_target_gtest(
  test_serialization_mime
  INCLUDES
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_SOURCE_DIR}/src
    ${CMAKE_BINARY_DIR}/include
    ${CMAKE_BINARY_DIR}
    ${LDASTOOLS_INCLUDE_DIRS}
    ${Boost_INCLUDE_DIRS}
    ${GTEST_INCLUDE_DIRS}
  SOURCES
    serialization_mime_test.cc
  DEPENDENCIES
    framecpp
  LDADD
    PUBLIC framecpp
    PUBLIC Boost::serialization
    PUBLIC Boost::system
    PUBLIC ${GTEST_LIBRARIES}
    PRIVATE Threads::Threads
)
