#
# LDASTools frameCPP - A library implementing the LIGO/Virgo frame specification
#
# Copyright (C) 2020 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 u )

add_subdirectory( impl )
add_subdirectory( VersionRegistry )

#------------------------------------------------------------------------
# 0:0:0 - ldas-tools-framepp-NEXT
#------------------------------------------------------------------------
# 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( libframecpp${FRAME_SPEC}_la_CURRENT 1 )
set( libframecpp${FRAME_SPEC}_la_REVISION 0 )
set( libframecpp${FRAME_SPEC}_la_AGE 0 )

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

#=========================================================================
# Frame Source and Headers
#=========================================================================

set( frame_struct_srcs
	FrameH.cc
  FrSE.cc
  FrSH.cc
  FrAdcData.cc
	FrHeader.cc
  FrDetector.cc
  Dimension.cc
  FrEndOfFile.cc
	FrEndOfFrame.cc
	FrEvent.cc
  FrHistory.cc
  FrMsg.cc
	FrProcData.cc
	FrRawData.cc
	FrSimData.cc
	FrSimEvent.cc
	FrSerData.cc
	FrStatData.cc
	FrSummary.cc
  FrTable.cc
	FrTOC.cc
	FrTOCData.cc
  FrTOCAdcData.cc
  FrTOCEvent.cc
  FrTOCProcData.cc
  FrTOCSerData.cc
  FrTOCSimData.cc
  FrTOCSimEvent.cc
  FrTOCSummary.cc
  FrTOCStatData.cc
  FrVect.cc
  )

set( support_srcs
  StreamRef.cc
  STRING.cc
  PTR_STRUCT.cc
  )

set( support_extra_hdrs
  GPSTime.hh
  )

cx_iterate( REPLACE ".cc" ".hh" frame_struct_hdrs ${frame_struct_srcs} )
cx_iterate( REPLACE ".cc" ".hh" support_hdrs ${support_srcs} )

set( src_hdrs
  ${frame_struct_hdrs}
  ${support_hdrs}
  ${support_extra_hdrs}
  TypeInstantiation.tcc
	FrTOCTypes.hh
  FrVect.tcc
  )
set( SRCS
  ${frame_struct_srcs}
  ${support_srcs}
  )
cx_iterate( REPLACE ".cc" "${FRAME_SPEC}.cc" built_srcs ${SRCS} )

set( EXTRA_DIST ${SRCS} )
set( hh_HEADERS ${src_hdrs} )

set( libframecpp${FRAME_SPEC}_la_LIBADD
  PUBLIC
    framecppcmn
  )

set( nodist_libframecpp${FRAME_SPEC}_la_SOURCES ${built_srcs} ${version_registry_srcs} )

cx_link_headers( ${HDR_DIR} ${hh_HEADERS} )

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

framecpp_create_cc_built_files( "${FRAME_SPEC}.cc" ".cc" ${built_srcs} )

cx_link_headers( ${HDR_DIR} ${hh_HEADERS} )
cx_link_headers( ${HDR_DIR} ${nodist_hh_HEADERS} BUILT_HEADERS )
set( EXTRA_DIST ${SRCS} )

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

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

cx_target_library(
  TARGET framecpp${FRAME_SPEC}
  CURRENT ${libframecpp${FRAME_SPEC}_la_CURRENT}
  REVISION ${libframecpp${FRAME_SPEC}_la_REVISION}
  AGE ${libframecpp${FRAME_SPEC}_la_AGE}
  ${_static_arg}
  SOURCES ${nodist_libframecpp${FRAME_SPEC}_la_SOURCES}
  LIBRARIES ${libframecpp${FRAME_SPEC}_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 Library for Version ${FRAME_SPEC}"
  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${FRAME_SPEC}
  )
