#------------------------------------------------------------------------
# -*- mode: cmake -*-
#------------------------------------------------------------------------
#
# LDASTools Abstraction Library  - General purpose library
#
# Copyright (C) 2018 California Institute of Technology
#
# LDASTools Abstraction Library  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 Abstraction Library 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
#
#------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.12...4.0)

set( LDAS_TOOLS_AL_SWIG_PACKAGE_NAME ldas-tools-al-swig )
set( LDAS_TOOLS_AL_SWIG_VERSION      2.6.14 )

set(
  PROJECT_DESCRIPTION
  "SWIG bindings for LDAS Tools abstraction library"
  )
set(
  PROJECT_DESCRIPTION_LONG
  "This provides the swig files for the LDAS Tools abstraction interface"
  )

set( LDAS_TOOLS_SWIG_VERSION  3.0.7 )
set( LDAS_TOOLS_CMAKE_VERSION 1.5.0 )
set( LDAS_TOOLS_AL_VERSION    2.10.0 )
set( BOOST_MINIMUM_VERSION    1.67 )

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

if (NOT "${CMAKE_CXX_STANDARD}")
  set(CMAKE_CXX_STANDARD 20)
endif( )
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)

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

project( ${LDAS_TOOLS_AL_SWIG_PACKAGE_NAME}
  VERSION ${LDAS_TOOLS_AL_SWIG_VERSION}
  DESCRIPTION "${PROJECT_DESCRIPTION}"
)

#------------------------------------------------------------------------
# Locate the standard LDAS Tools cmake macro directory
#------------------------------------------------------------------------

include( GNUInstallDirs )

set(LDAS_TOOLS_CMAKE_MODULES_DIRS
  ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/ldas-tools/cmake/Modules
  ${CMAKE_INSTALL_FULL_DATADIR}/ldas-tools/cmake/Modules
  )

find_package(
  LDASToolsCMake
  CONFIG
  REQUIRED
  HINTS ${LDAS_TOOLS_CMAKE_MODULES_DIRS}
  PATHS ${LDAS_TOOLS_CMAKE_MODULES_DIRS}
  )

#========================================================================
# Start pulling in the LDAS Tools macros for easy setup
#========================================================================

find_package(AxLDASTools)

set(PROJECT_BASENAME ldas-tools-al)
cm_init(
  ${LDAS_TOOLS_AL_SWIG_PACKAGE_NAME}
  "${LDAS_TOOLS_AL_SWIG_VERSION}"
  ${LDAS_TOOLS_BUG_REPORT_URL}
  ${LDAS_TOOLS_AL_SWIG_PACKAGE_NAME}
  ${LDAS_TOOLS_HOMEPAGE_URL}
  DESCRIPTION "${PROJECT_DESCRIPTION}"
  )
# Render COPYING, LICENSE.md, debian/copyright from suite-wide templates.
# See ldastools_cmake/Modules/cx_install_license.cmake (issue #267).
cx_install_license( )

set( PROJECT_CONFIG_PATH "${PROJECT_SOURCE_DIR}/config" )

cx_scheme_sanitizer(
  ALLOW_WARNINGS
  ENABLE_ASAN
  ENABLE_USE_AFTER_SCOPE
  DISABLE_RECOVERY_ASAN
  SUPPRESSION_FILE_ASAN ${CMAKE_SOURCE_DIR}/asan_suppressions.txt
  ENABLE_LSAN
  DISABLE_RECOVERY_LSAN
  SUPPRESSION_FILE_LSAN ${CMAKE_SOURCE_DIR}/lsan_suppressions.txt
  ENABLE_MSAN
  DISABLE_RECOVERY_MSAN
  SUPPRESSION_FILE_MSAN ${CMAKE_SOURCE_DIR}/msan_suppressions.txt
  ENABLE_TSAN
  DISABLE_RECOVERY_TSAN
  SUPPRESSION_FILE_TSAN ${CMAKE_SOURCE_DIR}/tsan_suppressions.txt
  ENABLE_UBSAN
  DISABLE_RECOVERY_UBSAN
  SUPPRESSION_FILE_UBSAN ${CMAKE_SOURCE_DIR}/ubsan_suppressions.txt
)

cx_check_compile_hardening( )
cx_cxx_warnings_as_errors( Debug )

#=======================================================================
# Check for key programs
#=======================================================================

cx_pkg_swig(
  REQUIRED
  VERSION ${LDAS_TOOLS_SWIG_VERSION}
  )

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

add_custom_target( doc )

#========================================================================
# Traverse the tree
#========================================================================

add_subdirectory(common)
add_subdirectory(python)

#========================================================================
# Stub for tests since this package doesn't have any
#========================================================================

add_test( NAME DUMMY_TEST COMMAND ${CMAKE_COMMAND} -E echo 'Dummy Test' )

#========================================================================
# Installation of key files
#========================================================================

#========================================================================
# Prepare the distribution
#========================================================================

# Issue #307: distribution-template relocation. See ldastoolsal/CMakeLists.txt
# for the rationale.
set( PROJECT_DEBIAN_CONTROL_INPUT_FILENAME
  "${CMAKE_CURRENT_SOURCE_DIR}/debian/control.in" )

cx_cpack(
  MACPORTS_CATEGORY science
  RPM_SPEC_FILE_TEMPLATE
    "${CMAKE_CURRENT_SOURCE_DIR}/rpm/${PROJECT_NAME}.spec.in"
  SUBPORTS
    py27-${PROJECT_BASENAME}
    py35-${PROJECT_BASENAME}
    py36-${PROJECT_BASENAME}
    py37-${PROJECT_BASENAME}
    py38-${PROJECT_BASENAME}
  )
#========================================================================
# Report configuration information
#  CMAKE_MAKE_PROGRAM:FILEPATH
#========================================================================
cm_msg_notice( "=========================================================" )
cm_msg_notice( " Project ${PROJECT_NAME} has now ben successfully configured:" )
cm_msg_notice( " " )
cm_msg_notice( " Python settings:" )
cm_msg_notice( "      PYTHON3                        ${PYTHON3_EXECUTABLE}" )
cm_msg_notice( "      PYTHON3_VERSION                ${PYTHON3_VERSION}" )
cm_msg_notice( "      PYTHON3_VERSION_NODOTS         ${PYTHON3_VERSION_NODOTS}" )
cm_msg_notice( "      PYTHON3_VERSION_STRING         ${PYTHON3_VERSION_STRING}" )
cm_msg_notice( "      PYTHON3_LIBRARIES              ${PYTHON3_LIBRARIES}" )
cm_msg_notice( "      PYTHON3LIBS_VERSION_STRING     ${PYTHON3LIBS_VERSION_STRING}" )
cm_msg_notice( " " )
cm_msg_notice( " Additional configuration information:" )
cm_msg_notice( "      CMAKE_INSTALL_PREFIX           ${CMAKE_INSTALL_PREFIX}" )
cm_msg_notice( "      CMAKE_PREFIX_PATH              ${CMAKE_PREFIX_PATH}" )
cm_msg_notice( "      LDASTOOLS_FOUND                ${LDASTOOLS_FOUND}" )
cm_msg_notice( "      LDASTOOLS_INCLUDE_DIRS         ${LDASTOOLS_INCLUDE_DIRS}" )
cm_msg_notice( "      LDASTOOLS_LIBRARIES            ${LDASTOOLS_LIBRARIES}" )
cm_msg_notice( "      LDASTOOLS_LIBRARIES_FULL_PATH  ${LDASTOOLS_LIBRARIES_FULL_PATH}" )
cm_msg_notice( "      LDASTOOLS_LINK_LIBRARIES       ${LDASTOOLS_LINK_LIBRARIES}" )
cm_msg_notice( " " )
cm_msg_notice( " installation directories:" )
cm_msg_notice( "      CMAKE_INSTALL_BINDIR           ${CMAKE_INSTALL_BINDIR}" )
cm_msg_notice( "      CMAKE_INSTALL_DATADIR          ${CMAKE_INSTALL_DATADIR}" )
cm_msg_notice( " " )
cm_msg_notice( "  Sanitizers:" )
cm_msg_notice( "      Active:                         ${CX_SCHEME_SANITIZERS_ACTIVE}" )
cm_msg_notice( " " )
cm_msg_notice( "  Now run 'cmake --build .' to build ${PROJECT_NAME}" )
cm_msg_notice( "  and run 'cpack' to package ${PROJECT_NAME}" )
cm_msg_notice( "=========================================================" )
