Skip to content

Commit

Permalink
#136: Move from qmake to CMake (#166)
Browse files Browse the repository at this point in the history
# Description

This commit switches the project's build system from qmake to CMake.

Using CMake has several advantages:
* Looking forward, Qt 6 uses CMake by default. It will be easier to
migrate to Qt 6 with CMake as the default build system.
* CMake is essentially an industry standard for C++ projects. This is a
good learning opportunity, and because there are many people using
CMake, it is easy to find resources for most edge-cases.
* Automatic discovery of tests whose build system is CMake-by-default.

Part of a series of commits for #136.

## Type of change

- [x] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [x] This change requires a documentation update

# How Has This Been Tested?

Tested by building debug builds on macOS, Windows, and Linux. Packaging
for release has not yet been tested, and will be tested once a release
is closer.

# Checklist:

- [x] My code follows the style guidelines of this project (`black` for
Python
  code, `.clang-format` in the `src/jyut-dict` directory for C++)
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have translated my user-facing strings to all
currently-supported languages
- [x] I have made corresponding changes to the documentation
aaronhktan authored Mar 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent f5f7bd6 commit 83e44f0
Showing 7 changed files with 238 additions and 374 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Aaron Tan
Copyright (c) 2024 Aaron Tan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ craft libs/qt/qtspeech
craft karchive
```
3. Set up Qt Creator with a kit from Craft, following instructions [here](https://community.kde.org/Craft#Using_Craft_with_an_IDE).
4. Open Jyut Dictionary in Qt Creator, and add DEFINES+="PORTABLE" to the QMake configuration if you would like to isolate your debug build from any system files.
4. Open CMakeLists.txt in Qt Creator, and define `CMAKE_CXX_FLAGS` as `-DPORTABLE -DDEBUG` in the CMake configuration if you would like to isolate your debug build from any system files.
5. Compile and run!

#### Ubuntu: Manual Git clone + Qt Creator
@@ -108,7 +108,7 @@ cmake .. -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX=~/Qt/5.15.2/gcc_64
make
sudo make install
```
3. Open Jyut Dictionary in Qt Creator, and add DEFINES+="PORTABLE" to the QMake configuration if you would like to isolate your debug build from any system files.
3. Open CMakeLists.txt in Qt Creator, and define `CMAKE_CXX_FLAGS` as `-DPORTABLE -DDEBUG` in the CMake configuration if you would like to isolate your debug build from any system files.
4. Compile and run!

## Packaging for release
232 changes: 232 additions & 0 deletions src/jyut-dict/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
cmake_minimum_required(VERSION 3.5)

project(CantoneseDictionary VERSION 2.23.0408 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS
LinguistTools
Multimedia
Network
Sql
Svg
TextToSpeech
Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS
LinguistTools
Multimedia
Network
Sql
Svg
TextToSpeech
Widgets)
find_package(KF5Archive)

set(TS_FILES
resources/translations/jyutdictionary-en.ts
resources/translations/jyutdictionary-fr.ts
resources/translations/jyutdictionary-fr_CA.ts
resources/translations/jyutdictionary-yue_Hans.ts
resources/translations/jyutdictionary-yue_Hant.ts
resources/translations/jyutdictionary-zh_Hans.ts
resources/translations/jyutdictionary-zh_Hant.ts
resources/translations/jyutdictionary-zh_Hans_HK.ts
resources/translations/jyutdictionary-zh_Hant_HK.ts)

set(PROJECT_SOURCES
components/definitioncard/definitioncardsection.cpp
components/definitioncard/definitioncardwidget.cpp
components/definitioncard/definitioncontentwidget.cpp
components/definitioncard/definitionheaderwidget.cpp
components/dictionarylist/dictionarylistdelegate.cpp
components/dictionarylist/dictionarylistmodel.cpp
components/dictionarylist/dictionarylistview.cpp
components/entrysearchresult/resultlistdelegate.cpp
components/entrysearchresult/resultlistmodel.cpp
components/entrysearchresult/resultlistview.cpp
components/entryview/entryactionwidget.cpp
components/entryview/entrycontentwidget.cpp
components/entryview/entryheaderwidget.cpp
components/entryview/entryscrollarea.cpp
components/entryview/entryscrollareawidget.cpp
components/entryview/entryviewsentencecardsection.cpp
components/favouritewindow/favouritesplitter.cpp
components/historyview/searchhistorylistdelegate.cpp
components/historyview/searchhistorylistmodel.cpp
components/historyview/searchhistorylistview.cpp
components/historyview/searchhistorytab.cpp
components/historyview/viewhistorylistdelegate.cpp
components/historyview/viewhistorylistmodel.cpp
components/historyview/viewhistorylistview.cpp
components/historyview/viewhistorytab.cpp
components/layouts/flowlayout.cpp
components/magnifywindow/magnifyscrollarea.cpp
components/magnifywindow/magnifyscrollareawidget.cpp
components/mainwindow/mainsplitter.cpp
components/mainwindow/maintoolbar.cpp
components/mainwindow/searchlineedit.cpp
components/mainwindow/searchoptionsradiogroupbox.cpp
components/related/relatedbutton.cpp
components/related/relatedbuttoncontentwidget.cpp
components/related/relatedbuttonheaderwidget.cpp
components/related/relatedsection.cpp
components/sentencecard/loadingwidget.cpp
components/sentencecard/sentencecardwidget.cpp
components/sentencecard/sentencecontentwidget.cpp
components/sentencecard/sentenceheaderwidget.cpp
components/sentencesearchresult/sentenceresultlistdelegate.cpp
components/sentencesearchresult/sentenceresultlistmodel.cpp
components/sentencesearchresult/sentenceresultlistview.cpp
components/sentenceview/sentencescrollarea.cpp
components/sentenceview/sentencescrollareawidget.cpp
components/sentenceview/sentenceviewcontentwidget.cpp
components/sentenceview/sentenceviewheaderwidget.cpp
components/sentenceview/sentenceviewsentencecardsection.cpp
components/sentencewindow/sentencesplitter.cpp
components/settings/advancedtab.cpp
components/settings/contacttab.cpp
components/settings/dictionarytab.cpp
components/settings/settingstab.cpp
components/settings/texttab.cpp
dialogs/defaultdialog.cpp
dialogs/dictionarytabfailuredialog.cpp
dialogs/downloadaudiodialog.cpp
dialogs/downloadresultdialog.cpp
dialogs/entryspeakerrordialog.cpp
dialogs/exportdatabasedialog.cpp
dialogs/noupdatedialog.cpp
dialogs/overwriteconflictingdictionarydialog.cpp
dialogs/resetsettingsdialog.cpp
dialogs/restoredatabasedialog.cpp
logic/database/queryparseutils.cpp
logic/database/sqldatabasemanager.cpp
logic/database/sqldatabaseutils.cpp
logic/database/sqluserdatautils.cpp
logic/database/sqluserhistoryutils.cpp
logic/dictionary/dictionarymetadata.cpp
logic/dictionary/dictionarysource.cpp
logic/download/downloader.cpp
logic/entry/definitionsset.cpp
logic/entry/entry.cpp
logic/entry/entryspeaker.cpp
logic/search/searchoptionsmediator.cpp
logic/search/sqlsearch.cpp
logic/sentence/sentenceset.cpp
logic/sentence/sourcesentence.cpp
logic/settings/settings.cpp
logic/settings/settingsutils.cpp
logic/update/jyutdictionaryreleasechecker.cpp
logic/utils/chineseutils.cpp
logic/utils/scriptdetector.cpp
logic/utils/utils.cpp
logic/utils/utils_qt.cpp
main.cpp
windows/aboutwindow.cpp
windows/historywindow.cpp
windows/mainwindow.cpp
windows/settingswindow.cpp
windows/updatewindow.cpp
${TS_FILES}
)

include_directories(
${CMAKE_SOURCE_DIR}
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(CantoneseDictionary
MANUAL_FINALIZATION
${PROJECT_SOURCES}
resources/resource.qrc
)

# qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
else()
add_executable(CantoneseDictionary
${PROJECT_SOURCES}
resources/resource.qrc
)

# qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
endif()

target_link_libraries(CantoneseDictionary
PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
PRIVATE Qt${QT_VERSION_MAJOR}::Multimedia
PRIVATE Qt${QT_VERSION_MAJOR}::Network
PRIVATE Qt${QT_VERSION_MAJOR}::Sql
PRIVATE Qt${QT_VERSION_MAJOR}::Svg
PRIVATE Qt${QT_VERSION_MAJOR}::TextToSpeech
PRIVATE KF5::Archive
)

add_subdirectory(
logic/utils/test/TestChineseUtils
)
add_subdirectory(
logic/utils/test/TestScriptDetector
)

set_target_properties(CantoneseDictionary PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/platform/mac/Info.plist
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)

if (APPLE)
target_link_libraries(CantoneseDictionary PRIVATE "-framework AppKit")
TARGET_SOURCES(CantoneseDictionary
PRIVATE logic/utils/utils_mac.mm
PRIVATE resources/db/dict.db
PRIVATE resources/db/user.db
PRIVATE resources/licenses/FLOW_LAYOUT_LICENSE.txt
PRIVATE resources/settings/settings.ini
PRIVATE resources/icon/icon.icns
PRIVATE platform/mac/en.lproj/InfoPlist.strings
PRIVATE platform/mac/fr.lproj/InfoPlist.strings
PRIVATE platform/mac/yue_Hans.lproj/InfoPlist.strings
PRIVATE platform/mac/yue_Hant.lproj/InfoPlist.strings
PRIVATE platform/mac/zh_Hans.lproj/InfoPlist.strings
PRIVATE platform/mac/zh_Hant.lproj/InfoPlist.strings)

set_property(SOURCE resources/db/dict.db PROPERTY MACOSX_PACKAGE_LOCATION "Resources")
set_property(SOURCE resources/db/user.db PROPERTY MACOSX_PACKAGE_LOCATION "Resources")
set_property(SOURCE resources/licenses/FLOW_LAYOUT_LICENSE.txt PROPERTY MACOSX_PACKAGE_LOCATION "Resources/Licenses")
set_property(SOURCE resources/settings/settings.ini PROPERTY MACOSX_PACKAGE_LOCATION "Resources")
set_property(SOURCE resources/icon/icon.icns PROPERTY MACOSX_PACKAGE_LOCATION "Resources")
set_property(SOURCE platform/mac/en.lproj/InfoPlist.strings PROPERTY MACOSX_PACKAGE_LOCATION "Resources/en.lproj")
set_property(SOURCE platform/mac/fr.lproj/InfoPlist.strings PROPERTY MACOSX_PACKAGE_LOCATION "Resources/fr.lproj")
set_property(SOURCE platform/mac/yue_Hans.lproj/InfoPlist.strings PROPERTY MACOSX_PACKAGE_LOCATION "Resources/yue-Hans.lproj")
set_property(SOURCE platform/mac/yue_Hant.lproj/InfoPlist.strings PROPERTY MACOSX_PACKAGE_LOCATION "Resources/yue-Hant.lproj")
set_property(SOURCE platform/mac/zh_Hans.lproj/InfoPlist.strings PROPERTY MACOSX_PACKAGE_LOCATION "Resources/zh-hans.lproj")
set_property(SOURCE platform/mac/zh_Hant.lproj/InfoPlist.strings PROPERTY MACOSX_PACKAGE_LOCATION "Resources/zh-hant.lproj")
elseif (UNIX)
TARGET_SOURCES(CantoneseDictionary PRIVATE logic/utils/utils_linux.cpp)
configure_file(resources/db/dict.db dict.db COPYONLY)
configure_file(resources/db/user.db user.db COPYONLY)
configure_file(resources/licenses/FLOW_LAYOUT_LICENSE.txt FLOW_LAYOUT_LICENSE.txt COPYONLY)
configure_file(resources/settings/settings.ini settings.ini COPYONLY)
elseif (WIN32)
enable_language("RC")
TARGET_SOURCES(CantoneseDictionary PRIVATE
logic/utils/utils_windows.cpp
platform/windows/app.rc)
configure_file(resources/db/dict.db dict.db COPYONLY)
configure_file(resources/db/user.db user.db COPYONLY)
configure_file(resources/licenses/FLOW_LAYOUT_LICENSE.txt FLOW_LAYOUT_LICENSE.txt COPYONLY)
configure_file(resources/settings/settings.ini settings.ini COPYONLY)
endif()

install(TARGETS CantoneseDictionary
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(test)
endif()

370 changes: 0 additions & 370 deletions src/jyut-dict/jyut-dict.pro

This file was deleted.

2 changes: 1 addition & 1 deletion src/jyut-dict/platform/mac/Info.plist
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
<key>CFBundleIdentifier</key>
<string>com.aaronhktan.cantonesedictionary</string>
<key>CFBundleExecutable</key>
<string>MacOS/Jyut Dictionary</string>
<string>MacOS/CantoneseDictionary</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleInfoDictionaryVersion</key>
2 changes: 2 additions & 0 deletions src/jyut-dict/platform/windows/app.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

IDI_ICON1 ICON "icon.ico"
Binary file added src/jyut-dict/platform/windows/icon.ico
Binary file not shown.

0 comments on commit 83e44f0

Please sign in to comment.