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!