From 372154ce2ac462d5d3951a72b6c3c2de697e7db8 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 5 Dec 2015 22:50:38 +0100 Subject: [PATCH] added simple CMake project file --- CMakeLists.txt | 70 +++++++++++++++++++++ aboutdialog/aboutdialog.cpp | 2 +- config.h.in | 9 +++ enterpassworddialog/enterpassworddialog.cpp | 11 ++-- enterpassworddialog/enterpassworddialog.h | 2 - general.pri | 2 +- settingsdialog/settingsdialog.cpp | 2 +- 7 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0e85dca --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,70 @@ +cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) + +# meta data +set(META_PROJECT_NAME qtutilities) +set(META_APP_NAME "Qt Utilities") +set(META_APP_AUTHOR "Martchus") +set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") +set(META APP_DESCRIPTION "Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models.") +set(META_VERSION_MAJOR 3) +set(META_VERSION_MINOR 0) +set(META_VERSION_PATCH 1) + +# define project +project(${META_PROJECT_NAME}) + +# 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(APP_DESCRIPTION_STR "\"${APP_DESCRIPTION}\"") +set(META_APP_VERSION_STR "\"${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}\"") + +# add configuration header +configure_file ( + "${PROJECT_SOURCE_DIR}/config.h.in" + "${PROJECT_BINARY_DIR}/config.h" +) +include_directories("${PROJECT_BINARY_DIR}") + +# add source and header files +file(GLOB_RECURSE SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp" "*.c" "*.qrc") +file(GLOB_RECURSE HEADER_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h") + +# enable capslock detection +add_definitions(-DPLATFORM_SPECIFIC_CAPSLOCK_DETECTION) + +# check required Qt 5 modules +find_package(Qt5Core REQUIRED) +find_package(Qt5Gui REQUIRED) +find_package(Qt5Widgets REQUIRED) + +# enable moc, uic and rcc +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +# executable and linking +add_library(${META_PROJECT_NAME} SHARED ${HEADER_FILES} ${SRC_FILES}) +set(EXTRA_LIBS "") +if(${CMAKE_SYSTEM_NAME} MATCHES Linux) + set(EXTRA_LIBS X11) +endif() +target_link_libraries(${META_PROJECT_NAME} c++utilities Qt5::Core Qt5::Widgets ${EXTRA_LIBS}) +set_target_properties(${META_PROJECT_NAME} PROPERTIES VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH} SOVERSION ${META_VERSION_MAJOR}) + +# enable C++11 +set_property(TARGET ${META_PROJECT_NAME} PROPERTY CXX_STANDARD 11) + +# add install target +install(TARGETS ${META_PROJECT_NAME} + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) +foreach(HEADER_FILE ${HEADER_FILES}) + get_filename_component(HEADER_DIR ${HEADER_FILE} DIRECTORY) + install(FILES ${HEADER_FILE} DESTINATION include/${META_PROJECT_NAME}/${HEADER_DIR}) +endforeach() diff --git a/aboutdialog/aboutdialog.cpp b/aboutdialog/aboutdialog.cpp index 948ea1e..8218889 100644 --- a/aboutdialog/aboutdialog.cpp +++ b/aboutdialog/aboutdialog.cpp @@ -1,7 +1,7 @@ #include "./aboutdialog.h" #include "../misc/dialogutils.h" -#include "gui/ui_aboutdialog.h" +#include "ui_aboutdialog.h" #include #include diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..2f9ca46 --- /dev/null +++ b/config.h.in @@ -0,0 +1,9 @@ +#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 diff --git a/enterpassworddialog/enterpassworddialog.cpp b/enterpassworddialog/enterpassworddialog.cpp index 4968613..f97f181 100644 --- a/enterpassworddialog/enterpassworddialog.cpp +++ b/enterpassworddialog/enterpassworddialog.cpp @@ -1,7 +1,7 @@ #include "./enterpassworddialog.h" #include "../misc/dialogutils.h" -#include "gui/ui_enterpassworddialog.h" +#include "ui_enterpassworddialog.h" #include #include @@ -301,15 +301,15 @@ void EnterPasswordDialog::confirm() * \brief Returns an indication whether the capslock key is pressed using platform specific functions. * * \remarks - Returns always false for unsupported platforms. - * - This method is only avialable if the library is built with + * - This method always returns false when not built with * PLATFORM_SPECIFIC_CAPSLOCK_DETECTION defined. * - This static function will be used internally to detect whether the capslock key is pressed * when initializing the dialog if available. - * - The function requires the application to be linked against X11 on Linux/Unix/Max OS X. + * - The function requires the application to be linked against X11 on Linux/Unix. */ -#ifdef PLATFORM_SPECIFIC_CAPSLOCK_DETECTION bool EnterPasswordDialog::isCapslockPressed() { +#ifdef PLATFORM_SPECIFIC_CAPSLOCK_DETECTION // platform dependent method of determining if CAPS LOCK is pressed # if defined(Q_OS_WIN32) return GetKeyState(VK_CAPITAL) == 1; @@ -325,7 +325,8 @@ bool EnterPasswordDialog::isCapslockPressed() # else return false; # endif -} + return false; #endif +} } diff --git a/enterpassworddialog/enterpassworddialog.h b/enterpassworddialog/enterpassworddialog.h index 79912d8..c58d5c7 100644 --- a/enterpassworddialog/enterpassworddialog.h +++ b/enterpassworddialog/enterpassworddialog.h @@ -40,9 +40,7 @@ public: void setPasswordRequired(bool value); const QString &instruction() const; void setInstruction(const QString &value); -#ifdef PLATFORM_SPECIFIC_CAPSLOCK_DETECTION static bool isCapslockPressed(); -#endif protected: bool event(QEvent *event); diff --git a/general.pri b/general.pri index 60bf445..6e654cd 100644 --- a/general.pri +++ b/general.pri @@ -1,5 +1,4 @@ #dirs -UI_DIR = ./gui MOC_DIR = ./moc OBJECTS_DIR = ./obj RCC_DIR = ./res @@ -18,6 +17,7 @@ CONFIG(debug, debug|release) { TARGET = $${targetprefix}$${projectname} } # add defines +DEFINES += "APP_METADATA_AVAIL" DEFINES += "'PROJECT_NAME=\"$${projectname}\"'" DEFINES += "'APP_NAME=\"$${appname}\"'" DEFINES += "'APP_AUTHOR=\"$${appauthor}\"'" diff --git a/settingsdialog/settingsdialog.cpp b/settingsdialog/settingsdialog.cpp index 55b3f85..f143620 100644 --- a/settingsdialog/settingsdialog.cpp +++ b/settingsdialog/settingsdialog.cpp @@ -7,7 +7,7 @@ #include "../misc/dialogutils.h" -#include "gui/ui_settingsdialog.h" +#include "ui_settingsdialog.h" #include #include