#[[
CMake build script for ACM Collected Algorithms: DCUHRE and DQUAD
Copyright (C) 2022  Tim Haase

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this program.  If not, see
<https://www.gnu.org/licenses/>.
]]

include(CMakePackageConfigHelpers)

if (NOT DEFINED CalgoIntegrators_INSTALL_CMAKEDIR)
    set(CalgoIntegrators_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
        CACHE STRING "Path to Calgo Integrators CMake files")
endif ()

target_include_directories(DCUHRE PUBLIC
    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

target_include_directories(DQUAD PUBLIC
    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

if (BUILD_SHARED_LIBS)
    set(type shared)
else ()
    set(type static)
endif ()

install(
    TARGETS DCUHRE
    EXPORT CalgoIntegrators_DCUHRE_Targets
    LIBRARY COMPONENT dcuhre
    NAMELINK_COMPONENT dcuhre
    ARCHIVE COMPONENT dcuhre
    FILE_SET HEADERS COMPONENT dcuhre
    DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

install(
    EXPORT CalgoIntegrators_DCUHRE_Targets
    DESTINATION "${CalgoIntegrators_INSTALL_CMAKEDIR}"
    FILE CalgoIntegrators_DCUHRE_Targets-${type}.cmake
    NAMESPACE Netlib::
    COMPONENT dcuhre
)

install(
    TARGETS DQUAD
    EXPORT CalgoIntegrators_DQUAD_Targets
    LIBRARY COMPONENT dquad
    NAMELINK_COMPONENT dquad
    ARCHIVE COMPONENT dquad
    FILE_SET HEADERS COMPONENT dquad
    DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

install(
    EXPORT CalgoIntegrators_DQUAD_Targets
    DESTINATION "${CalgoIntegrators_INSTALL_CMAKEDIR}"
    FILE CalgoIntegrators_DQUAD_Targets-${type}.cmake
    NAMESPACE Netlib::
    COMPONENT dquad
)

install(
    FILES
    "../3rdparty/ACM Software License Agreement.txt"
    RENAME copyright
    DESTINATION "${CMAKE_INSTALL_DOCDIR}"
    COMPONENT dcuhre
)

install(
    FILES
    "../3rdparty/ACM Software License Agreement.txt"
    RENAME copyright
    DESTINATION "${CMAKE_INSTALL_DOCDIR}"
    COMPONENT dquad
)

write_basic_package_version_file(
    CalgoIntegratorsConfigVersion.cmake
    COMPATIBILITY SameMajorVersion
)

if (NOT LoadStaticSharedTargets_FOUND)
    set(LoadStaticSharedTargets_DIR "${LoadStaticSharedTargets_INSTALL_CMAKEDIR}")
endif ()

if (NOT NetlibF2C_FOUND)
    set(NetlibF2C_DIR "${NetlibF2C_INSTALL_CMAKEDIR}")
endif ()

configure_file(
    "CalgoIntegratorsConfig.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/CalgoIntegratorsConfig.cmake"
    @ONLY
)

if (NOT LoadStaticSharedTargets_FOUND)
    unset(LoadStaticSharedTargets_DIR)
endif ()

if (NOT NetlibF2C_FOUND)
    unset(NetlibF2C_DIR)
endif ()

install(
    FILES
    "${CMAKE_CURRENT_BINARY_DIR}/CalgoIntegratorsConfigVersion.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/CalgoIntegratorsConfig.cmake"
    DESTINATION "${CalgoIntegrators_INSTALL_CMAKEDIR}"
    COMPONENT dcuhre
)

install(
    FILES
    "${CMAKE_CURRENT_BINARY_DIR}/CalgoIntegratorsConfigVersion.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/CalgoIntegratorsConfig.cmake"
    DESTINATION "${CalgoIntegrators_INSTALL_CMAKEDIR}"
    COMPONENT dquad
)
