message("Running OSX deploy script.")
set(MACDEPLOYQT "@MACDEPLOYQT@")

# Remove when done debugging
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
    message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
#message("Prefix is: ${CMAKE_INSTALL_PREFIX}")
#execute_process(COMMAND ls ${CMAKE_INSTALL_PREFIX})
set(TMP_APPDIR "${CPACK_TEMPORARY_INSTALL_DIRECTORY}/@PROJECT_NAME@.app")

execute_process(COMMAND find "${CPACK_TEMPORARY_INSTALL_DIRECTORY}")
message("Running macdeployqt on ${TMP_APPDIR}")
execute_process(COMMAND ${MACDEPLOYQT} "${TMP_APPDIR}" -verbose=3)
execute_process(COMMAND install_name_tool -add_rpath "@executable_path/../Frameworks" "${CPACK_TEMPORARY_INSTALL_DIRECTORY}/@PROJECT_NAME@.app/Contents/MacOS/merkaartor")
execute_process(COMMAND otool -l "${CPACK_TEMPORARY_INSTALL_DIRECTORY}/@PROJECT_NAME@.app/Contents/MacOS/merkaartor")
message("Done bundling.")
execute_process(COMMAND find "${CPACK_TEMPORARY_INSTALL_DIRECTORY}")
