cmake_minimum_required(VERSION 3.6.3)
project(hipify-clang)

set(CMAKE_INSTALL_PREFIX @CMAKE_INSTALL_PREFIX@)
install(PROGRAMS @HIPIFY_BIN_INSTALL_PATH@/hipify-clang DESTINATION @CMAKE_INSTALL_BINDIR@)
install(PROGRAMS @HIPIFY_BIN_INSTALL_PATH@/hipify-perl DESTINATION @CMAKE_INSTALL_BINDIR@)
install(PROGRAMS @HIPIFY_LIBEXEC_INSTALL_PATH@/hipify-perl DESTINATION @CMAKE_INSTALL_LIBEXECDIR@/hipify)
install(PROGRAMS @HIPIFY_LIBEXEC_INSTALL_PATH@/findcode.sh DESTINATION @CMAKE_INSTALL_LIBEXECDIR@/hipify)
install(PROGRAMS @HIPIFY_LIBEXEC_INSTALL_PATH@/findcode_headers.sh DESTINATION @CMAKE_INSTALL_LIBEXECDIR@/hipify)
install(PROGRAMS @HIPIFY_LIBEXEC_INSTALL_PATH@/findcode_sources.sh DESTINATION @CMAKE_INSTALL_LIBEXECDIR@/hipify)
install(PROGRAMS @HIPIFY_LIBEXEC_INSTALL_PATH@/findcode_custom.sh DESTINATION @CMAKE_INSTALL_LIBEXECDIR@/hipify)
install(PROGRAMS @HIPIFY_LIBEXEC_INSTALL_PATH@/finduncodep.sh DESTINATION @CMAKE_INSTALL_LIBEXECDIR@/hipify)
install(PROGRAMS @HIPIFY_LIBEXEC_INSTALL_PATH@/hipconvertinplace-perl.sh DESTINATION @CMAKE_INSTALL_LIBEXECDIR@/hipify)
install(PROGRAMS @HIPIFY_LIBEXEC_INSTALL_PATH@/hipconvertinplace.sh DESTINATION @CMAKE_INSTALL_LIBEXECDIR@/hipify)
install(PROGRAMS @HIPIFY_LIBEXEC_INSTALL_PATH@/hipexamine-perl.sh DESTINATION @CMAKE_INSTALL_LIBEXECDIR@/hipify)
install(PROGRAMS @HIPIFY_LIBEXEC_INSTALL_PATH@/hipexamine.sh DESTINATION @CMAKE_INSTALL_LIBEXECDIR@/hipify)
if(@HIPIFY_INSTALL_CLANG_HEADERS@)
  install(DIRECTORY @CMAKE_INSTALL_PREFIX@/include/ DESTINATION @CMAKE_INSTALL_INCLUDEDIR@)
endif()
# hipify-clang.txt is processed to produce CMakeList.txt,
# pass down value from parent
set (ROCM_DEP_ROCMCORE "@ROCM_DEP_ROCMCORE@")

#############################
# Packaging steps
#############################
set(CPACK_PACKAGE_NAME @PROJECT_NAME@)
set(CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc.")
set(CPACK_PACKAGE_VERSION_MAJOR @LLVM_VERSION_MAJOR@)
set(CPACK_PACKAGE_VERSION_MINOR @LLVM_VERSION_MINOR@)
set(CPACK_PACKAGE_VERSION_PATCH @LLVM_VERSION_PATCH@)
set(CPACK_PACKAGE_CONTACT "ROCm Compiler Support <rocm.compiler.support@amd.com>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Hipify CUDA source")
set(CPACK_PACKAGE_DESCRIPTION "This tool translates CUDA source code into portable HIP C++ automatically")
set(CPACK_SET_DESTDIR @CPACK_SET_DESTDIR@)
set(CPACK_INSTALL_PREFIX @CPACK_PACKAGING_INSTALL_PREFIX@)
set(CPACK_PACKAGING_INSTALL_PREFIX @CPACK_PACKAGING_INSTALL_PREFIX@)
set(CPACK_GENERATOR "TGZ;DEB;RPM")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
install(FILES ${CPACK_RESOURCE_FILE_LICENSE} DESTINATION @CMAKE_INSTALL_DOCDIR@)

#Make proper version for appending
#Default Value is 99999, setting it first
set(ROCM_VERSION_FOR_PACKAGE "99999")
if(DEFINED ENV{ROCM_LIBPATCH_VERSION})
  set(ROCM_VERSION_FOR_PACKAGE $ENV{ROCM_LIBPATCH_VERSION})
endif()

#Debian package specific variables
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CPACK_DEBIAN_PACKAGE_HOMEPAGE} CACHE STRING "https://github.com/ROCm")
if(ROCM_DEP_ROCMCORE)
  set(CPACK_DEBIAN_PACKAGE_DEPENDS "rocm-core")
endif()
if (DEFINED ENV{CPACK_DEBIAN_PACKAGE_RELEASE})
   set(CPACK_DEBIAN_PACKAGE_RELEASE $ENV{CPACK_DEBIAN_PACKAGE_RELEASE})
else()
   set(CPACK_DEBIAN_PACKAGE_RELEASE "local")
endif()

#RPM package specific variables
set(CPACK_RPM_PACKAGE_AUTOREQPROV "NO")
string(REPLACE "/hip" "" ROCM_PATH @CPACK_PACKAGING_INSTALL_PREFIX@)
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/opt" "${ROCM_PATH}" "@CPACK_PACKAGING_INSTALL_PREFIX@" "@CPACK_PACKAGING_INSTALL_PREFIX@/bin")
if(ROCM_DEP_ROCMCORE)
  set(CPACK_RPM_PACKAGE_REQUIRES "rocm-core")
endif()
if(DEFINED ENV{CPACK_RPM_PACKAGE_RELEASE})
  set(CPACK_RPM_PACKAGE_RELEASE $ENV{CPACK_RPM_PACKAGE_RELEASE})
else()
  set(CPACK_RPM_PACKAGE_RELEASE "local")
endif()
set(CPACK_RPM_PACKAGE_LICENSE "MIT")

#Set rpm distro
if(CPACK_RPM_PACKAGE_RELEASE)
  set(CPACK_RPM_PACKAGE_RELEASE_DIST ON)
endif()

#Prepare final version for the CAPACK use
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}.${ROCM_VERSION_FOR_PACKAGE}")

#Set the names now using CPACK utility
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")

# Control debug info package generation
set(CPACK_RPM_DEBUGINFO_PACKAGE @CPACK_RPM_DEBUGINFO_PACKAGE@)
set(CPACK_DEBIAN_DEBUGINFO_PACKAGE @CPACK_DEBIAN_DEBUGINFO_PACKAGE@)
set(CPACK_RPM_INSTALL_WITH_EXEC @CPACK_RPM_INSTALL_WITH_EXEC@)

include(CPack)
