Skip to content

Commit

Permalink
PR408: Migrate from qmake to CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
zjeffer committed Dec 30, 2022
1 parent 7f71dae commit d759ca1
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 277 deletions.
30 changes: 16 additions & 14 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
QT_PKGS: ${{ matrix.qt-version-major == '6' && 'qt6-base-private-dev libgl-dev' || 'qtbase5-private-dev' }}
run: |
sudo apt update
sudo apt install -y build-essential qtchooser ${{ env.QT_PKGS }}
sudo apt install -y build-essential cmake ninja-build ${{ env.QT_PKGS }}
- name: Setup GCC problem matcher
if: matrix.build-type == 'debug'
Expand All @@ -70,11 +70,9 @@ jobs:
run: |
mkdir build
cd build
# Workaround for qtchooser not supporting Qt 6: https://bugs.launchpad.net/ubuntu/+source/qtchooser/+bug/1964763
echo -e '/usr/lib/qt6/bin\n/usr/lib/x86_64-linux-gnu' | sudo tee /usr/lib/x86_64-linux-gnu/qtchooser/qt6.conf
export QT_SELECT=qt${{ matrix.qt-version-major }}
qmake -config ${{ matrix.build-type }} ../src/Notes.pro
make -j$(nproc)
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.build-type }}
export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc)
cmake --build .
# Build the AppImage using official Qt releases, downloaded by aqtinstall.
# This is also done for macOS and Windows, just to make sure we use the exact same Qt version across all three OSes.
Expand Down Expand Up @@ -112,20 +110,23 @@ jobs:
apt update
- name: Install other dependencies in docker container
# - cmake: Used to build the application
# - curl: Used to download the linuxdeploy AppImage tool.
# - git: Self-explanatory.
# - libfontconfig1: Used as dependency of the resulting AppImage.
# - ninja-build: needed by cmake
# - python3/python3-pip: Used by aqtinstall.
# - sudo: Used by most GitHub actions to install things.
if: matrix.container != ''
run: |
apt update
apt install -y curl git libfontconfig1 python3 python3-pip sudo
# Upgrade to the latest setuptools, as Ubuntu's python3-setuptools package has compatibility issues with aqtinstall.
python3 -m pip install --upgrade setuptools
# Configure the timezone, otherwise 'install-qt-action' gets stuck at 'configuring tzdata'.
ln -sf /usr/share/zoneinfo/UTC /etc/localtime
echo UTC > /etc/timezone
# install packages
apt update
apt install -y cmake curl git libfontconfig1 ninja-build python3 python3-pip sudo
# Upgrade to the latest setuptools, as Ubuntu's python3-setuptools package has compatibility issues with aqtinstall.
python3 -m pip install --upgrade setuptools
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -135,12 +136,12 @@ jobs:
- name: Update version
shell: bash
run: |
sed -i.bak "/^VERSION *=/ s/$/-g${GITHUB_SHA::7}/" src/Notes.pro
sed -i.bak "s/PROJECT_VERSION *[^)]\+/&-g${GITHUB_SHA::7}/" CMakeLists.txt
- name: Setup variables
id: vars
run: |
version=$(grep -m 1 VERSION src/Notes.pro | sed 's/^VERSION *= *//')
version=$(grep -m 1 'PROJECT_VERSION' CMakeLists.txt | sed 's/.*PROJECT_VERSION *//' | sed 's/).*//')
artifact_name="Notes_${version}-x86_64-Qt${{ matrix.qt-version }}"
file_name="$artifact_name${{ matrix.build-type == 'debug' && '-debug.' || '.' }}AppImage"
echo "version=$version" >> $GITHUB_OUTPUT
Expand All @@ -166,8 +167,9 @@ jobs:
run: |
mkdir build
cd build
qmake -config ${{ matrix.build-type }} ../src/Notes.pro
make -j$(nproc)
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.build-type }}
export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc)
cmake --build .
- name: Setup linuxdeploy
run: |
Expand Down
34 changes: 20 additions & 14 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ jobs:
submodules: recursive

- name: Install Qt ${{ matrix.qt-version-major }} (homebrew)
env:
# TODO: remove once https://github.com/actions/setup-python/issues/577 gets fixed.
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
run: |
brew update
brew install qt@${{ matrix.qt-version-major }}
brew install ninja qt@${{ matrix.qt-version-major }}
- name: Configure Qt ${{ matrix.qt-version-major }} (homebrew)
run: |
Expand All @@ -47,10 +50,9 @@ jobs:

- name: Build (${{ matrix.build-type }})
run: |
mkdir build
cd build
qmake -config ${{ matrix.build-type }} ../src/Notes.pro
make -j$(sysctl -n hw.logicalcpu)
export CMAKE_BUILD_PARALLEL_LEVEL=$(sysctl -n hw.logicalcpu)
cmake . -G Ninja -B build -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DCMAKE_PREFIX_PATH="$(brew --prefix qt@${{ matrix.qt-version-major }})"
cmake --build build
# Build the dmg disk image using the official Qt 5 release downloaded by aqtinstall.
# This is also done for Linux and Windows, just to make sure we use the exact same Qt version across all three OSes.
Expand Down Expand Up @@ -78,12 +80,12 @@ jobs:

- name: Update version
run: |
sed -i.bak "/^VERSION *=/ s/$/-g${GITHUB_SHA::7}/" src/Notes.pro
sed -i.bak "s/PROJECT_VERSION *[^)]\+/&-g${GITHUB_SHA::7}/" CMakeLists.txt
- name: Setup variables
id: vars
run: |
version=$(grep -m 1 VERSION src/Notes.pro | sed 's/^VERSION *= *//')
version=$(grep -m 1 'PROJECT_VERSION' CMakeLists.txt | sed 's/.*PROJECT_VERSION *//' | sed 's/).*//')
artifact_name="Notes_${version}-x86_64-Qt${{ matrix.qt-version }}"
file_name="$artifact_name${{ matrix.build-type == 'debug' && '-debug.' || '.' }}dmg"
echo "version=$version" >> $GITHUB_OUTPUT
Expand All @@ -96,23 +98,27 @@ jobs:
version: ${{ matrix.qt-version }}
cache: true

- name: Install Ninja
run: |
brew update
brew install ninja
- name: Build (${{ matrix.build-type }})
run: |
mkdir build
cd build
qmake -config ${{ matrix.build-type }} ../src/Notes.pro
make -j$(sysctl -n hw.logicalcpu)
export CMAKE_BUILD_PARALLEL_LEVEL=$(sysctl -n hw.logicalcpu)
cmake . -G Ninja -B build -DCMAKE_BUILD_TYPE=${{ matrix.build-type }}
cmake --build build
- name: Build dmg (${{ matrix.build-type }})
run: |
cd bin
cd build
plutil -insert NSRequiresAquaSystemAppearance -bool true Notes.app/Contents/Info.plist
plutil -insert CFBundleName -string Notes Notes.app/Contents/Info.plist
plutil -replace CFBundleName -string Notes Notes.app/Contents/Info.plist
macdeployqt Notes.app -dmg
mv Notes.dmg '${{ steps.vars.outputs.file_name }}'
- name: Upload dmg artifact (${{ matrix.build-type }})
uses: actions/upload-artifact@v3
with:
name: ${{ steps.vars.outputs.artifact_name }}-${{ runner.os }}-${{ matrix.build-type }}
path: bin/${{ steps.vars.outputs.file_name }}
path: build/${{ steps.vars.outputs.file_name }}
16 changes: 7 additions & 9 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ jobs:

- name: Update version
run: |
(Get-Content src\Notes.pro) -Replace '^VERSION *= *(.+)$',"`$0-g$($env:GITHUB_SHA.Substring(0,7))" | Set-Content src\Notes.pro
(Get-Content CMakeLists.txt) -Replace ("PROJECT_VERSION *[^)]+", "`$0-g$($env:GITHUB_SHA.Substring(0,7))") | Set-Content CMakeLists.txt
- name: Setup variables
id: vars
run: |
$version = Select-String -Path src\Notes.pro -Pattern '^VERSION *= *(.+)$' | %{$_.Matches.Groups[1].value}
$version = Select-String -Path CMakeLists.txt -Pattern 'PROJECT_VERSION *([^)]+)' | %{$_.Matches.Groups[1].value}
$artifact_name = "Notes_$version-${{ matrix.arch }}-Qt${{ matrix.qt-version }}"
Write-Output "version=$version" >> $env:GITHUB_OUTPUT
Write-Output "artifact_name=$artifact_name" >> $env:GITHUB_OUTPUT
Expand All @@ -64,18 +64,16 @@ jobs:

- name: Build (${{ matrix.build-type }}, ${{ matrix.arch }})
run: |
New-Item build -ItemType Directory
Set-Location build
qmake -config ${{ matrix.build-type }} ..\src\Notes.pro
nmake
cmake . -B build -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.build-type }}
cmake --build build
- name: Deploy (${{ matrix.build-type }}, ${{ matrix.arch }})
run: |
windeployqt bin
windeployqt build
- name: Include required runtime libraries (${{ matrix.build-type }}, ${{ matrix.arch }})
run: |
Set-Location bin
Set-Location build
if ('${{ matrix.arch }}' -ieq 'x64') {
$openssl_lib_suffix = '-x64'
Expand Down Expand Up @@ -114,7 +112,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: ${{ steps.vars.outputs.artifact_name }}-${{ runner.os }}-${{ matrix.build-type }}
path: bin
path: build

unified-installer:
name: Unified x64-x86 Installer (Qt 5 only)
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ bin*
######################
.DS_Store*
.vscode/
.cache/
ehthumbs.db
Thumbs.db
Makefile
Expand Down
186 changes: 186 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
cmake_minimum_required(VERSION 3.10)
project(notes LANGUAGES CXX)
set (PROJECT_VERSION 2.0.0)
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

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

if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()

set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}")

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)

if (NOT DEFINED QT_VERSION_MAJOR)
# message(FATAL_ERROR "Qt not found.")
message("Qt not found.")
else()
message("Using QT_VERSION_MAJOR: ${QT_VERSION_MAJOR}")
endif()

find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Concurrent Gui Network Sql Widgets Test)

set (GENERAL_PROJECT_SOURCES
${PROJECT_SOURCE_DIR}/src/aboutwindow.cpp
${PROJECT_SOURCE_DIR}/src/allnotebuttontreedelegateeditor.cpp
${PROJECT_SOURCE_DIR}/src/customapplicationstyle.cpp
${PROJECT_SOURCE_DIR}/src/customdocument.cpp
${PROJECT_SOURCE_DIR}/src/dbmanager.cpp
${PROJECT_SOURCE_DIR}/src/defaultnotefolderdelegateeditor.cpp
${PROJECT_SOURCE_DIR}/src/editorsettingsbutton.cpp
${PROJECT_SOURCE_DIR}/src/elidedlabel.cpp
${PROJECT_SOURCE_DIR}/src/foldertreedelegateeditor.cpp
${PROJECT_SOURCE_DIR}/src/labeledittype.cpp
${PROJECT_SOURCE_DIR}/src/listviewlogic.cpp
${PROJECT_SOURCE_DIR}/src/main.cpp
${PROJECT_SOURCE_DIR}/src/mainwindow.cpp
${PROJECT_SOURCE_DIR}/src/nodedata.cpp
${PROJECT_SOURCE_DIR}/src/nodepath.cpp
${PROJECT_SOURCE_DIR}/src/nodetreedelegate.cpp
${PROJECT_SOURCE_DIR}/src/nodetreemodel.cpp
${PROJECT_SOURCE_DIR}/src/nodetreeview.cpp
${PROJECT_SOURCE_DIR}/src/noteeditorlogic.cpp
${PROJECT_SOURCE_DIR}/src/notelistdelegate.cpp
${PROJECT_SOURCE_DIR}/src/notelistdelegateeditor.cpp
${PROJECT_SOURCE_DIR}/src/notelistmodel.cpp
${PROJECT_SOURCE_DIR}/src/notelistview.cpp
${PROJECT_SOURCE_DIR}/src/pushbuttontype.cpp
${PROJECT_SOURCE_DIR}/src/singleinstance.cpp
${PROJECT_SOURCE_DIR}/src/splitterstyle.cpp
${PROJECT_SOURCE_DIR}/src/styleeditorwindow.cpp
${PROJECT_SOURCE_DIR}/src/tagdata.cpp
${PROJECT_SOURCE_DIR}/src/taglistdelegate.cpp
${PROJECT_SOURCE_DIR}/src/taglistmodel.cpp
${PROJECT_SOURCE_DIR}/src/taglistview.cpp
${PROJECT_SOURCE_DIR}/src/tagpool.cpp
${PROJECT_SOURCE_DIR}/src/tagtreedelegateeditor.cpp
${PROJECT_SOURCE_DIR}/src/trashbuttondelegateeditor.cpp
${PROJECT_SOURCE_DIR}/src/treeviewlogic.cpp
${PROJECT_SOURCE_DIR}/src/updaterwindow.cpp
# ui
${PROJECT_SOURCE_DIR}/src/aboutwindow.ui
${PROJECT_SOURCE_DIR}/src/mainwindow.ui
${PROJECT_SOURCE_DIR}/src/styleeditorwindow.ui
${PROJECT_SOURCE_DIR}/src/updaterwindow.ui
# 3rdParty ui
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qplaintexteditsearchwidget.ui
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/Downloader.ui
# 3rdParty source files
${PROJECT_SOURCE_DIR}/3rdParty/qautostart/src/qautostart.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qautostart/src/qautostart.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/markdownhighlighter.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qmarkdowntextedit.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qownlanguagedata.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qplaintexteditsearchwidget.cpp
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/Downloader.cpp
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/QSimpleUpdater.cpp
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/Updater.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobal.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobalshortcut.cpp
# qrc files
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/media.qrc
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/etc/resources/qsimpleupdater.qrc
${PROJECT_SOURCE_DIR}/src/fonts.qrc
${PROJECT_SOURCE_DIR}/src/images.qrc
${PROJECT_SOURCE_DIR}/src/styles.qrc
)

file (GLOB_RECURSE HEADERS
${PROJECT_SOURCE_DIR}/3rdParty/qautostart/qautostart.h
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/linenumberarea.h
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/markdownhighlighter.h
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qmarkdowntextedit.h
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qownlanguagedata.h
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qplaintexteditsearchwidget.h
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/include/*.h
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/*.h
${PROJECT_SOURCE_DIR}/3rdParty/qxt/*.h
${PROJECT_SOURCE_DIR}/src/*.h
)

set (MACX_PROJECT_SOURCES
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobalshortcut_mac.cpp
${PROJECT_SOURCE_DIR}/src/framelesswindow.mm
)

set (WIN32_PROJECT_SOURCES
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobalshortcut_win.cpp
${PROJECT_SOURCE_DIR}/src/framelesswindow.cpp
)

set (LINUX_PROJECT_SOURCES
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobalshortcut_x11.cpp
)


add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE ${GENERAL_PROJECT_SOURCES} ${HEADERS})

target_include_directories(${PROJECT_NAME} PUBLIC
${PROJECT_SOURCE_DIR}/src/
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/include
${PROJECT_SOURCE_DIR}/3rdParty/qautostart/src
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit
${PROJECT_SOURCE_DIR}/3rdParty/qxt
)

target_compile_definitions(${PROJECT_NAME} PUBLIC
APP_VERSION="2.0.0"
QSU_INCLUDE_MOC=1
QT_DISABLE_DEPRECATED_BEFORE=0x050900
)


target_link_libraries(${PROJECT_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::Concurrent
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::CorePrivate
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::GuiPrivate
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Sql
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::WidgetsPrivate
)

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_sources(${PROJECT_NAME} PUBLIC ${MACX_PROJECT_SOURCES})

target_link_libraries(${PROJECT_NAME} PUBLIC
"-framework Carbon"
"-framework Cocoa"
)
elseif(UNIX)
target_sources(${PROJECT_NAME} PUBLIC ${LINUX_PROJECT_SOURCES})

target_link_libraries(${PROJECT_NAME} PUBLIC
X11
)
elseif (WIN32)
target_sources(${PROJECT_NAME} PUBLIC ${WIN32_PROJECT_SOURCES})

target_compile_definitions(${PROJECT_NAME} PUBLIC
QXT_STATIC
)

target_link_libraries(${PROJECT_NAME} PUBLIC
user32
)

# windows outputs to build/<Debug/Release> folder for some reason
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
endif()



install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)
Loading

0 comments on commit d759ca1

Please sign in to comment.