reduce code duplication in build system

- get rid of qmake project file
- provide CMake modules for common tasks
- provide templates for *.desktop files
This commit is contained in:
Martchus 2016-04-16 18:38:36 +02:00
parent 0817010dbf
commit ea257f9fee
6 changed files with 32 additions and 483 deletions

View File

@ -1,5 +1,16 @@
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
# meta data
set(META_PROJECT_NAME videodownloader)
set(META_APP_NAME "Video Downloader")
set(META_APP_CATEGORIES "Utility;Network;")
set(META_APP_AUTHOR "Martchus")
set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
set(META_APP_DESCRIPTION "Simple video downloader with Qt GUI (currently only YouTube and Vimeo are maintained).")
set(META_VERSION_MAJOR 1)
set(META_VERSION_MINOR 3)
set(META_VERSION_PATCH 1)
# add project files
set(HEADER_FILES
application/main.h
@ -54,8 +65,8 @@ set(SRC_FILES
network/testdownload.cpp
network/vimeodownload.cpp
network/youtubedownload.cpp
)
set(WIDGETS_HEADER_FILES
gui/downloadwidget.h
gui/adddownloaddialog.h
@ -90,171 +101,38 @@ set(WIDGETS_UI_FILES
gui/proxypage.ui
gui/useragentpage.ui
)
#set(QUICK_HEADER_FILES
#)
#set(QUICK_SRC_FILES
#)
#set(TS_FILES
# translations/${META_PROJECT_NAME}_de_DE.ts
# translations/${META_PROJECT_NAME}_en_US.ts
#)
# meta data
set(META_PROJECT_NAME videodownloader)
set(META_APP_NAME "Video Downloader")
set(META_APP_AUTHOR "Martchus")
set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
set(META_APP_DESCRIPTION "A video downloader with Qt GUI (currently only YouTube and Vimeo are maintained).")
set(META_VERSION_MAJOR 1)
set(META_VERSION_MINOR 3)
set(META_VERSION_PATCH 1)
# stringification of meta data
set(META_PROJECT_NAME_STR "\"${META_PROJECT_NAME}\"")
set(META_APP_NAME_STR "\"${META_APP_NAME}\"")
set(META_APP_AUTHOR_STR "\"${META_APP_AUTHOR}\"")
set(META_APP_URL_STR "\"${META_APP_URL}\"")
set(META_APP_DESCRIPTION_STR "\"${META_APP_DESCRIPTION}\"")
set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH})
set(META_APP_VERSION_STR "\"${META_APP_VERSION}\"")
# define project
project(${META_PROJECT_NAME})
# add configuration header
configure_file(
"${PROJECT_SOURCE_DIR}/resources/config.h.in"
"${PROJECT_BINARY_DIR}/resources/config.h"
)
include_directories("${PROJECT_BINARY_DIR}")
# set "GUI-type" to WIN32 to hide console under windows
if(WIN32)
set(GUI_TYPE WIN32)
endif(WIN32)
# add windows resource file
if(MINGW)
# creation windows icon from png with ffmpeg if available
find_program(FFMPEG_BIN ffmpeg avconv)
if(FFMPEG_BIN)
set(PNG_ICON_PATH "${PROJECT_SOURCE_DIR}/resources/icons/hicolor/128x128/apps/${META_PROJECT_NAME}.png")
if(EXISTS ${PNG_ICON_PATH})
set(WINDOWS_ICON_PATH "${PROJECT_BINARY_DIR}/${META_PROJECT_NAME}.ico")
set(WINDOWS_ICON_RC_ENTRY "IDI_ICON1 ICON DISCARDABLE \"${WINDOWS_ICON_PATH}\"")
add_custom_command(
OUTPUT "${WINDOWS_ICON_PATH}"
COMMAND ${FFMPEG_BIN} -y -i "${PNG_ICON_PATH}" -vf crop=iw-20:ih-20:10:10,scale=64:64 "${WINDOWS_ICON_PATH}"
)
endif()
endif(FFMPEG_BIN)
# create windows rc file from template
set(WINDOWS_EXT "exe")
configure_file(
"${PROJECT_SOURCE_DIR}/resources/windows.rc.in"
"${PROJECT_BINARY_DIR}/resources/windows.rc"
)
# set windres as resource compiler
set(RES_FILES "${PROJECT_BINARY_DIR}/resources/windows.rc")
set(CMAKE_RC_COMPILER_INIT windres)
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
enable_language(RC)
endif(MINGW)
# enable Qt Widgets GUI
# disable new ABI (can't catch ios_base::failure with new ABI)
add_definitions(
-DGUI_QTWIDGETS
-DMODEL_UNDO_SUPPORT
-D_GLIBCXX_USE_CXX11_ABI=0
set(ICON_FILES
resources/icons/hicolor/scalable/apps/${META_PROJECT_NAME}.svg
)
# check required Qt 5 modules
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5LinguistTools REQUIRED)
find_package(Qt5Network REQUIRED)
# find c++utilities
find_package(c++utilities REQUIRED)
use_cpp_utilities()
# enable moc, uic and rcc
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# find qtutilities
find_package(qtutilities REQUIRED)
use_qt_utilities()
# enable lrelease
qt5_add_translation(QM_FILES ${TS_FILES})
ADD_CUSTOM_TARGET(translations ALL DEPENDS ${QM_FILES})
# add Qt modules which can currently not be detected automatically
list(APPEND ADDITIONAL_QT_MODULES Network)
# executable and linking
add_executable(${META_PROJECT_NAME} ${GUI_TYPE} ${HEADER_FILES} ${SRC_FILES} ${WIDGETS_HEADER_FILES} ${WIDGETS_SRC_FILES} ${WIDGETS_UI_FILES} ${QM_FILES} ${RES_FILES} ${WINDOWS_ICON_PATH})
target_link_libraries(${META_PROJECT_NAME} c++utilities qtutilities Qt5::Core Qt5::Widgets Qt5::Network)
set_target_properties(${META_PROJECT_NAME} PROPERTIES
CXX_STANDARD 11
)
# include modules to apply configuration
include(BasicConfig)
include(QtGuiConfig)
include(QtConfig)
include(WindowsResources)
include(AppTarget)
# add install target
install(TARGETS ${META_PROJECT_NAME}
RUNTIME DESTINATION bin
COMPONENT binary
)
install(FILES resources/icons/hicolor/scalable/apps/${META_PROJECT_NAME}.svg
DESTINATION share/icons/hicolor/scalable/apps
COMPONENT desktop
)
install(FILES resources/desktop/applications/${META_PROJECT_NAME}.desktop
DESTINATION share/applications
COMPONENT desktop
)
install(FILES ${QM_FILES}
DESTINATION share/${META_PROJECT_NAME}/translations
COMPONENT localization
)
install(FILES resources/json/groovesharkauthenticationinfo.json
DESTINATION share/${META_PROJECT_NAME}/json
COMPONENT config
)
install(FILES resources/json/itaginfo.json
DESTINATION share/${META_PROJECT_NAME}/json
COMPONENT config
)
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()
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()
if(NOT TARGET install-localization)
add_custom_target(install-localization
DEPENDS ${META_PROJECT_NAME}
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=localization -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
)
endif()
if(NOT TARGET install-config)
add_custom_target(install-config
DEPENDS ${META_PROJECT_NAME}
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=config -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
)
endif()
if(NOT TARGET install-mingw-w64)
add_custom_target(install-mingw-w64
DEPENDS install-binary install-localization install-config
)
endif()
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()
if(NOT TARGET install-mingw-w64-strip)
add_custom_target(install-mingw-w64-strip
DEPENDS install-binary-strip install-localization install-config
)
endif()
# create desktop file using previously defined meta data
add_desktop_file()

View File

@ -1,103 +0,0 @@
# specify build directories for moc, object and rcc files
MOC_DIR = ./moc
OBJECTS_DIR = ./obj
RCC_DIR = ./res
# compiler flags: enable C++11
QMAKE_CXXFLAGS += -std=c++11
QMAKE_LFLAGS += -std=c++11
# disable new ABI (can't catch ios_base::failure with new ABI)
DEFINES += _GLIBCXX_USE_CXX11_ABI=0
# variables to check target architecture
win32-g++:QMAKE_TARGET.arch = $$QMAKE_HOST.arch
win32-g++-32:QMAKE_TARGET.arch = x86
win32-g++-64:QMAKE_TARGET.arch = x86_64
linux-g++:QMAKE_TARGET.arch = $$QMAKE_HOST.arch
linux-g++-32:QMAKE_TARGET.arch = x86
linux-g++-64:QMAKE_TARGET.arch = x86_64
# determine and print target prefix
targetprefix = $$(TARGET_PREFIX)
message("Using target prefix \"$${targetprefix}\".")
# print install root
message("Using install root \"$$(INSTALL_ROOT)\".")
# set target
CONFIG(debug, debug|release) {
TARGET = $${targetprefix}$${projectname}d
} else {
TARGET = $${targetprefix}$${projectname}
}
# add defines for meta data
DEFINES += "APP_METADATA_AVAIL"
DEFINES += "'PROJECT_NAME=\"$${projectname}\"'"
DEFINES += "'APP_NAME=\"$${appname}\"'"
DEFINES += "'APP_AUTHOR=\"$${appauthor}\"'"
DEFINES += "'APP_URL=\"$${appurl}\"'"
DEFINES += "'APP_VERSION=\"$${VERSION}\"'"
# configure Qt modules and defines
mobile {
DEFINES += CONFIG_MOBILE
} else:desktop {
DEFINES += CONFIG_DESKTOP
} else:android {
CONFIG += mobile
DEFINES += CONFIG_MOBILE
} else {
CONFIG += desktop
DEFINES += CONFIG_DESKTOP
}
no-gui {
QT -= gui
DEFINES += GUI_NONE
guiqtquick || guiqtwidgets {
error("Can not use no-gui with guiqtquick or guiqtwidgets.")
} else {
message("Configured for no GUI support.")
}
} else {
QT += gui
mobile {
CONFIG += guiqtquick
}
desktop {
CONFIG += guiqtwidgets
}
}
guiqtquick {
message("Configured for Qt Quick GUI support.")
QT += quick
CONFIG(debug, debug|release) {
CONFIG += qml_debug
}
DEFINES += GUI_QTQUICK
}
guiqtwidgets {
message("Configured for Qt widgets GUI support.")
QT += widgets
DEFINES += GUI_QTWIDGETS
DEFINES += MODEL_UNDO_SUPPORT
}
# configuration for cross compliation with mingw-w64
win32 {
QMAKE_TARGET_PRODUCT = "$${appname}"
QMAKE_TARGET_COPYRIGHT = "by $${appauthor}"
}
mingw-w64-manualstrip-dll {
QMAKE_POST_LINK=$${CROSS_COMPILE}strip --strip-unneeded ./release/$(TARGET); \
$${CROSS_COMPILE}strip --strip-unneeded ./release/lib$(TARGET).a
}
mingw-w64-manualstrip-exe {
QMAKE_POST_LINK=$${CROSS_COMPILE}strip --strip-unneeded ./release/$(TARGET)
}
mingw-w64-noversion {
TARGET_EXT = ".dll"
TARGET_VERSION_EXT = ""
CONFIG += skip_target_version_ext
}

View File

@ -1,9 +0,0 @@
#ifndef APP_METADATA_AVAIL
#define APP_METADATA_AVAIL
#define PROJECT_NAME @META_PROJECT_NAME_STR@
#define APP_NAME @META_APP_NAME_STR@
#define APP_VERSION @META_APP_VERSION_STR@
#define APP_AUTHOR @META_APP_AUTHOR_STR@
#define APP_URL @META_APP_URL_STR@
#define APP_DESCRIPTION @META_APP_DESCRIPTION_STR@
#endif // APP_METADATA_AVAIL

View File

@ -1,9 +0,0 @@
[Desktop Entry]
Name=Video Downloader
GenericName=Video downloader
Comment=A simple YouTube and Grooveshark downloader.
Exec=videodownloader
Icon=videodownloader
Terminal=false
Type=Application
Categories=Utility;Network;

View File

@ -1,40 +0,0 @@
# if defined(UNDER_CE)
# include <winbase.h>
# else
# include <windows.h>
# endif
@WINDOWS_ICON_RC_ENTRY@
VS_VERSION_INFO VERSIONINFO
FILEVERSION @META_VERSION_MAJOR@,@META_VERSION_MINOR@,@META_VERSION_PATCH@,0
PRODUCTVERSION @META_VERSION_MAJOR@,@META_VERSION_MINOR@,@META_VERSION_PATCH@,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "@META_APP_AUTHOR@\0"
VALUE "FileDescription", "@META_APP_DESCRIPTION@\0"
VALUE "FileVersion", "@META_APP_VERSION@\0"
VALUE "LegalCopyright", "by @META_APP_AUTHOR@\0"
VALUE "OriginalFilename", "@META_PROJECT_NAME@.@WINDOWS_EXT@\0"
VALUE "ProductName", "@META_APP_NAME@\0"
VALUE "ProductVersion", "@META_APP_VERSION@\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1200
END
END
/* End of Version info */

View File

@ -1,168 +0,0 @@
# meta data
projectname = videodownloader
appname = "Video Downloader"
appauthor = Martchus
appurl = "https://github.com/$${appauthor}/$${projectname}"
QMAKE_TARGET_DESCRIPTION = "A video downloader with Qt GUI (currently only YouTube and Vimeo are maintained)."
VERSION = 1.3.1
# include ../../common.pri when building as part of a subdirs project; otherwise include general.pri
!include(../../common.pri) {
!include(./general.pri) {
error("Couldn't find the common.pri or the general.pri file!")
}
}
# basic configuration: application
TEMPLATE = app
QT += core gui widgets network
# add defines for configuration
testdownload {
DEFINES += CONFIG_TESTDOWNLOAD
}
underconstruction {
DEFINES += UNDER_CONSTRUCTION
}
!notrayicon {
DEFINES += CONFIG_USE_TRAY_ICON
usetrayiconalways {
DEFINES += CONFIG_USE_TRAY_ICON_ALWAYS
}
}
# add project files
HEADERS += \
application/main.h \
network/bitsharedownload.h \
network/download.h \
model/downloadmodel.h \
network/downloadrange.h \
network/filenukedownload.h \
network/finder/downloadfinder.h \
network/finder/groovesharksearcher.h \
network/finder/youtubeplaylist.h \
model/downloadfinderresultsmodel.h \
network/finder/linkfinder.h \
network/groovesharkdownload.h \
network/httpdownload.h \
network/httpdownloadwithinforequst.h \
network/misc/contentdispositionparser.h \
network/socksharedownload.h \
network/youtubedownload.h \
gui/adddownloaddialog.h \
gui/addmultipledownloadswizard.h \
gui/downloadwidget.h \
gui/mainwindow.h \
gui/setrangedialog.h \
application/utils.h \
itemdelegates/comboboxitemdelegate.h \
itemdelegates/progressbaritemdelegate.h \
gui/downloadinteraction.h \
gui/settings.h \
network/authenticationcredentials.h \
network/permissionstatus.h \
network/optiondata.h \
application/main.h \
gui/initiate.h \
cli/mainfeatures.h \
cli/clidownloadinteraction.h \
network/vimeodownload.h
SOURCES += \
application/main.cpp \
network/bitsharedownload.cpp \
network/download.cpp \
model/downloadmodel.cpp \
network/downloadrange.cpp \
network/filenukedownload.cpp \
network/finder/downloadfinder.cpp \
network/finder/groovesharksearcher.cpp \
network/finder/youtubeplaylist.cpp \
model/downloadfinderresultsmodel.cpp \
network/finder/linkfinder.cpp \
network/groovesharkdownload.cpp \
network/httpdownload.cpp \
network/httpdownloadwithinforequst.cpp \
network/misc/contentdispositionparser.cpp \
network/socksharedownload.cpp \
network/youtubedownload.cpp \
gui/adddownloaddialog.cpp \
gui/addmultipledownloadswizard.cpp \
gui/downloadwidget.cpp \
gui/mainwindow.cpp \
gui/setrangedialog.cpp \
application/utils.cpp \
itemdelegates/comboboxitemdelegate.cpp \
itemdelegates/progressbaritemdelegate.cpp \
gui/downloadinteraction.cpp \
gui/settings.cpp \
network/optiondata.cpp \
gui/initiate.cpp \
cli/mainfeatures.cpp \
cli/clidownloadinteraction.cpp \
network/vimeodownload.cpp
testdownload {
HEADERS += \
network/testdownload.h
SOURCES += \
network/testdownload.cpp
}
underconstruction {
SOURCES += \
network/spotifydownload.cpp
HEADERS += \
network/spotifydownload.h
}
FORMS += \
gui/adddownloaddialog.ui \
gui/downloadwidget.ui \
gui/setrangedialog.ui \
gui/mainwindow.ui \
gui/targetpage.ui \
gui/proxypage.ui \
gui/useragentpage.ui
RESOURCES += \
resources/icons.qrc \
resources/json.qrc
OTHER_FILES += \
README.md \
LICENSE \
CMakeLists.txt \
resources/config.h.in \
resources/windows.rc.in
# add libs
CONFIG(debug, debug|release) {
LIBS += -lc++utilitiesd
!no-gui {
LIBS += -lqtutilitiesd
}
} else {
LIBS += -lc++utilities
!no-gui {
LIBS += -lqtutilities
}
}
# installs
target.path = $$(INSTALL_ROOT)/bin
INSTALLS += target
!mingw-w64-install {
icon.path = $$(INSTALL_ROOT)/share/icons/hicolor/scalable/apps/
icon.files = $${PWD}/resources/icons/hicolor/scalable/apps/$${projectname}.svg
INSTALLS += icon
menu.path = $$(INSTALL_ROOT)/share/applications/
menu.files = $${PWD}/resources/desktop/applications/$${projectname}.desktop
INSTALLS += menu
}
json.path = $$(INSTALL_ROOT)/share/$${projectname}/json/
json.files = $${PWD}/resources/json/groovesharkauthenticationinfo.json
INSTALLS += json