################################################################################
##
## Copyright (c) 2016 Advanced Micro Devices, Inc. All rights reserved.
##
## MIT LICENSE:
## Permission is hereby granted, free of charge, to any person obtaining a copy of
## this software and associated documentation files (the "Software"), to deal in
## the Software without restriction, including without limitation the rights to
## use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
## of the Software, and to permit persons to whom the Software is furnished to do
## so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in all
## copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
################################################################################

cmake_minimum_required ( VERSION 3.5.0 )

set ( HSAKMT_DEV_PACKAGE "hsakmt-roct-dev" )

project ( ${HSAKMT_DEV_PACKAGE} )

include ( GNUInstallDirs )

## Set the runtime package name.
set ( HSAKMT_PACKAGE @HSAKMT_PACKAGE@ )

## Setup the package version.
set ( BUILD_VERSION_MAJOR @BUILD_VERSION_MAJOR@ )
set ( BUILD_VERSION_MINOR @BUILD_VERSION_MINOR@ )
set ( BUILD_VERSION_PATCH @BUILD_VERSION_PATCH@ )

## Verbose output.
set ( CMAKE_VERBOSE_MAKEFILE on )

## Set the install targets
install ( FILES libhsakmt.pc DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pkgconfig )
install ( DIRECTORY ${SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${HSAKMT_COMPONENT} PATTERN "linux" EXCLUDE )


## Set the default generator types for the devel package.
set ( CPACK_GENERATOR "DEB;RPM;TGZ"  CACHE STRING "Default packaging generators." )

## Packaging directives
set ( CPACK_PACKAGE_NAME ${HSAKMT_DEV_PACKAGE} )
set ( CPACK_PACKAGE_VENDOR "AMD" )
set ( CPACK_PACKAGE_VERSION_MAJOR ${BUILD_VERSION_MAJOR} )
set ( CPACK_PACKAGE_VERSION_MINOR ${BUILD_VERSION_MINOR} )
set ( CPACK_PACKAGE_VERSION_PATCH ${BUILD_VERSION_PATCH} )
set ( CPACK_PACKAGE_CONTACT "Advanced Micro Devices Inc." )
set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "HSAKMT development package." )
set ( CPACK_RESOURCE_FILE_LICENSE "${SOURCE_DIR}/LICENSE.md" )

# Debian package specific variables
set ( CPACK_DEBIAN_PACKAGE_DEPENDS "${HSAKMT_PACKAGE} (=${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH})" )
set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/RadeonOpenCompute/ROCT-Thunk-Interface" )

# RPM package specific variables
set ( CPACK_RPM_PACKAGE_DEPENDS "${HSAKMT_PACKAGE} = ${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}" )

# Create cmake configuration files
include(CMakePackageConfigHelpers)

set(HSAKMT_LIBRARY_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})

set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} CACHE INTERNAL "")
set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE INTERNAL "")

configure_package_config_file(${SOURCE_DIR}/${HSAKMT_BIN_NAME}-config.cmake.in
                              ${CMAKE_CURRENT_BINARY_DIR}/${HSAKMT_BIN_NAME}-config.cmake
                              PATH_VARS
                                  INCLUDE_INSTALL_DIR LIB_INSTALL_DIR
                              INSTALL_DESTINATION
                                  ${CMAKE_INSTALL_LIBDIR}/cmake/${HSAKMT_BIN_NAME})

write_basic_package_version_file(${HSAKMT_BIN_NAME}-config-version.cmake
				 VERSION ${VERSION}
                                 COMPATIBILITY
                                     AnyNewerVersion)

install(FILES
            ${CMAKE_CURRENT_BINARY_DIR}/${HSAKMT_BIN_NAME}-config.cmake
            ${CMAKE_CURRENT_BINARY_DIR}/${HSAKMT_BIN_NAME}-config-version.cmake
        DESTINATION
            ${CMAKE_INSTALL_LIBDIR}/cmake/${HSAKMT_BIN_NAME}
        COMPONENT
            devel)

include ( CPack )
