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:
parent
b722ccb5cb
commit
59d37b8c5e
|
@ -25,90 +25,11 @@ set(META_VERSION_MINOR 1)
|
||||||
set(META_VERSION_PATCH 1)
|
set(META_VERSION_PATCH 1)
|
||||||
set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH})
|
set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH})
|
||||||
|
|
||||||
# stringification of meta data
|
# find c++utilities
|
||||||
set(META_PROJECT_NAME_STR "\"${META_PROJECT_NAME}\"")
|
find_package(c++utilities REQUIRED)
|
||||||
set(META_APP_NAME_STR "\"${META_APP_NAME}\"")
|
use_cpp_utilities()
|
||||||
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}")
|
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
# disable new ABI (can't catch ios_base::failure with new ABI)
|
|
||||||
add_definitions(
|
|
||||||
-D_GLIBCXX_USE_CXX11_ABI=0
|
|
||||||
)
|
|
||||||
|
|
||||||
# executable and linking
|
|
||||||
add_executable(${META_PROJECT_NAME} ${HEADER_FILES} ${SRC_FILES} ${RES_FILES} ${WINDOWS_ICON_PATH})
|
|
||||||
target_link_libraries(${META_PROJECT_NAME} c++utilities)
|
|
||||||
set_target_properties(${META_PROJECT_NAME} PROPERTIES
|
|
||||||
CXX_STANDARD 11
|
|
||||||
)
|
|
||||||
|
|
||||||
# add install target
|
|
||||||
install(TARGETS ${META_PROJECT_NAME}
|
|
||||||
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()
|
|
||||||
if(NOT TARGET install-mingw-w64)
|
|
||||||
add_custom_target(install-mingw-w64
|
|
||||||
DEPENDS install-binary
|
|
||||||
)
|
|
||||||
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
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
# include modules to apply configuration
|
||||||
|
include(BasicConfig)
|
||||||
|
include(WindowsResources)
|
||||||
|
include(AppTarget)
|
||||||
|
|
103
general.pri
103
general.pri
|
@ -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
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
# meta data
|
|
||||||
projectname = geocoordinatecalculator
|
|
||||||
appname = "Geo coordinate calculator"
|
|
||||||
appauthor = Martchus
|
|
||||||
appurl = "https://github.com/$${appauthor}/$${projectname}"
|
|
||||||
QMAKE_TARGET_DESCRIPTION = "Command line tool for basic calculations with geo coordinates such as format conversions and calculation of distance, bearing, mid point, destination and more."
|
|
||||||
VERSION = 1.1.1
|
|
||||||
|
|
||||||
# implicit configuration: no GUI
|
|
||||||
CONFIG += no-gui
|
|
||||||
|
|
||||||
# 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: console application, no Qt
|
|
||||||
TEMPLATE = app
|
|
||||||
CONFIG -= qt
|
|
||||||
CONFIG += console
|
|
||||||
|
|
||||||
# add project files
|
|
||||||
HEADERS += \
|
|
||||||
main.h \
|
|
||||||
location.h \
|
|
||||||
angle.h \
|
|
||||||
utils.h
|
|
||||||
|
|
||||||
SOURCES += \
|
|
||||||
main.cpp \
|
|
||||||
location.cpp \
|
|
||||||
angle.cpp \
|
|
||||||
utils.cpp
|
|
||||||
|
|
||||||
OTHER_FILES += \
|
|
||||||
README.md \
|
|
||||||
LICENSE \
|
|
||||||
CMakeLists.txt \
|
|
||||||
resources/config.h.in \
|
|
||||||
resources/windows.rc.in
|
|
||||||
|
|
||||||
# add libs
|
|
||||||
CONFIG(debug, debug|release) {
|
|
||||||
LIBS += -lc++utilitiesd
|
|
||||||
} else {
|
|
||||||
LIBS += -lc++utilities
|
|
||||||
}
|
|
||||||
|
|
||||||
# installs
|
|
||||||
target.path = $$(INSTALL_ROOT)/bin
|
|
||||||
INSTALLS += target
|
|
|
@ -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
|
|
|
@ -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 */
|
|
Loading…
Reference in New Issue