99 lines
3.2 KiB
CMake
99 lines
3.2 KiB
CMake
# usage: deploy_target(<target> <full_app_name> <version> <icon> <label> <copyright> <info>
|
|
# [DEPLOY_DIR <dir>] [DESTINATION <dir>] [NO_AUTO_ICON_EXT])
|
|
#
|
|
# DEPLOY_DIR - dir where you install
|
|
# * executable on Windows, Linux
|
|
# * <T>.app directory with executable on MacOS
|
|
#
|
|
# DESTINATION - dir where macro place package
|
|
#
|
|
# Example:
|
|
# deploy_target(my_app
|
|
# "org.Company.my_app"
|
|
# "0.0.1"
|
|
# "icons/my_app.icns"
|
|
# "My Application"
|
|
# "Company"
|
|
# "Info about My Application"
|
|
# DESTINATION packages
|
|
#
|
|
# Create make target "deploy"
|
|
#
|
|
# This macro use "deploy_tool" from sdk,
|
|
# make sure it can be executed from shell
|
|
#
|
|
# use "CMAKE_OTOOL" or "CMAKE_OBJDUMP" variable,
|
|
# depends on target platform
|
|
# can use "DEPLOY_ADD_LIBPATH" variable as additional
|
|
# library search path
|
|
#
|
|
macro(deploy_target _T full_app_name version icon label copyright info)
|
|
set(_DESTINATION)
|
|
set(_DEPLOY_DIR)
|
|
set(_is_dest 0)
|
|
set(_is_deploy_dir 0)
|
|
foreach(_i ${ARGN})
|
|
if (_is_dest)
|
|
set(_is_dest 0)
|
|
set(_DESTINATION "${_i}/")
|
|
else()
|
|
if (_is_deploy_dir)
|
|
set(_is_deploy_dir 0)
|
|
set(_DEPLOY_DIR "${_i}/")
|
|
else()
|
|
if ("x${_i}" STREQUAL "xDESTINATION")
|
|
set(_is_dest 1)
|
|
else()
|
|
if ("x${_i}" STREQUAL "xDEPLOY_DIR")
|
|
set(_is_deploy_dir 1)
|
|
endif()
|
|
endif()
|
|
endif()
|
|
endif()
|
|
#message("-i = ${_i}")
|
|
endforeach()
|
|
get_filename_component(_ICON_NAME "${icon}" NAME)
|
|
get_filename_component(_ICON_FN "${icon}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
set(_TV "${_T}-${version}")
|
|
set(_DEP_LIBPATH)
|
|
get_target_property(_LL ${_T} LINK_LIBRARIES)
|
|
foreach (_L ${_LL})
|
|
if (TARGET ${_L})
|
|
get_target_property(_II ${_L} IMPORTED)
|
|
if (NOT _II)
|
|
#message("depend on ${_L}")
|
|
set(_DEP_LIBPATH "${_DEP_LIBPATH}\;$<TARGET_FILE_DIR:${_L}>")
|
|
endif()
|
|
endif()
|
|
endforeach()
|
|
#message("app depend libpath ${_DEP_LIBPATH}")
|
|
if (APPLE)
|
|
set(MACOSX_BUNDLE_GUI_IDENTIFIER "${full_app_name}")
|
|
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${version}")
|
|
set(MACOSX_BUNDLE_LONG_VERSION_STRING "${version}")
|
|
set(MACOSX_BUNDLE_ICON_FILE "${_ICON_NAME}")
|
|
set(MACOSX_BUNDLE_BUNDLE_NAME "${label}")
|
|
set(MACOSX_BUNDLE_COPYRIGHT "${copyright}")
|
|
set(MACOSX_BUNDLE_INFO_STRING "${info}")
|
|
set(MACOSX_BUNDLE_BUNDLE_VERSION "6.0")
|
|
set_target_properties(${_T} PROPERTIES MACOSX_BUNDLE TRUE)
|
|
set(_AGD "${_DEPLOY_DIR}${_T}.app")
|
|
set(_DMG "${CMAKE_CURRENT_BINARY_DIR}/dmg")
|
|
add_custom_target(deploy
|
|
# gather .app dir
|
|
COMMAND mkdir -p ${_AGD}/Contents/Resources
|
|
COMMAND mkdir -p ${_AGD}/Contents/Frameworks
|
|
COMMAND cp ${_ICON_FN} ${_AGD}/Contents/Resources
|
|
COMMAND deploy_tool -M "${CMAKE_OTOOL}" -P cocoa -S mac -q ${Qt5_ROOT} -s \"${CMAKE_PREFIX_PATH}/lib\;${DEPLOY_ADD_LIBPATH}${_DEP_LIBPATH}\" -o ${_AGD}/Contents/Frameworks -p ${_AGD}/Contents/PlugIns ${_AGD}/Contents/MacOS/${_T}
|
|
# prepare dmg dir
|
|
COMMAND rm -rf ${_DMG}
|
|
COMMAND mkdir -p ${_DMG}
|
|
COMMAND cp -r ${_AGD} ${_DMG}
|
|
COMMAND ln --symbolic /Applications ${_DMG}
|
|
# generate dmg
|
|
COMMAND genisoimage -quiet -V ${_T} -D -R -apple -no-pad -o ${_DESTINATION}${_TV}.dmg ${_DMG}
|
|
COMMENT "Generating ${_TV}.dmg"
|
|
)
|
|
endif()
|
|
endmacro()
|