if(NOT "$ENV{MATCH_PASSWORD}" STREQUAL ""
   AND NOT "$ENV{MATCH_PASSWORD}" STREQUAL ""
   AND NOT "$ENV{MATCH_PASSWORD}" STREQUAL "")
  # -appstore-compliant will strip away odbc, psql and webengine plugins
  execute_process(COMMAND "${MACDEPLOYQT_EXECUTABLE}" qfield.app -appstore-compliant -qmldir=${CMAKE_SOURCE_DIR}/src/qml -codesign=${MACOS_CODE_SIGN_IDENTITY} -sign-for-notarization=${MACOS_CODE_SIGN_IDENTITY}
                  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/output/bin
                  COMMAND_ERROR_IS_FATAL ANY
                  )

  execute_process(COMMAND create-dmg --volname "QField Installer" --hide-extension qfield.app --volicon "${CMAKE_SOURCE_DIR}/platform/macos/installer.icns" --background "${CMAKE_SOURCE_DIR}/platform/macos/installer_background.png" --window-pos 200 120 --window-size 512 320 --icon-size 100 --icon "qfield.app" 130 160 --app-drop-link 400 155 --codesign "${MACOS_CODE_SIGN_IDENTITY}" ${CMAKE_BINARY_DIR}/QField-Installer.dmg  ${CMAKE_BINARY_DIR}/output/bin/qfield.app
                  RESULT_VARIABLE CREATE_DMG_FAILURE)

  if(CREATE_DMG_FAILURE)
  message(STATUS "Creating dmg failed. Retrying ...")
  execute_process(COMMAND create-dmg --volname "QField Installer" --hide-extension qfield.app --volicon "${CMAKE_SOURCE_DIR}/platform/macos/installer.icns" --background "${CMAKE_SOURCE_DIR}/platform/macos/installer_background.png" --window-pos 200 120 --window-size 512 320 --icon-size 100 --icon "qfield.app" 130 160 --app-drop-link 400 155 --codesign "${MACOS_CODE_SIGN_IDENTITY}" ${CMAKE_BINARY_DIR}/QField-Installer.dmg  ${CMAKE_BINARY_DIR}/output/bin/qfield.app
                  COMMAND_ERROR_IS_FATAL ANY)
  endif()
else()
  # -appstore-compliant will strip away odbc, psql and webengine plugins
  execute_process(COMMAND "${MACDEPLOYQT_EXECUTABLE}" qfield.app -appstore-compliant -qmldir=${CMAKE_SOURCE_DIR}/src/qml
                  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/output/bin
                  COMMAND_ERROR_IS_FATAL ANY
                  )

  execute_process(COMMAND create-dmg --volname "QField Installer" --hide-extension qfield.app --volicon "${CMAKE_SOURCE_DIR}/platform/macos/installer.icns" --background "${CMAKE_SOURCE_DIR}/platform/macos/installer_background.png" --window-pos 200 120 --window-size 512 320 --icon-size 100 --icon "qfield.app" 130 160 --app-drop-link 400 155 ${CMAKE_BINARY_DIR}/QField-Installer.dmg  ${CMAKE_BINARY_DIR}/output/bin/qfield.app
                  RESULT_VARIABLE CREATE_DMG_FAILURE)

  if(CREATE_DMG_FAILURE)
  message(STATUS "Creating dmg failed. Retrying ...")
  execute_process(COMMAND create-dmg --volname "QField Installer" --hide-extension qfield.app --volicon "${CMAKE_SOURCE_DIR}/platform/macos/installer.icns" --background "${CMAKE_SOURCE_DIR}/platform/macos/installer_background.png" --window-pos 200 120 --window-size 512 320 --icon-size 100 --icon "qfield.app" 130 160 --app-drop-link 400 155 ${CMAKE_BINARY_DIR}/QField-Installer.dmg  ${CMAKE_BINARY_DIR}/output/bin/qfield.app
                  COMMAND_ERROR_IS_FATAL ANY)
  endif()
endif()
