Wednesday 11 September 2019

Modern CMake 101: tutorial

CMake is a cross-platform build system generator, tool to test and package applications. Over the years, it gained attention and now it is widespread. As many tutorials on the Internet are outdated and do not show best practices, I have decided to create a modern CMake tutorial. This post is a table of contents.

Modern CMake 101


  1. Introduction

Friday 9 August 2019

The Meson Build System: part #2. Dependencies

This is a second post about Meson. If You have not read the first one, check it out!

Meson dependencies


In the first post about Meson, I have written how to create simple Meson project. But hardly any project can be done without external dependencies. In Meson, You use subprojects to specify external dependencies. If a developer's machine has dependency installed system-wide, Meson will use system version. In the other case, Meson will download dependency sources and build it.

All external dependencies should be declared by placing .wrap file in subprojects subfolder of the root directory of the project. To use dependencies managed by Meson team, You can use meson wrap subcommand. For example, to use gtest library, You will use the following commands:
mkdir subprojects in main dir
meson wrap install gtest

To create an executable using gtest dependency, use following Meson commands:
gtest_dep = dependency('gtest', main : true, fallback : ['gtest', 'gtest_dep'])

tests_executable = executable(
    'name',
    [sources],
    dependencies: [gtest_dep]
)
And that is all!

Meson dependencies vs CMake's

Following CMake code creates executable using gtests.
find_package(GTest REQUIRED)
add_executable(
    tests_executable
    [sources]
)
target_link_libraries(
    tests_executable
    PUBLIC
        GTest::GTest
        GTest::Main
)
The code is similar to one in Meson. But if Your system has not gtest package, using gtests is not straightforward. You can use package managers like vcpkg, but there is no single cross-platform solution.

Wednesday 7 August 2019

The Meson Build System: part #1


In an earlier post, I have stated that I installed Fedora to learn gtk programming. The first step was to try GNOME Builder. I have starter gtkmm project generated and I have learned, that preferred build tool for GNOME apps is Meson. After deciding to give it a try, I had rewritten one of my side projects into it. In this post, I will compare CMake and Meson code used to generate the same library and installing it. Because a picture is worth a thousand words, and code speaks louder than picture, below there are both: CMake and Meson codes.

CMake

cmake_minimum_required (VERSION 3.10)

project(
    "madterm"
    VERSION 0.0.0.1
    LANGUAGES CXX
)

# Project dependencies

# Project definition
add_library(
    madterm
    src/enable_formatting.cpp
    src/terminal_sequence.cpp
    src/text/effects.cpp
    src/text/modification.cpp
    src/text/charset.cpp
    src/cursor/move.cpp
    src/cursor/mode.cpp
    src/window/window.cpp
    src/screen_buffer/screen_buffer.cpp
)
target_compile_features(
    madterm
    PUBLIC cxx_std_17
)
target_include_directories(
    madterm
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include>
)

# Install part
include(CMakePackageConfigHelpers)

add_library(madterm::madterm ALIAS madterm)

configure_package_config_file(
    "madtermConfig.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/madtermConfig.cmake"
    INSTALL_DESTINATION lib/cmake/madterm
)
write_basic_package_version_file(
    "${CMAKE_CURRENT_BINARY_DIR}/madtermConfigVersion.cmake"
    VERSION ${madterm_VERSION}
    COMPATIBILITY SameMajorVersion
)
install(
    TARGETS madterm EXPORT madtermTargets
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
    RUNTIME DESTINATION bin
    INCLUDES DESTINATION include
)
install(
    EXPORT madtermTargets
    FILE madtermTargets.cmake
    NAMESPACE madterm::
    DESTINATION lib/cmake/madterm
)
install(
    FILES
        "${CMAKE_CURRENT_BINARY_DIR}/madtermConfig.cmake"
        "${CMAKE_CURRENT_BINARY_DIR}/madtermConfigVersion.cmake"
    DESTINATION lib/cmake/madterm
)
INSTALL (
    DIRECTORY include/
    DESTINATION include
    FILES_MATCHING PATTERN "*.h*"
)

Meson

project('madterm', 'cpp', version: '0.0.0.1', default_options: ['cpp_std=c++17'])

madterm_includes = include_directories('include')
madterm_lib = library(
    'madterm',
    'src/cursor/mode.cpp',
    'src/cursor/move.cpp',
    'src/enable_formatting.cpp',
    'src/screen_buffer/screen_buffer.cpp',
    'src/terminal_sequence.cpp',
    'src/text/effects.cpp',
    'src/text/modification.cpp',
    'src/text/charset.cpp',
    'src/window/window.cpp',
    include_directories: madterm_includes,
    install: true
)
madterm = declare_dependency(
    link_with : madterm_lib, include_directories : madterm_includes
)
install_subdir('include/madterm', install_dir: 'include')


CMake vs Meson

It is obvious, that Meson is more expressive and shorter, even thou I have omitted additional CMake file madtermConfig.cmake.in. Moreover, Meson is a typed language, so IDEs can better suggest its code and Meson functions do not look like a sh script. What is more, writing good CMake file is hard! The Internet is full of tutorials, which teach how to code in CMake in outdated and unmaintainable fashion! To write good CMake file, You have to know Modern CMake term and spend long hours searching through the web.

It is noteworthy, to compare CMake's behaviour and Meson's. Adding CMake's target is sufficient to use it later as a dependency, providing both: include directory and built library. On the other hand, in Meson, You have to be explicit: create include directory object, library and dependency with declare_dependency function.

Bad things in Meson

Unfortunately, there are some downsides of using Meson. It is not as widespread as CMake, so it has not had as good IDEs support as CMake. Moreover, when using Windows, You have to install ninja and launch Developers Console, to properly build Meson project. Because of a switch to Linux, these are not deal-breakers to me, so I will play with Meson for a while and post my afterthoughts.

Monday 5 August 2019

Creating screencasts in GNOME

On omg! ubuntu! I have learned a nice trick! In GNOME 3 there is a builtin tool to record screencasts. It records the whole desktop and without sound, so if You need something fancier, You should look somewhere else.

To start recording, You should press
Ctrl + Alt + Shift + R
Then, in top right corner red dot will appear:

Normal desktop
Recording desktop
 
To end recording, use the same key combination. By default, GNOME stops recording after 30 seconds. To check maximal movie length, use the following command:
gsettings get org.gnome.settings-daemon.plugins.media-keys max-screencast-length

If You want to record longer movies, use command
gsettings set org.gnome.settings-daemon.plugins.media-keys max-screencast-length <length in seconds>

Friday 2 August 2019

Boxes

On this blog, I have written a few times about configuring a virtual machine with Ubuntu on Windows host. It was not a straightforward process. Nowadays, You have two options for creating Ubuntu virtual machine on hyper-v:
  • manual way
  • wizard
Only using wizard, I had satisfying performance of a virtual machine. Even when using a wizard, there are some configuration steps to be done, after creating a virtual machine.

When using GNOME 3 it is completely different! When using Boxes app, You simply use a wizard and it creates a virtual machine without the fuss! Copying files to the virtual machine is as simple as dragging them from files explorer on the host system and dropping onto virtual machine window! Development on Linux is really so much easier!

Tuesday 30 July 2019

Mounting OneDrive in Linux

In one of the posts about GNOME 3, I have mentioned that I had installed rclone app. I use it, to mount my OneDrive folder in my Linux home directory. After configuring OneDrive in rclone browser, I have configured the system to mount it, when I logged in. First, I had created a target directory in my home directory:
cd ~
mkdir OneDrive
Then, I have used systemd to create service which mounts my OneDrive folder. Command
systemctl --user edit OneDrive
creates service file in ~/.config/systemd/user/OneDrive.service and I have filled it with my gist:

Then I have enabled OneDrive service to run on login:
systemctl --user enable OneDrive
To run it immediately, You can issue the command:
systemctl --user start OneDrive

Sunday 28 July 2019

Outlook synchronization in GNOME

GNOME 3 has online accounts feature, similar to one in iOS or Android. By adding Your Google account, You will have synchronized:
But adding outlook account gives You only synchronization of mails. To have tasks and appointments synchronized, You have to install Evolution plugin for Exchange Web Services by using the command:
sudo dnf install evolution-ews
Then You have to generate a Microsoft App Password, which You can do here. This link should send You to the right place where an App password is generated, if not, from outlook account go to Security (top menu), more security options (bottom of the page) and Create a new app password (middle of the page).

When You have Microsoft App Password, You can add Microsoft Account in GNOME online account settings. Note: to synchronize tasks and appointments, You have to add Microsoft Exchange account using App Password from the second step!


Then add normal Microsoft Account to synchronize emails in Geary app.