cmake_minimum_required(VERSION 3.16)

MESSAGE(STATUS "Executing notarytool on ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
IF(KEYCHAIN AND NOT KEYCHAIN STREQUAL "default")
  EXECUTE_PROCESS(COMMAND xcrun notarytool submit ${CPACK_TEMPORARY_PACKAGE_FILE_NAME} --keychain-profile "@SNAP_MACOS_NOTARYTOOL_PROFILE@" --keychain "${KEYCHAIN}" --wait RESULT_VARIABLE RC_N COMMAND_ECHO STDOUT)
ELSE()
  EXECUTE_PROCESS(COMMAND xcrun notarytool submit ${CPACK_TEMPORARY_PACKAGE_FILE_NAME} --keychain-profile "@SNAP_MACOS_NOTARYTOOL_PROFILE@" --wait RESULT_VARIABLE RC_N COMMAND_ECHO STDOUT)
ENDIF()
MESSAGE(STATUS "notarytool return code: ${RC_N}")

MESSAGE(STATUS "Executing staple on ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
EXECUTE_PROCESS(COMMAND xcrun stapler staple ${CPACK_TEMPORARY_PACKAGE_FILE_NAME} RESULT_VARIABLE RC_S COMMAND_ECHO STDOUT)
MESSAGE(STATUS "staple return code: ${RC_S}")
