### Sequential Build Scripts for Signed Installers Source: https://github.com/meganz/megasync/blob/master/doc/Installer_win.md Execute a sequence of scripts to prepare for creating signed installers. This involves building, gathering products, and making uninstallers before manual signing and final installer generation. ```bash $ .\production_build.cmd $ .\gather_built_products.cmd $ .\make_uninstallers.cmd ``` -------------------------------- ### Determining Installation Paths Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtNemo/CMakeLists.txt Determines the installation prefix, prioritizing the DESKTOP_DESTDIR environment variable. This is used for installing the extension and its assets. ```cmake # Determine install prefix from env vble if(DEFINED ENV{DESKTOP_DESTDIR}) set(DESKTOP_DESTDIR "$ENV{DESKTOP_DESTDIR}") else() set(DESKTOP_DESTDIR "/usr") endif() # Get nemo extensions path pkg_get_variable(EXTENSIONS_PATH ${NEMO_EXT_MODULE_NAME} extensiondir) # Strip /usr string(REGEX REPLACE "^/usr" "" RELATIVE_EXTENSIONS_PATH "${EXTENSIONS_PATH}") set(FINAL_EXT_PATH "${DESKTOP_DESTDIR}${RELATIVE_EXTENSIONS_PATH}") ``` -------------------------------- ### Execute Full Build Process Script Source: https://github.com/meganz/megasync/blob/master/doc/Installer_win.md Run the `full_build_process.cmd` script to build, sign, and create installers. This script accepts arguments for architecture, signing, core count, and an optional suffix for the installer version. ```bash "Usage: C:\mega\desktop\full_build_process.cmd [-help] [64|32/64 sign|nosign []]" Script building, signing and creating the installer(s) It can take 0, 1, 3 or 4 arguments: - -help: this message - 0 arguments: use these settings: 32/64 sign 1 - Architecture : 64 or 32/64 to build either for 64 bit or both 32 and 64 bit - Sign: sign or nosign if the binaries must be signed or not - Cores: the number of cores to build the project, or 0 for default value (4) - Suffix for installer: The installer will add this suffix to the version. [OPTIONAl] MEGA_VCPKGPATH environment variable should be set to the root of the 3rd party dir. MEGA_QTPATH environment variable should be set to the Qt install dir. Takes the value of MEGAQTPATH, or defaults to C:\Qt\5.15.17\x64 ``` -------------------------------- ### Install Qt Creator IDE Source: https://github.com/meganz/megasync/blob/master/README.linux.md Installs the Qt Creator IDE on Debian-based systems using the apt package manager. ```bash sudo apt install qtcreator ``` -------------------------------- ### Install CMake GUI Source: https://github.com/meganz/megasync/blob/master/README.mac.md Installs the CMake GUI to the system path for current user. ```bash sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install ``` -------------------------------- ### Install Nautilus Extensions Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtNautilus/CMakeLists.txt Installs the created library to the Nautilus extensions directory. ```cmake # Get nautilus extensions path pkg_get_variable(EXTENSIONS_PATH ${NAUTILUS_EXT_MODULE_NAME} extensiondir) install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${EXTENSIONS_PATH}) ``` -------------------------------- ### Download and Build System Tools Source: https://github.com/meganz/megasync/blob/master/README.mac.md Downloads, builds, and installs autoconf, automake, autoconf-archive, NASM, and pkg-config. ```bash curl -O -L https://ftpmirror.gnu.org/gnu/autoconf/autoconf-2.71.tar.xz curl -O -L https://ftpmirror.gnu.org/gnu/automake/automake-1.16.5.tar.xz curl -O -L https://ftpmirror.gnu.org/gnu/autoconf-archive/autoconf-archive-2023.02.20.tar.xz tar xzf autoconf-2.71.tar.xz tar xzf automake-1.16.5.tar.xz tar xzf autoconf-archive-2023.02.20.tar.xz cd autoconf-2.71 ./configure sudo make install cd .. cd automake-1.16.5 ./configure sudo make install cd .. cd autoconf-archive-2023.02.20 ./configure sudo make install cd .. ``` ```bash # Check that both are working autoconf --version automake --version ``` ```bash curl -O -L https://www.nasm.us/pub/nasm/releasebuilds/2.16.01/nasm-2.16.01.tar.xz curl -O -L https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz tar xzf nasm-2.16.01.tar.xz tar xzf pkg-config-0.29.2.tar.gz cd nasm-2.16.01 ./configure $make sudo make install cd .. cd pkg-config-0.29.2 ./configure --with-internal-glib make sudo make install cd .. ``` ```bash # Check that both are working nasm --version pkg-config --version ``` ```bash rm -rf autoconf* rm -rf automake* rm -rf nasm* rm -rf pkg-config* ``` -------------------------------- ### Installing the Shared Library Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtNemo/CMakeLists.txt Installs the built shared library to the determined final extension path. ```cmake install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION "${FINAL_EXT_PATH}") ``` -------------------------------- ### Example Qt Patch Organization Source: https://github.com/meganz/megasync/blob/master/contrib/build_qt/patches/readme.md A concrete example demonstrating how patches are laid out for a specific Qt version (5.15.11). It shows patches for different Qt submodules like qtbase, qtimageformats, qtmultimedia, and qtsvg, specifying their application order and target platforms. ```tree 5.15.11 ├───qtbase 00.all.CVE-2023-24607-qtbase-5.15.diff 01.all.CVE-2023-32762-qtbase-5.15.diff 02.all.CVE-2023-32763-qtbase-5.15.diff 03.all.CVE-2023-33285-qtbase-5.15.diff 04.all.CVE-2023-34410-qtbase-5.15.diff 05.all.CVE-2023-37369-qtbase-5.15.diff 06.all.CVE-2023-38197-qtbase-5.15.diff 07.all.CVE-2023-43114-5.15.patch 08.macx.QTBUG-117225-cdf64b0.diff 09.macx.QTBUG-117484-Out-standard-lib-memory-resource.patch ├───qtimageformats 00.win.CVE-2023-4863-5.15.patch ├───qtmultimedia 00.macx.Xcode15-unary_function-avfcamerautility.patch └───qtsvg 00.all.CVE-2023-32573-qtsvg-5.15.diff ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtNemo/CMakeLists.txt Sets the minimum CMake version and project name. Specifies C as the primary language. ```cmake cmake_minimum_required(VERSION 3.16.0) project(MEGAShellExtNemo LANGUAGES C) ``` -------------------------------- ### Install MEGAsync Binary and Libraries on Unix Source: https://github.com/meganz/megasync/blob/master/src/MEGASync/CMakeLists.txt Installs the MEGAsync target and its runtime libraries to the CMAKE_INSTALL_LIBDIR. Also handles the installation of the gfxworker target if it exists. ```cmake if (UNIX AND NOT APPLE) install(TARGETS MEGAsync RUNTIME) # In CMAKE_INSTALL_LIBDIR directory # Install GFX worker if needed if(TARGET gfxworker) install(TARGETS gfxworker RUNTIME) # In CMAKE_INSTALL_LIBDIR directory endif() set(vcpkg_lib_folder "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/$<$:debug/>lib/") install(DIRECTORY "${vcpkg_lib_folder}" TYPE LIB # In CMAKE_INSTALL_LIBDIR directory FILES_MATCHING PATTERN "*.so*" PATTERN "manual-link" EXCLUDE PATTERN "pkgconfig" EXCLUDE ) if(DEPLOY_QT_LIBRARIES) include(desktopapp_deploy_qt) endif() endif() ``` -------------------------------- ### Load Finder Extension (Commented Out) Source: https://github.com/meganz/megasync/blob/master/src/CMakeLists.txt This is a commented-out example for loading a Finder extension subdirectory. ```cmake if(ENABLE_FINDER_EXT) # add_subdirectory(MEGAShellExtFinder) endif() ``` -------------------------------- ### Install Icon Files Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtDolphin/CMakeLists.txt Finds and installs emblem icon files for different resolutions (32x32, 64x64) into the Hicolor icon theme directory. ```cmake #---- ICONS ---- set(HICOLOR_INSTALL_DIR ${KDE_INSTALL_FULL_ICONDIR}/hicolor) file(GLOB_RECURSE FILES32 "data/emblems/32x32/*") file(GLOB_RECURSE FILES64 "data/emblems/64x64/*") install(FILES ${FILES32} DESTINATION ${HICOLOR_INSTALL_DIR}/32x32/emblems) install(FILES ${FILES64} DESTINATION ${HICOLOR_INSTALL_DIR}/64x64/emblems) ``` -------------------------------- ### Generate Final Signed Installers Source: https://github.com/meganz/megasync/blob/master/doc/Installer_win.md Run the `make_installers.cmd` script after manually signing the binaries and copying them to the appropriate directories (`built64`, `built32`). This step generates the final signed installers. ```bash $ .\make_installers.cmd ``` -------------------------------- ### Project and Version Setup Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtDolphin/CMakeLists.txt Sets the minimum CMake version, project name, and defines variables for Qt and KDE Framework versions used throughout the build. ```cmake cmake_minimum_required(VERSION 3.16.0) project(megasync-plugin) set(KF_VER "5" CACHE STRING "") set(KF_DEP_VERSION "${KF_VER}") set(Qt_VER ${KF_VER} CACHE STRING "") ``` -------------------------------- ### Install Emblems (64x64) Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtNautilus/CMakeLists.txt Installs 64x64 pixel emblem files to the hicolor icon theme directory. ```cmake set(FILES64 ${EMBLEMS_LOC}/64x64/mega-pending.png ${EMBLEMS_LOC}/64x64/mega-pending.icon ${EMBLEMS_LOC}/64x64/mega-synced.icon ${EMBLEMS_LOC}/64x64/mega-synced.png ${EMBLEMS_LOC}/64x64/mega-syncing.icon ${EMBLEMS_LOC}/64x64/mega-syncing.png ${EMBLEMS_LOC}/64x64/mega-upload.icon ${EMBLEMS_LOC}/64x64/mega-upload.png ) install(FILES ${FILES64} DESTINATION ${HICOLOR}/64x64/emblems) ``` -------------------------------- ### Install System Build Dependencies Source: https://github.com/meganz/megasync/blob/master/README.linux.md Installs essential build tools and libraries required for compiling the MEGAsync desktop app on Debian-based systems. ```bash sudo apt install \ build-essential \ git \ cmake \ wget \ autoconf-archive \ curl \ zip \ unzip \ tar \ pkg-config \ nasm ``` ```bash sudo apt install \ libxcb-cursor0 \ qtbase5-dev \ qttools5-dev \ libqt5x11extras5-dev \ libqt5svg5-dev \ qtdeclarative5-dev \ qml-module-qtquick-dialogs \ qml-module-qtquick-controls2 ``` -------------------------------- ### Install Emblems (32x32) Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtNautilus/CMakeLists.txt Installs 32x32 pixel emblem files to the hicolor icon theme directory. ```cmake # Install emblems set(EMBLEMS_LOC ${CMAKE_CURRENT_SOURCE_DIR}/data/emblems) set(FILES32 ${EMBLEMS_LOC}/32x32/mega-pending.png ${EMBLEMS_LOC}/32x32/mega-pending.icon ${EMBLEMS_LOC}/32x32/mega-synced.icon ${EMBLEMS_LOC}/32x32/mega-synced.png ${EMBLEMS_LOC}/32x32/mega-syncing.icon ${EMBLEMS_LOC}/32x32/mega-syncing.png ${EMBLEMS_LOC}/32x32/mega-upload.icon ${EMBLEMS_LOC}/32x32/mega-upload.png ) set(HICOLOR share/icons/hicolor) install(FILES ${FILES32} DESTINATION ${HICOLOR}/32x32/emblems) ``` -------------------------------- ### Unsigned 64-bit Installer Build Source: https://github.com/meganz/megasync/blob/master/doc/Installer_win.md Build only the 64-bit installer without signing the binaries. This command specifies the architecture (64), signing preference (nosign), the number of cores to use (8), and a custom version suffix ('myBuild'). ```bash $ .\full_build_process 64 nosign 8 myBuild ``` -------------------------------- ### Installing Emblems Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtNemo/CMakeLists.txt Installs Nemo-specific emblem icons to the hicolor icon theme directory. Supports different resolutions. ```cmake # Install emblems (nemo-specific) set(EMBLEMS_LOC "${CMAKE_CURRENT_SOURCE_DIR}/data/emblems") set(HICOLOR "${DESKTOP_DESTDIR}/share/icons/hicolor") install(DIRECTORY "${EMBLEMS_LOC}/32x32/" DESTINATION "${HICOLOR}/32x32/emblems" FILES_MATCHING PATTERN "*nemo*") install(DIRECTORY "${EMBLEMS_LOC}/64x64/" DESTINATION "${HICOLOR}/64x64/emblems" FILES_MATCHING PATTERN "*nemo*") ``` -------------------------------- ### Add Action Plugin Target Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtDolphin/CMakeLists.txt Configures and builds the main action plugin using kcoreaddons_add_plugin, specifying sources and installation namespace. ```cmake #---ACTION PLUGIN--- set(MEGA_PLUGIN megasync-plugin) kcoreaddons_add_plugin(${MEGA_PLUGIN} SOURCES ${MEGA_PLUGIN_SOURCES} INSTALL_NAMESPACE "kf${KF_VER}/kfileitemaction" ) ``` -------------------------------- ### Add Overlay Icon Plugin Target Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtDolphin/CMakeLists.txt Configures and builds the overlay icon plugin using kcoreaddons_add_plugin, specifying sources and installation namespace. ```cmake #---OVERLAY PLUGIN--- set(MEGA_OVERLAYICON_PLUGIN megasync-overlay-plugin) kcoreaddons_add_plugin(${MEGA_OVERLAYICON_PLUGIN} SOURCES ${MEGA_PLUGIN_OVERLAY_SOURCES} INSTALL_NAMESPACE "kf${KF_VER}/overlayicon" ) ``` -------------------------------- ### Clone VCPKG Repository Source: https://github.com/meganz/megasync/blob/master/README.linux.md Clones the VCPKG C++ Library Manager repository to manage third-party dependencies. The example uses `~/mega` as the local directory. ```bash mkdir ~/mega cd ~/mega git clone https://github.com/microsoft/vcpkg ``` -------------------------------- ### Build Qt using a script Source: https://github.com/meganz/megasync/blob/master/README.win.md Use this script to build Qt if you need a custom version. Ensure Python, Perl, and JOM are in your PATH. ```bash cd contrib\build_qt\windows .uild-qt.cmd ``` -------------------------------- ### Configure project with CMake (64-bit) Source: https://github.com/meganz/megasync/blob/master/README.win.md Run CMake to configure the project for a 64-bit build. This step also builds dependencies via VCPKG. Adapt paths to your system. ```bash cd c:\mega\ cmake -DCMAKE_GENERATOR_PLATFORM=x64 -DCMAKE_PREFIX_PATH='C:\Qt\5.15.17\x64' -DVCPKG_ROOT='c:\mega\vcpkg' -S 'c:\mega\desktop' -B 'c:\mega\build-x64' ``` -------------------------------- ### Configure project with CMake (32-bit) Source: https://github.com/meganz/megasync/blob/master/README.win.md Run CMake to configure the project for a 32-bit build. Ensure you specify the correct x86 paths for Qt. ```bash cd c:\mega\ cmake -DCMAKE_GENERATOR_PLATFORM=Win32 -DCMAKE_PREFIX_PATH='C:\Qt\5.15.17\x86' -DVCPKG_ROOT='c:\mega\vcpkg' -S 'c:\mega\desktop' -B 'c:\mega\build-x86' ``` -------------------------------- ### Build Qt 5 SDK Source: https://github.com/meganz/megasync/blob/master/README.mac.md Builds a custom version of Qt 5 using a provided script. Assumes python3, perl, and jom are in the PATH. ```bash cd contrib/build_qt/macOS ./build-qt.sh ``` -------------------------------- ### Updating GTK Icon Cache Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtNemo/CMakeLists.txt Conditionally installs a command to update the GTK icon cache after installing emblems, if 'no_desktop' is not defined. This ensures Nemo picks up the new emblems. ```cmake if(NOT DEFINED no_desktop) install(CODE " message(STATUS \"Updating GTK\") execute_process(COMMAND gtk-update-icon-cache -f -t ${HICOLOR}) ") endif() ``` -------------------------------- ### Configure Project with CMake for x86_64 Source: https://github.com/meganz/megasync/blob/master/README.mac.md Configures the MEGA Desktop project using CMake for an x86_64 target. It specifies Qt and VCPKG paths and the source and build directories, and sets the architecture. ```bash cd ~/mega/ cmake -DCMAKE_OSX_ARCHITECTURES:UNINITIALIZED=x86_64 -DCMAKE_PREFIX_PATH='~/Qt-build/5.15.17/5.15.17/x86_64' -DVCPKG_ROOT='~/mega/vcpkg' -S '~/mega/desktop' -B '~/mega/build-x64' ``` -------------------------------- ### Find and Configure Qt5 Components Source: https://github.com/meganz/megasync/blob/master/src/MEGASync/CMakeLists.txt Finds the necessary Qt5 components (Widgets, Core, Gui, Network, Qml, Quick, QuickWidgets, LinguistTools) and configures translation file generation. ```cmake find_package(Qt5 REQUIRED COMPONENTS Widgets Core Gui Network Qml Quick QuickWidgets LinguistTools) qt5_create_translation(QM_OUTPUT ${CMAKE_CURRENT_SOURCE_DIR} gui/translations/translation.source.ts OPTIONS -locations none -no-ui-lines -no-obsolete) ``` -------------------------------- ### Load Explorer Extension Source: https://github.com/meganz/megasync/blob/master/src/CMakeLists.txt Sets the MEGA_DESKTOP_APP_VER variable and loads the MEGAShellExt subdirectory if ENABLE_EXPLORER_EXT is enabled. ```cmake if(ENABLE_EXPLORER_EXT) set(MEGA_DESKTOP_APP_VER ${PROJECT_VERSION}) add_subdirectory(MEGAShellExt) endif() ``` -------------------------------- ### Configure Project with CMake for arm64 Source: https://github.com/meganz/megasync/blob/master/README.mac.md Configures the MEGA Desktop project using CMake for an arm64 target. It specifies Qt and VCPKG paths and the source and build directories. ```bash cd ~/mega/ cmake -DCMAKE_PREFIX_PATH='~/Qt-build/5.15.17/5.15.17/arm64' -DVCPKG_ROOT='~/mega/vcpkg' -S '~/mega/desktop' -B '~/mega/build-arm64' ``` -------------------------------- ### Include Directories and Linking Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtNautilus/CMakeLists.txt Configures include directories and links the necessary libraries for the project. ```cmake target_include_directories(${PROJECT_NAME} PRIVATE ${NAUTILUS_EXT_INCLUDE_DIRS}) target_link_libraries(${PROJECT_NAME} ${NAUTILUS_EXT_LIBRARIES}) ``` -------------------------------- ### Project and Package Configuration Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtNautilus/CMakeLists.txt Sets the minimum CMake version, project name, and finds required packages like PkgConfig and Nautilus extensions. ```cmake cmake_minimum_required(VERSION 3.16.0) project(MEGAShellExtNautilus LANGUAGES C) find_package(PkgConfig REQUIRED) pkg_search_module(NAUTILUS_EXT REQUIRED libnautilus-extension libnautilus-extension-4) ``` -------------------------------- ### Load MEGA Desktop App Project Source: https://github.com/meganz/megasync/blob/master/src/CMakeLists.txt Loads the main MEGA Desktop application subdirectory if the ENABLE_DESKTOP_APP feature is enabled. ```cmake if(ENABLE_DESKTOP_APP OR ENABLE_DESKTOP_UPDATE_GEN) add_subdirectory(MEGASync/mega) endif() ``` -------------------------------- ### Qt Patch Directory Structure Source: https://github.com/meganz/megasync/blob/master/contrib/build_qt/patches/readme.md Illustrates the hierarchical organization of patch files within the build system. Each patch is named with its order, target OS, and a descriptive name. ```tree ├─── .. .. [...] ├─── .. .. [...] [...] ``` -------------------------------- ### Build the Desktop App Source: https://github.com/meganz/megasync/blob/master/README.win.md Build the MEGAsync target using CMake. You can specify 'Debug' or 'Release' configurations. The executable will be located in the output directory. ```bash cmake --build 'c:\mega\build-x64' --config Debug --target MEGAsync ``` -------------------------------- ### Define Plugin Source Files Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtDolphin/CMakeLists.txt Lists the source files for the main plugin and its overlay component, used to compile the respective targets. ```cmake set(MEGA_PLUGIN_OVERLAY_SOURCES megasync-plugin-overlay.cpp ) set(MEGA_PLUGIN_SOURCES megasync-plugin.h megasync-plugin.cpp ) ``` -------------------------------- ### Find Qt5 Components Source: https://github.com/meganz/megasync/blob/master/src/MEGAAutoTests/UnitTests/CMakeLists.txt Finds the necessary components of the Qt5 framework required for the project, including Widgets, Core, Gui, Network, Qml, Quick, and QuickWidgets. ```cmake find_package(Qt5 REQUIRED COMPONENTS Widgets Core Gui Network Qml Quick QuickWidgets) ``` -------------------------------- ### Load MEGA Desktop App Source: https://github.com/meganz/megasync/blob/master/src/CMakeLists.txt Loads the MEGASync subdirectory if the ENABLE_DESKTOP_APP feature is enabled. ```cmake if(ENABLE_DESKTOP_APP) add_subdirectory(MEGASync) endif() ``` -------------------------------- ### CMake configuration template Source: https://github.com/meganz/megasync/blob/master/README.win.md A template for configuring the project with CMake, allowing you to specify custom paths for Qt, VCPKG, and the repository. ```bash cmake -DCMAKE_GENERATOR_PLATFORM=x64 -DCMAKE_PREFIX_PATH='' -DVCPKG_ROOT='' -S '' -B '' ``` -------------------------------- ### Load Desktop App Tests Source: https://github.com/meganz/megasync/blob/master/src/CMakeLists.txt Loads the MEGAAutoTests subdirectory if ENABLE_DESKTOP_APP_TESTS is enabled. ```cmake if (ENABLE_DESKTOP_APP_TESTS) add_subdirectory(MEGAAutoTests) endif() ``` -------------------------------- ### Finding PkgConfig and Nemo Extension Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtNemo/CMakeLists.txt Finds the PkgConfig module and searches for the libnemo-extension package. This is required for Nemo extension development. ```cmake find_package(PkgConfig REQUIRED) pkg_search_module(NEMO_EXT REQUIRED libnemo-extension) ``` -------------------------------- ### Source and Header File Definitions Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtNautilus/CMakeLists.txt Defines the source and header files used for building the shared library. ```cmake set(SOURCES mega_ext_module.c mega_ext_client.c mega_notify_client.c MEGAShellExt.c ) set(HEADERS MEGAShellExt.h mega_ext_client.h mega_notify_client.h ) ``` -------------------------------- ### Load Linux Extensions Source: https://github.com/meganz/megasync/blob/master/src/CMakeLists.txt Loads multiple Linux shell extension subdirectories if ENABLE_LINUX_EXT is enabled. ```cmake if(ENABLE_LINUX_EXT) add_subdirectory(MEGAShellExtDolphin) add_subdirectory(MEGAShellExtNautilus) add_subdirectory(MEGAShellExtThunar) add_subdirectory(MEGAShellExtNemo) endif() ``` -------------------------------- ### Include Build System Modules Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtDolphin/CMakeLists.txt Includes standard CMake modules for feature summarization and generating export headers, essential for managing build configurations. ```cmake include(FeatureSummary) include(GenerateExportHeader) ``` -------------------------------- ### Configure Project with CMake Source: https://github.com/meganz/megasync/blob/master/README.linux.md Configures the MEGAsync project using CMake, specifying the VCPKG root, source directory, build directory, and build type (Debug or Release). ```bash cd ~/mega cmake -DVCPKG_ROOT='~/mega/vcpkg' -S '~/mega/desktop' -B '~/mega/build_dir' -DCMAKE_BUILD_TYPE=Debug ``` ```bash cmake -DVCPKG_ROOT='' -S '' -B '' -DCMAKE_BUILD_TYPE= ``` -------------------------------- ### Find Cryptopp Configuration Source: https://github.com/meganz/megasync/blob/master/src/MEGAUpdater/CMakeLists.txt Finds and configures the cryptopp library for use with the MEGAupdater target. ```cmake find_package(cryptopp CONFIG REQUIRED) ``` -------------------------------- ### Enable Werror for Specific Configurations Source: https://github.com/meganz/megasync/blob/master/src/MEGASync/CMakeLists.txt Conditionally adds the /WX flag on Windows and -Werror on Unix for debug builds when ENABLE_DESKTOP_APP_WERROR is enabled. It also allows specific warnings to be ignored. ```cmake if (ENABLE_DESKTOP_APP_WERROR) target_platform_compile_options( TARGET MEGAsync WINDOWS /WX UNIX $<$: -Werror -Wno-error=deprecated-declarations> # Kept as a warning, do not promote to error. ) endif() ``` -------------------------------- ### Find Qt Dependencies Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtDolphin/CMakeLists.txt Locates the specified Qt version and its required components (Core, Network) for use in the project. ```cmake find_package(Qt${Qt_VER} CONFIG COMPONENTS Core Network ) ``` -------------------------------- ### Clone MEGAsync Desktop Repository Source: https://github.com/meganz/megasync/blob/master/doc/Installer_win.md Clone the MEGAsync Desktop repository and its submodules to your local machine. Ensure you are in the desired parent directory before running the command. ```bash $ mkdir c:\mega\ $ cd c:\mega\ $ git clone --recursive https://github.com/meganz/MEGAsync.git desktop ``` -------------------------------- ### Setting Target Properties Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtNemo/CMakeLists.txt Configures properties for the target library, such as the prefix. ```cmake set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "lib" ) ``` -------------------------------- ### List Unit Test Source Files Source: https://github.com/meganz/megasync/blob/master/src/MEGAAutoTests/UnitTests/CMakeLists.txt Defines a list of source files that will be compiled for the UnitTests executable. ```cmake set(UNIT_TEST_FILES AllMegaIncludes.h main.cpp MegaCatchReporter.cpp MegaCatchReporter.h MegaCatchReporterUtilities.cpp MegaCatchReporterUtilities.h ScaleFactorManagerTestFixture.cpp ScaleFactorManagerTestFixture.h StringConversions.h ScaleFactorManagerTests.cpp control/TransferBatchTests.cpp control/TransferRemainingTimeTests.cpp control/UtilitiesTests.cpp ) ``` -------------------------------- ### Find KDE Frameworks and ECM Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtDolphin/CMakeLists.txt Finds the Extra CMake Modules (ECM) and KDE Frameworks, setting up the module path and including necessary build policies. ```cmake # ECM setup find_package(ECM ${KF_DEP_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) if (${ECM_VERSION} VERSION_LESS 5.82.0) include(KDEInstallDirs) else() include(KDEInstallDirs${KF_VER}) endif() find_package(KF${KF_VER} REQUIRED COMPONENTS KIO ) include(KDECMakeSettings NO_POLICY_SCOPE) include(KDECompilerSettings NO_POLICY_SCOPE) ``` -------------------------------- ### Find Platform-Specific Qt5 Components Source: https://github.com/meganz/megasync/blob/master/src/MEGAAutoTests/UnitTests/CMakeLists.txt Finds additional Qt5 components based on the operating system (Windows, macOS, or others). ```cmake if (WIN32) find_package(Qt5 REQUIRED COMPONENTS WinExtras) elseif (APPLE) find_package(Qt5 REQUIRED COMPONENTS MacExtras Svg) else() find_package(Qt5 REQUIRED COMPONENTS Svg) endif() ``` -------------------------------- ### Including Directories and Linking Libraries Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtNemo/CMakeLists.txt Adds include directories and links necessary libraries to the target. This ensures the extension can find and use Nemo's APIs. ```cmake target_include_directories(${PROJECT_NAME} PRIVATE ${NEMO_EXT_INCLUDE_DIRS}) target_link_libraries(${PROJECT_NAME} ${NEMO_EXT_LIBRARIES}) ``` -------------------------------- ### Load MEGA Updater Source: https://github.com/meganz/megasync/blob/master/src/CMakeLists.txt Loads the MEGAUpdater subdirectory if the ENABLE_DESKTOP_UPDATER feature is enabled. ```cmake if(ENABLE_DESKTOP_UPDATER) add_subdirectory(MEGAUpdater) endif() ``` -------------------------------- ### Build MEGAsync Desktop App Source: https://github.com/meganz/megasync/blob/master/README.linux.md Builds the MEGAsync desktop application using CMake, targeting the `MEGAsync` executable. The built executable will be located in the specified build directory. ```bash cmake --build '~/mega/build_dir' --target MEGAsync ``` -------------------------------- ### Link Libraries for Overlay Plugin Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtDolphin/CMakeLists.txt Links the overlay plugin target against necessary KDE Frameworks libraries (KIOCore, KIOWidgets). ```cmake target_link_libraries(${MEGA_OVERLAYICON_PLUGIN} KF${KF_VER}::KIOCore KF${KF_VER}::KIOWidgets ) ``` -------------------------------- ### Set Platform-Specific Compile Options Source: https://github.com/meganz/megasync/blob/master/src/MEGAUpdater/CMakeLists.txt Configures compile options, specifically enabling -Werror for debug builds on Unix-like systems if ENABLE_DESKTOP_APP_WERROR is set. ```cmake if (ENABLE_DESKTOP_APP_WERROR) target_platform_compile_options( TARGET MEGAupdater UNIX $<$: -Werror -Wno-error=deprecated-declarations> # Kept as a warning, do not promote to error. ) endif() ``` -------------------------------- ### Enable Qt's Automatic Tools Source: https://github.com/meganz/megasync/blob/master/src/MEGAAutoTests/UnitTests/CMakeLists.txt Enables Qt's User Interface Compiler (UIC) and meta-object code generator (MOC) for the UnitTests target. ```cmake set(CMAKE_AUTOUIC ON) set_target_properties(UnitTests PROPERTIES AUTOUIC ON # Activates the User Interface Compiler generator for Qt. AUTOMOC ON # Activates the meta-object code generator for Qt. ) ``` -------------------------------- ### Link Libraries to UnitTests Target Source: https://github.com/meganz/megasync/blob/master/src/MEGAAutoTests/UnitTests/CMakeLists.txt Links all necessary libraries to the UnitTests executable, including third-party libraries and Qt5 components, with platform-specific conditions. ```cmake target_link_libraries(UnitTests PRIVATE trompeloeil MEGA::SDKlib MEGA::SDKQtBindings $<$:Qt5::WinExtras> $<$:Qt5::MacExtras> $<$:Qt5::Svg> $<$:unofficial::breakpad::libbreakpad> $<$:unofficial::breakpad::libbreakpad_client> Qt5::Widgets Qt5::Core Qt5::Gui Qt5::Network Qt5::Qml Qt5::Quick Qt5::QuickWidgets Catch2::Catch2 ) ``` -------------------------------- ### Link Libraries for Action Plugin Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtDolphin/CMakeLists.txt Links the main plugin target against required KDE Frameworks libraries (KIOCore, KIOWidgets, KIOFileWidgets). ```cmake target_link_libraries(${MEGA_PLUGIN} KF${KF_VER}::KIOCore KF${KF_VER}::KIOWidgets KF${KF_VER}::KIOFileWidgets ) ``` -------------------------------- ### Enable CMake Automatic Meta-Object Compilation Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtDolphin/CMakeLists.txt Enables automatic handling of meta-object information for Qt components, simplifying the build process for Qt projects. ```cmake set(CMAKE_AUTOMOC ON) ``` -------------------------------- ### Build MEGAsync Target Source: https://github.com/meganz/megasync/blob/master/README.mac.md Builds the MEGAsync target using CMake. Supports Debug and Release configurations. ```bash cmake --build '~/mega/build-arm64' --config Debug --target MEGAsync ``` -------------------------------- ### Set Include Directories for UnitTests Source: https://github.com/meganz/megasync/blob/master/src/MEGAAutoTests/UnitTests/CMakeLists.txt Specifies the include directories for the UnitTests target, including third-party directories and the main project directory. ```cmake target_include_directories(UnitTests PRIVATE ../3rdparty ${MegaSyncDir}) ``` -------------------------------- ### Add DPI Aware Manifest to Windows Executable Source: https://github.com/meganz/megasync/blob/master/src/MEGASync/CMakeLists.txt Uses a custom build command to amend the Windows executable's manifest file, marking the application as DPI aware. This is necessary for proper scaling on modern Windows versions. ```cmake if (MSVC) add_custom_command( TARGET MEGAsync POST_BUILD COMMAND "mt.exe" -manifest "${CMAKE_CURRENT_SOURCE_DIR}\MEGAsync.exe.manifest" -inputresource:"$"\;\#1 -outputresource:"$"\;\#1 COMMENT "Adding display aware manifest..." ) endif() ``` -------------------------------- ### Find Catch2 and TrompeLoeil Source: https://github.com/meganz/megasync/blob/master/src/MEGAAutoTests/UnitTests/CMakeLists.txt Finds the Catch2 testing framework and the TrompeLoeil library, both required for the unit tests. ```cmake find_package(Catch2 REQUIRED) find_package(TrompeLoeil REQUIRED) ``` -------------------------------- ### Activate Qt Code Generation Properties Source: https://github.com/meganz/megasync/blob/master/src/MEGASync/CMakeLists.txt Enables automatic code generation features for Qt, including the User Interface Compiler (UIC), Meta-Object Compiler (MOC), and Resource Compiler (RCC). ```cmake set_target_properties(MEGAsync PROPERTIES AUTOUIC ON # Activates the User Interface Compiler generator for Qt. AUTOMOC ON # Activates the meta-object code generator for Qt. AUTORCC OFF # Activates the creation of rules over qrc files ) ``` -------------------------------- ### Link Libraries for MEGAUpdateGenerator Source: https://github.com/meganz/megasync/blob/master/src/MEGAUpdateGenerator/CMakeLists.txt Finds and links the required cryptopp and MEGA::SDKlib libraries to the MEGAUpdateGenerator target. ```cmake # Load and link needed libraries for the CHATlib target find_package(cryptopp CONFIG REQUIRED) target_link_libraries(MEGAUpdateGenerator PRIVATE cryptopp::cryptopp MEGA::SDKlib ) ``` -------------------------------- ### Configure Breakpad if Enabled Source: https://github.com/meganz/megasync/blob/master/src/MEGAAutoTests/UnitTests/CMakeLists.txt If USE_BREAKPAD is enabled, this block finds the unofficial-breakpad package, sets the CRASH_BACKEND_URL cache variable, and adds it as a compile definition. ```cmake if(USE_BREAKPAD) find_package(unofficial-breakpad CONFIG REQUIRED) set(CRASH_BACKEND_URL "$ENV{MEGA_CRASH_BACKEND_URL}" CACHE STRING "Crash backend URL") target_compile_definitions(UnitTests PRIVATE CRASH_BACKEND_URL="${CRASH_BACKEND_URL}") message(STATUS "Breakpad added") endif() ``` -------------------------------- ### Define Compiler Flags Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtDolphin/CMakeLists.txt Adds preprocessor definitions to enable specific optimizations for Qt's string concatenation. ```cmake add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS) ``` -------------------------------- ### Library Target Creation and Properties Source: https://github.com/meganz/megasync/blob/master/src/MEGAShellExtNautilus/CMakeLists.txt Creates a shared library target named MEGAShellExtNautilus and sets its properties, including the prefix. ```cmake # Create the library target add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS}) set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "lib" # SOVERSION "${PROJECT_VERSION}" ) ``` -------------------------------- ### Set Platform-Specific Compile Options Source: https://github.com/meganz/megasync/blob/master/src/MEGAAutoTests/UnitTests/CMakeLists.txt Applies platform-specific compile options, in this case, for UNIX systems. ```cmake target_platform_compile_options(TARGET UnitTests UNIX -D__STDC_FORMAT_MACROS) ``` -------------------------------- ### Set MEGA_DESKTOP_APP_SOURCES Variable Source: https://github.com/meganz/megasync/blob/master/src/MEGAAutoTests/CMakeLists.txt Sets a CMake variable to list the source files for the MEGA Desktop application. These files are then used in the build process. ```cmake set(MegaSyncDir "../../MEGASync") set(MEGA_DESKTOP_APP_SOURCES ${MegaSyncDir}/BlockingStageProgressController.cpp ${MegaSyncDir}/CommonMessages.cpp ${MegaSyncDir}/EventUpdater.cpp ${MegaSyncDir}/FolderTransferListener.cpp ${MegaSyncDir}/MegaApplication.cpp ${MegaSyncDir}/ScaleFactorManager.cpp ${MegaSyncDir}/ScanStageController.cpp ${MegaSyncDir}/TransferQuota.cpp ${MegaSyncDir}/UserAlertTimedClustering.cpp ${MegaSyncDir}/drivedata.cpp ) ``` -------------------------------- ### Add Sources to Target Source: https://github.com/meganz/megasync/blob/master/src/MEGAUpdater/CMakeLists.txt Adds all defined header and source files to the MEGAupdater target. ```cmake target_sources(MEGAupdater PRIVATE ${UPDATER_HEADERS} ${UPDATER_SOURCES} ) ``` -------------------------------- ### List Header and Source Files Source: https://github.com/meganz/megasync/blob/master/src/MEGASync/CMakeLists.txt Defines lists of header and source files required for the MEGAsync application. These lists are used later to populate the target sources. ```cmake set(MEGA_DESKTOP_APP_HEADERS BlockingStageProgressController.h CommonMessages.h EventUpdater.h FolderTransferEvents.h FolderTransferListener.h MegaApplication.h ScaleFactorManager.h ScanStageController.h TransferQuota.h UserAlertTimedClustering.h drivedata.h ) set(MEGA_DESKTOP_APP_SOURCES BlockingStageProgressController.cpp CommonMessages.cpp EventUpdater.cpp FolderTransferListener.cpp MegaApplication.cpp ScaleFactorManager.cpp ScanStageController.cpp TransferQuota.cpp UserAlertTimedClustering.cpp drivedata.cpp main.cpp ) ``` -------------------------------- ### Add Platform-Specific Sources Source: https://github.com/meganz/megasync/blob/master/src/MEGAUpdater/CMakeLists.txt Conditionally adds source files for specific platforms, like macOS. ```cmake target_sources_conditional(MEGAupdater FLAG APPLE PRIVATE MacUtils.mm ) ``` -------------------------------- ### Load MEGA Update Generator Source: https://github.com/meganz/megasync/blob/master/src/CMakeLists.txt Loads the MEGAUpdateGenerator subdirectory if the ENABLE_DESKTOP_UPDATE_GEN feature is enabled. ```cmake if(ENABLE_DESKTOP_UPDATE_GEN) add_subdirectory(MEGAUpdateGenerator) endif() ``` -------------------------------- ### Configure Breakpad for Crash Reporting Source: https://github.com/meganz/megasync/blob/master/src/MEGASync/CMakeLists.txt Finds and configures the unofficial Breakpad library for crash reporting. It also allows setting a crash backend URL via CMake cache or environment variables. ```cmake if(USE_BREAKPAD) find_package(unofficial-breakpad CONFIG REQUIRED) if(NOT DEFINED CACHE{CRASH_BACKEND_URL}) set(CRASH_BACKEND_URL "" CACHE STRING "Crash backend URL") endif() if(DEFINED ENV{MEGA_CRASH_BACKEND_URL} AND NOT "$ENV{MEGA_CRASH_BACKEND_URL}" STREQUAL "") set(CRASH_BACKEND_URL "$ENV{MEGA_CRASH_BACKEND_URL}" CACHE STRING "Crash backend URL" FORCE) endif() if("${CRASH_BACKEND_URL}" STREQUAL "") message(WARNING "CRASH_BACKEND_URL is empty. Crash reporting may not function correctly.") endif() target_compile_definitions(MEGAsync PRIVATE CRASH_BACKEND_URL="${CRASH_BACKEND_URL}") message(STATUS "Breakpad added") endif() ``` -------------------------------- ### Include CMake Modules Source: https://github.com/meganz/megasync/blob/master/src/MEGAAutoTests/UnitTests/CMakeLists.txt Includes various CMake modules from different parts of the MEGA Sync project to incorporate their build logic. ```cmake include(${MegaSyncDir}/control/control.cmake) include(${MegaSyncDir}/gui/gui.cmake) include(${MegaSyncDir}/syncs/syncs.cmake) include(${MegaSyncDir}/platform/platform.cmake) include(${MegaSyncDir}/transfers/transfers.cmake) include(${MegaSyncDir}/stalled_issues/stalledissues.cmake) include(${MegaSyncDir}/node_selector/nodeselector.cmake) include(${MegaSyncDir}/notifications/notifications.cmake) include(${MegaSyncDir}/UserAttributesRequests/userattributesrequests.cmake) ``` -------------------------------- ### Clone MEGAsync Source Code Source: https://github.com/meganz/megasync/blob/master/README.linux.md Clones the MEGAsync desktop application repository and its submodules. It also fetches the MEGA SDK recursively. ```bash cd ~/mega mkdir desktop cd desktop git clone https://github.com/meganz/MEGAsync.git . git submodule update --init src/MEGASync/mega cd .. ``` -------------------------------- ### Load Design Tokens Importer Source: https://github.com/meganz/megasync/blob/master/src/CMakeLists.txt Loads the DesignTokensImporter subdirectory if ENABLE_DESIGN_TOKENS_IMPORTER is enabled. ```cmake if (ENABLE_DESIGN_TOKENS_IMPORTER) add_subdirectory(DesignTokensImporter) endif() ``` -------------------------------- ### Specify MEGAUpdateGenerator Source Files Source: https://github.com/meganz/megasync/blob/master/src/MEGAUpdateGenerator/CMakeLists.txt Lists the source files for the MEGAUpdateGenerator executable. ```cmake set(UPDATE_GENERATOR_SOURCES MEGAUpdateGenerator.cpp ) target_sources(MEGAUpdateGenerator PRIVATE ${UPDATE_GENERATOR_SOURCES} ) ``` -------------------------------- ### Define Updater Headers Source: https://github.com/meganz/megasync/blob/master/src/MEGAUpdater/CMakeLists.txt Lists the header files required for the MEGAUpdater. ```cmake set(UPDATER_HEADERS Preferences.h UpdateTask.h ) ``` -------------------------------- ### Set Compile Definitions Source: https://github.com/meganz/megasync/blob/master/src/MEGASync/CMakeLists.txt Configures compile-time definitions for the MEGAsync target, including Qt-specific flags, debug-only definitions, and platform-specific macros. ```cmake target_compile_definitions(MEGAsync PUBLIC QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII $<$:LOG_TO_STDOUT LOG_TO_LOGGER CREATE_COMPATIBLE_MINIDUMPS> $<$:PUBLIC NOMINMAX WIN32_LEAN_AND_MEAN UNICODE> $<$:ENABLE_SDK_ISOLATED_GFX> $<$:USE_BREAKPAD> ) ``` -------------------------------- ### Include CMake Control Modules Source: https://github.com/meganz/megasync/blob/master/src/MEGASync/CMakeLists.txt Includes various CMake control modules that manage different aspects of the application build, such as control, GUI, notifications, platform specifics, and sync functionalities. ```cmake include(control/control.cmake) include(gui/gui.cmake) include(notifications/notifications.cmake) include(platform/platform.cmake) include(qtlockedfile/qtlockedfile.cmake) include(stalled_issues/stalledissues.cmake) include(node_selector/nodeselector.cmake) include(syncs/syncs.cmake) include(transfers/transfers.cmake) include(UserAttributesRequests/userattributesrequests.cmake) ``` -------------------------------- ### Link Libraries to MEGAsync Target Source: https://github.com/meganz/megasync/blob/master/src/MEGASync/CMakeLists.txt Links the necessary libraries to the MEGAsync target, including MEGA SDK libraries, Qt modules, platform-specific Qt extras, and Breakpad libraries if enabled. ```cmake target_link_libraries(MEGAsync PUBLIC MEGA::SDKlib MEGA::SDKQtBindings $<$:Qt5::WinExtras> $<$:Qt5::MacExtras> $<$:Qt5::Svg> $<$:unofficial::breakpad::libbreakpad> $<$:unofficial::breakpad::libbreakpad_client> Qt5::Widgets Qt5::Core Qt5::Gui Qt5::Network Qt5::Qml Qt5::Quick Qt5::QuickWidgets ) ```