diff --git a/20-q1/Using Cmake With Qt/CMakeLists.txt b/20-q1/Using Cmake With Qt/CMakeLists.txt new file mode 100644 index 0000000..7a087dc --- /dev/null +++ b/20-q1/Using Cmake With Qt/CMakeLists.txt @@ -0,0 +1,52 @@ +cmake_minimum_required(VERSION 3.5) + +project(ucwqt VERSION "1.0.0" LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) +include(QtCommon) + +fix_project_version() +set(RES_FILES) +add_project_meta(RES_FILES) +# QtCreator supports the following variables for Android, which are identical to qmake Android variables. +# Check http://doc.qt.io/qt-5/deployment-android.html for more information. +# They need to be set before the find_package(Qt5 ...) call. + +#if(ANDROID) +# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") +# if (ANDROID_ABI STREQUAL "armeabi-v7a") +# set(ANDROID_EXTRA_LIBS +# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so +# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so) +# endif() +#endif() + +find_package(Qt5 COMPONENTS Widgets LinguistTools REQUIRED) + +set(TS_FILES ucwqt_zh_CN.ts) + +if(ANDROID) + add_library(ucwqt SHARED + main.cpp + MainWindow.cpp + MainWindow.h + MainWindow.ui + ${TS_FILES} + ${RES_FILES} + ) +else() + add_executable(ucwqt + main.cpp + MainWindow.cpp + MainWindow.h + MainWindow.ui + ${TS_FILES} + ${RES_FILES} + ) +endif() + +target_link_libraries(ucwqt PRIVATE Qt5::Widgets) + +qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) diff --git a/20-q1/Using Cmake With Qt/CMakeLists.txt.user b/20-q1/Using Cmake With Qt/CMakeLists.txt.user new file mode 100644 index 0000000..b672149 --- /dev/null +++ b/20-q1/Using Cmake With Qt/CMakeLists.txt.user @@ -0,0 +1,348 @@ + + + + + + EnvironmentId + {0329f3a9-5c08-4d73-8025-84a220fe49ab} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.12.5 MSVC2017 64bit + Desktop Qt 5.12.5 MSVC2017 64bit + qt.qt5.5125.win64_msvc2017_64_kit + 0 + 0 + 0 + + + CMAKE_BUILD_TYPE:STRING=Debug + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/mypack/blog/20.03/build-ucwqt-Desktop_Qt_5_12_5_MSVC2017_64bit-Debug + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/mypack/blog/20.03/build-ucwqt-Desktop_Qt_5_12_5_MSVC2017_64bit-Release + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/mypack/blog/20.03/build-ucwqt-Desktop_Qt_5_12_5_MSVC2017_64bit-RelWithDebInfo + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=MinSizeRel + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/mypack/blog/20.03/build-ucwqt-Desktop_Qt_5_12_5_MSVC2017_64bit-MinSizeRel + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + ucwqt + CMakeProjectManager.CMakeRunConfiguration.ucwqt + ucwqt + + false + + false + true + true + false + false + true + + D:/mypack/blog/20.03/build-ucwqt-Desktop_Qt_5_12_5_MSVC2017_64bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/20-q1/Using Cmake With Qt/MainWindow.cpp b/20-q1/Using Cmake With Qt/MainWindow.cpp new file mode 100644 index 0000000..9525e15 --- /dev/null +++ b/20-q1/Using Cmake With Qt/MainWindow.cpp @@ -0,0 +1,15 @@ +#include "MainWindow.h" +#include "./ui_MainWindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + diff --git a/20-q1/Using Cmake With Qt/MainWindow.h b/20-q1/Using Cmake With Qt/MainWindow.h new file mode 100644 index 0000000..4643e32 --- /dev/null +++ b/20-q1/Using Cmake With Qt/MainWindow.h @@ -0,0 +1,21 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class MainWindow; } +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private: + Ui::MainWindow *ui; +}; +#endif // MAINWINDOW_H diff --git a/20-q1/Using Cmake With Qt/MainWindow.ui b/20-q1/Using Cmake With Qt/MainWindow.ui new file mode 100644 index 0000000..b232854 --- /dev/null +++ b/20-q1/Using Cmake With Qt/MainWindow.ui @@ -0,0 +1,22 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + + + diff --git a/20-q1/Using Cmake With Qt/MyClass.cpp b/20-q1/Using Cmake With Qt/MyClass.cpp new file mode 100644 index 0000000..fae04e5 --- /dev/null +++ b/20-q1/Using Cmake With Qt/MyClass.cpp @@ -0,0 +1,6 @@ +#include "MyClass.h" + +MyClass::MyClass(QObject *parent) : QObject(parent) +{ + +} diff --git a/20-q1/Using Cmake With Qt/MyClass.h b/20-q1/Using Cmake With Qt/MyClass.h new file mode 100644 index 0000000..bff59bc --- /dev/null +++ b/20-q1/Using Cmake With Qt/MyClass.h @@ -0,0 +1,16 @@ +#ifndef MYCLASS_H +#define MYCLASS_H + +#include + +class MyClass : public QObject +{ + Q_OBJECT +public: + explicit MyClass(QObject *parent = nullptr); + +signals: + +}; + +#endif // MYCLASS_H diff --git a/20-q1/Using Cmake With Qt/cmake/QtCommon.cmake b/20-q1/Using Cmake With Qt/cmake/QtCommon.cmake new file mode 100644 index 0000000..b338409 --- /dev/null +++ b/20-q1/Using Cmake With Qt/cmake/QtCommon.cmake @@ -0,0 +1,93 @@ +macro(fix_project_version) + if (NOT PROJECT_VERSION_PATCH) + set(PROJECT_VERSION_PATCH 0) + endif() + + if (NOT PROJECT_VERSION_TWEAK) + set(PROJECT_VERSION_TWEAK 0) + endif() +endmacro() + +macro(get_git_tag) + execute_process(COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_VARIABLE PACKAGE_GIT_VERSION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +endmacro(get_git_tag) + +macro(add_project_meta FILES_TO_INCLUDE) + if (NOT RESOURCE_FOLDER) + set(RESOURCE_FOLDER res) + endif() + + if (NOT ICON_NAME) + set(ICON_NAME AppIcon) + endif() + + if (APPLE) + set(ICON_FILE ${RESOURCE_FOLDER}/${ICON_NAME}.icns) + elseif (WIN32) + set(ICON_FILE ${RESOURCE_FOLDER}/${ICON_NAME}.ico) + endif() + + if (WIN32) + configure_file("${PROJECT_SOURCE_DIR}/cmake/windows_metafile.rc.in" + "windows_metafile.rc" + ) + set(RES_FILES "windows_metafile.rc") + set(CMAKE_RC_COMPILER_INIT windres) + ENABLE_LANGUAGE(RC) + # SET(CMAKE_RC_COMPILE_OBJECT " -O coff -i -o ") + endif() + + if (APPLE) + set_source_files_properties(${ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) + + # Identify MacOS bundle + set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME}) + set(MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}) + set(MACOSX_BUNDLE_LONG_VERSION_STRING ${PROJECT_VERSION}) + set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}") + set(MACOSX_BUNDLE_COPYRIGHT ${COPYRIGHT}) + set(MACOSX_BUNDLE_GUI_IDENTIFIER ${IDENTIFIER}) + set(MACOSX_BUNDLE_ICON_FILE ${ICON_NAME}) + endif() + + if (APPLE) + set(${FILES_TO_INCLUDE} ${ICON_FILE}) + elseif (WIN32) + set(${FILES_TO_INCLUDE} ${RES_FILES}) + endif() +endmacro(add_project_meta) + +macro(init_os_bundle) + if (APPLE) + set(OS_BUNDLE MACOSX_BUNDLE) + elseif (WIN32) + set(OS_BUNDLE WIN32) + endif() +endmacro(init_os_bundle) + +macro(fix_win_compiler) +if (MSVC) + set_target_properties(${PROJECT_NAME} PROPERTIES + WIN32_EXECUTABLE YES + LINK_FLAGS "/ENTRY:mainCRTStartup" + ) +endif() +endmacro() + +macro(init_qt) + # Let's do the CMake job for us + set(CMAKE_AUTOMOC ON) # For meta object compiler + set(CMAKE_AUTORCC ON) # Resource files + set(CMAKE_AUTOUIC ON) # UI files + set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD_REQUIRED ON) +endmacro() + +init_os_bundle() +init_qt() +#fix_win_compiler() diff --git a/20-q1/Using Cmake With Qt/cmake/windows_metafile.rc.in b/20-q1/Using Cmake With Qt/cmake/windows_metafile.rc.in new file mode 100644 index 0000000..c0710e5 --- /dev/null +++ b/20-q1/Using Cmake With Qt/cmake/windows_metafile.rc.in @@ -0,0 +1,29 @@ +#include "winver.h" + +IDI_ICON1 ICON DISCARDABLE "@ICON_FILE@" + +VS_VERSION_INFO VERSIONINFO + FILEVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@,@PROJECT_VERSION_TWEAK@ + PRODUCTVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@,@PROJECT_VERSION_TWEAK@ + FILEFLAGS 0x0L + FILEFLAGSMASK 0x3fL + FILEOS 0x00040004L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "CompanyName", "@COMPANY@" + VALUE "FileDescription", "@PROJECT_NAME@" + VALUE "FileVersion", "@PROJECT_VERSION@" + VALUE "LegalCopyright", "@COPYRIGHT@" + VALUE "InternalName", "@PROJECT_NAME@" + VALUE "OriginalFilename", "@PROJECT_NAME@.exe" + VALUE "ProductName", "@PROJECT_NAME@" + VALUE "ProductVersion", "@PROJECT_VERSION@" + END + END +END + diff --git a/20-q1/Using Cmake With Qt/main.cpp b/20-q1/Using Cmake With Qt/main.cpp new file mode 100644 index 0000000..0a0916f --- /dev/null +++ b/20-q1/Using Cmake With Qt/main.cpp @@ -0,0 +1,11 @@ +#include "MainWindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/20-q1/Using Cmake With Qt/res/AppIcon.ico b/20-q1/Using Cmake With Qt/res/AppIcon.ico new file mode 100644 index 0000000..35fe58c Binary files /dev/null and b/20-q1/Using Cmake With Qt/res/AppIcon.ico differ diff --git a/20-q1/Using Cmake With Qt/ucwqt_zh_CN.ts b/20-q1/Using Cmake With Qt/ucwqt_zh_CN.ts new file mode 100644 index 0000000..1f4e254 --- /dev/null +++ b/20-q1/Using Cmake With Qt/ucwqt_zh_CN.ts @@ -0,0 +1,12 @@ + + + + + MainWindow + + + MainWindow + + + +