2016-04-16 00:50:16 +02:00
|
|
|
# before including this module, BasicConfig must be included
|
|
|
|
|
2016-08-19 16:13:41 +02:00
|
|
|
# check whether project type is set correctly
|
|
|
|
if(NOT "${META_PROJECT_TYPE}" STREQUAL "application")
|
|
|
|
message(FATAL_ERROR "The AppTarget CMake module is intended to be used for building application projects only (and not for libraries).")
|
|
|
|
endif()
|
|
|
|
|
2016-07-22 01:35:32 +02:00
|
|
|
# set the windows extension to "exe", this is required by the Windows specific WindowsResources module
|
|
|
|
if(WIN32)
|
2016-04-16 00:50:16 +02:00
|
|
|
set(WINDOWS_EXT "exe")
|
2016-07-22 01:35:32 +02:00
|
|
|
endif(WIN32)
|
2016-04-16 00:50:16 +02:00
|
|
|
|
2016-08-19 16:13:41 +02:00
|
|
|
# use correct linker flags and compile definitions (depend on linkage)
|
|
|
|
if(STATIC_LINKAGE)
|
|
|
|
set(ACTUAL_ADDITIONAL_LINK_FLAGS ${ADDITIONAL_STATIC_LINK_FLAGS})
|
|
|
|
set(ACTUAL_ADDITIONAL_COMPILE_DEFINITIONS ${ADDITIONAL_STATIC_COMPILE_DEFINITIONS})
|
|
|
|
else()
|
|
|
|
set(ACTUAL_ADDITIONAL_LINK_FLAGS ${ADDITIONAL_LINK_FLAGS})
|
|
|
|
set(ACTUAL_ADDITIONAL_COMPILE_DEFINITIONS ${ADDITIONAL_COMPILE_DEFINITIONS})
|
|
|
|
endif()
|
2016-04-16 00:50:16 +02:00
|
|
|
# add target for building the application
|
|
|
|
add_executable(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} ${GUI_TYPE} ${HEADER_FILES} ${SRC_FILES} ${WIDGETS_FILES} ${QML_FILES} ${RES_FILES} ${QM_FILES} ${WINDOWS_ICON_PATH})
|
2016-08-19 16:13:41 +02:00
|
|
|
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} ${ACTUAL_ADDITIONAL_LINK_FLAGS} ${LIBRARIES})
|
2016-04-16 00:50:16 +02:00
|
|
|
set_target_properties(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} PROPERTIES
|
|
|
|
CXX_STANDARD 11
|
2016-08-19 16:13:41 +02:00
|
|
|
COMPILE_DEFINITIONS "${ACTUAL_ADDITIONAL_COMPILE_DEFINITIONS}"
|
|
|
|
LINK_SEARCH_START_STATIC ${STATIC_LINKAGE}
|
|
|
|
LINK_SEARCH_END_STATIC ${STATIC_LINKAGE}
|
2016-04-16 00:50:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# add install target for binary
|
|
|
|
install(TARGETS ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
|
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
COMPONENT binary
|
|
|
|
)
|
|
|
|
|
|
|
|
if(NOT TARGET install-binary)
|
|
|
|
add_custom_target(install-binary
|
|
|
|
DEPENDS ${META_PROJECT_NAME}
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=binary -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# add install target for localization
|
|
|
|
if(NOT TARGET install-mingw-w64)
|
|
|
|
add_custom_target(install-mingw-w64
|
|
|
|
DEPENDS install-binary ${LOCALIZATION_TARGET}
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# add install target for desktop entries and icons
|
|
|
|
foreach(DESKTOP_FILE ${DESKTOP_FILES})
|
|
|
|
install(
|
|
|
|
FILES "${DESKTOP_FILE}"
|
|
|
|
DESTINATION "share/applications"
|
|
|
|
COMPONENT desktop
|
|
|
|
)
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
foreach(ICON_FILE ${ICON_FILES})
|
|
|
|
install(
|
|
|
|
FILES "${ICON_FILE}"
|
|
|
|
DESTINATION "share/icons/hicolor/scalable/apps"
|
|
|
|
COMPONENT desktop
|
|
|
|
)
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if(NOT TARGET install-desktop)
|
|
|
|
add_custom_target(install-desktop
|
|
|
|
DEPENDS ${META_PROJECT_NAME}
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=desktop -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# add install target for stripped binaries
|
|
|
|
if(NOT TARGET install-binary-strip)
|
|
|
|
add_custom_target(install-binary-strip
|
|
|
|
DEPENDS ${META_PROJECT_NAME}
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_DO_STRIP=1 -DCMAKE_INSTALL_COMPONENT=binary -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# add mingw-w64 specific install target
|
|
|
|
if(NOT TARGET install-mingw-w64-strip)
|
|
|
|
add_custom_target(install-mingw-w64-strip
|
|
|
|
DEPENDS install-binary-strip ${LOCALIZATION_TARGET}
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2016-07-16 23:04:22 +02:00
|
|
|
# add target for launching application with wine ensuring the WINEPATH is set correctly so wine is able to find all required *.dll files
|
|
|
|
# requires script from c++utilities, hence the sources of c++utilities must be present
|
|
|
|
if(MINGW AND CMAKE_CROSSCOMPILING AND CPP_UTILITIES_SOURCE_DIR)
|
|
|
|
if(NOT TARGET ${META_PROJECT_NAME}_run)
|
|
|
|
if(CMAKE_FIND_ROOT_PATH)
|
|
|
|
list(APPEND RUNTIME_LIBRARY_PATH "${CMAKE_FIND_ROOT_PATH}/bin")
|
|
|
|
endif()
|
|
|
|
add_custom_target(${META_PROJECT_NAME}_run COMMAND "${CPP_UTILITIES_SOURCE_DIR}/scripts/wine.sh" "${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}.${WINDOWS_EXT}" ${RUNTIME_LIBRARY_PATH})
|
|
|
|
add_dependencies(${META_PROJECT_NAME}_run ${META_PROJECT_NAME})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2016-04-16 00:50:16 +02:00
|
|
|
# find template for *.desktop files
|
2016-06-09 22:57:51 +02:00
|
|
|
include(TemplateFinder)
|
|
|
|
find_template_file("desktop" CPP_UTILITIES APP_DESKTOP_TEMPLATE_FILE)
|
2016-04-16 00:50:16 +02:00
|
|
|
|
|
|
|
# function to add *.desktop files
|
|
|
|
function(add_custom_desktop_file
|
|
|
|
FILE_NAME
|
|
|
|
DESKTOP_FILE_APP_NAME
|
|
|
|
DESKTOP_FILE_DESCRIPTION
|
|
|
|
DESKTOP_FILE_CATEGORIES
|
|
|
|
DESKTOP_FILE_CMD
|
|
|
|
DESKTOP_FILE_ICON)
|
|
|
|
# create desktop file from template
|
|
|
|
configure_file(
|
|
|
|
"${APP_DESKTOP_TEMPLATE_FILE}"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/resources/${FILE_NAME}.desktop"
|
|
|
|
)
|
|
|
|
# add install for the desktop file
|
|
|
|
install(
|
|
|
|
FILES "${CMAKE_CURRENT_BINARY_DIR}/resources/${FILE_NAME}.desktop"
|
|
|
|
DESTINATION "share/applications"
|
|
|
|
COMPONENT desktop
|
|
|
|
)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# convenience function to add *.desktop file from project meta data
|
|
|
|
function(add_desktop_file)
|
|
|
|
add_custom_desktop_file(
|
2016-07-02 02:04:32 +02:00
|
|
|
"${TARGET_EXECUTABLE}"
|
2016-04-16 00:50:16 +02:00
|
|
|
"${META_APP_NAME}"
|
|
|
|
"${META_APP_DESCRIPTION}"
|
|
|
|
"${META_APP_CATEGORIES}"
|
|
|
|
"${META_PROJECT_NAME}"
|
|
|
|
"${META_PROJECT_NAME}"
|
|
|
|
)
|
|
|
|
endfunction()
|