Skip to content

Commit

Permalink
Merge pull request #122 from UiL-OTS-labs/feature/build-windows
Browse files Browse the repository at this point in the history
Feature/build windows
  • Loading branch information
maartenuni authored Oct 3, 2024
2 parents fb4af25 + b56bca6 commit 0d34544
Show file tree
Hide file tree
Showing 26 changed files with 266 additions and 86 deletions.
5 changes: 5 additions & 0 deletions doc/building-psylib-on-linux.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Title:Building psylib on Linux
SPDX-License-Identifier: MIT
SPDX-FileCopyrightText: 2024 Maarten Duijndam

# Building psylib on Linux
86 changes: 86 additions & 0 deletions doc/building-psylib-on-windows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
Title:Building psylib on Windows
SPDX-License-Identifier: MIT
SPDX-FileCopyrightText: 2024 Maarten Duijndam

#Building psylib on Windows

There are probably many ways to get psylib to compile on windows. We are going
to explore, howto compile using [msys2][1] and [MinGW-w64][2] and try to
install compile it using the VisualStudio backend of the Meson build system.

Microsoft has developer [virtual machine][3] images available. These vm's are
for developers are valid for a limited period. This guide is written with
a Windows 11 vm running using virtual box or QEMU/KVM using virtmanager.

## Building using msys2 and MinGW-w64

The following steps are used to build psylib using msys2 and the toolchains
listed in the [msys2-environments][4]

### install [msys2][1]

When msys2 is installed, you can find different environments in the msys2 folder
in the start bar. This example uses the msys2 UCRT64 environment. To allow building a
library for an `x86_64` architecture using the ucrt C library and libstdc++ as
standard C++ library.

Open a mintty terminal: When you click the start menu/bar, (all apps) go to
MSYS2->MSYS2_UCRT64.


```bash
# install git
pacman -S git

# cd to the directory where to git clone psylib
mkdir git
cd git

# install pactoys for installing packages with short name
pacman -S pactoys


# clone psylib
git clone [email protected]:UiL-OTS-labs/psy-lib.git
cd psy-lib

#install python within msys environment
pacboy -S python:p python-pip:p

#install gcc/g++ or clang etc. depending on the chose environment.
pacboy -S toolchain:p

#install required packages
pacboy -S glib2:p\
gstreamer:p\
gst-plugins-base:p\
gst-plugins-good:p\
gtk4:p\
libepoxy:p\
portaudio:p\
boost:p\
gobject-introspection:p

# optional for unit tests
pacboy -S cunit:p

# optional for documentation
packboy -S gi-docgen:p

#finally install CMake (for ninja), ninja and meson
pacboy -S cmake:p\
meson:p\
ninja:p

# configure the build directory you
meson setup build

# cd to the build directory
cd build
ninja
```

[1]: https://msys2.org
[2]: https://MinGW-w64.org
[3]: https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/
[4]: https://www.msys2.org/docs/environments/#__tabbed_1_1
30 changes: 30 additions & 0 deletions doc/building-psylib.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Title:Building psylib
SPDX-License-Identifier: MIT
SPDX-FileCopyrightText: 2024 Maarten Duijndam

# Building psylib from source

Psylib can be build from source. Psylib is mainly programmed in C, but uses a
number of C++ files along the way. It mostly uses C libraries, but a few
C++ libraries are included/used as well. So we've tried to look at a number of
build systems that can build psyib from source.
Currently psylib is developed on Linux and we are trying to build it on Windows.
You might find other platforms on which you are able to build it, but we try
to document on how to build psylib on Windows and Linux.

## The Meson Build system

We've been looking for a build system to use in order to build psylib. Since,
psylib depends very much on [GObject][1] for object orientation, and [GLib][2]
for internal algorithms and data structures, and both those two use meson to
build itself. Additionally,

## Compiling on Linux
see [Building psylib on Linux](./building-psylib-on-linux.html)

## Compiling on Windows
see [Building psylib on Windows](./building-psylib-on-windows.html)

[1]: https://docs.gtk.org/gobject/
[2]: https://docs.gtk.org/glib/
[3]: https://mesonbuild.com/
2 changes: 1 addition & 1 deletion doc/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if get_option('documentation')
error(
'introspection is disabled.',
'Configure with introspection in order to build the documentation',
'or disable the documentation in ordr to build')
'or disable the documentation in order to build')
endif

gidocgen = find_program('gi-docgen', required : true)
Expand Down
5 changes: 5 additions & 0 deletions doc/psy-doc.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ doc_url = "https://docs.gtk.org/glib/"
name = "GObject"
description = "The base type system library"
doc_url = "https://docs.gtk.org/gobject/"

[dependencies."Gtk-4.0"]
name = "Gtk"
description = "The Gtk toolkit"
doc_url = "https://docs.gtk.org/gtk4/"

[dependencies."Pango-1.0"]
name = "Pango"
description = "Internationalized text layout and rendering"
Expand All @@ -55,6 +57,9 @@ doc_url = "https://docs.gtk.org/pango/"
# The generated files will be placed in the root output directory
content_files = [
"introduction.md",
"building-psylib.md",
"building-psylib-on-linux.md",
"building-psylib-on-windows.md",
"stepping-through-experiment.md",
"drawing-with-psylib-developer.md",
"audio-with-psylib.md",
Expand Down
3 changes: 2 additions & 1 deletion examples/c/loop.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

#include <psylib.h>
#include <inttypes.h>

static void
on_trial_activate(PsyStep *self, PsyTimePoint *tp)
{
(void) self;
(void) tp;
psy_step_leave(self, tp);
g_print("Trial activated %ld.\n", psy_step_get_loop_index(self, 0, NULL));
g_print("Trial activated %" PRId64 "\n", psy_step_get_loop_index(self, 0, NULL));
}

void
Expand Down
2 changes: 1 addition & 1 deletion examples/c/nested-loops.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ on_trial_activate(PsyTrial *trial, PsyTimePoint *tp)
{
gint64 outer = psy_step_get_loop_index(PSY_STEP(trial), 1, NULL);
gint64 inner = psy_step_get_loop_index(PSY_STEP(trial), 0, NULL);
g_print("{outer : %ld, inner : %ld}\n", outer, inner);
g_print("{outer : %" PRId64 ", inner : %" PRId64 "}\n", outer, inner);
psy_step_leave(PSY_STEP(trial), tp);
}

Expand Down
38 changes: 20 additions & 18 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project('libpsy',
version : '0.1',
default_options : [
'warning_level=3',
# 'werror=true',
'werror=false',
'buildtype=debugoptimized',
'c_std=gnu11', # this makes it easier to compile sub projects
'cpp_std=gnu++11' # use c++ 11
Expand Down Expand Up @@ -90,21 +90,32 @@ psy_deps = [
gtk_dep,
epoxy_dep,
gstreamer_dep,
gstreamer_app_dep
gstreamer_app_dep,
]

# add optional dependencies

if get_option('alsa')
message('Using alsa')
alsa_dep = dependency (
'alsa',
version : alsa_req,
required : true
)
alsa_dep = dependency (
'alsa',
version : alsa_req,
required : get_option('alsa')
)
if alsa_dep.found()
psy_deps += alsa_dep
endif

portaudio_dep = dependency (
'portaudio-2.0',
version : portaudio_req,
required : get_option('portaudio')
)
if portaudio_dep.found()
psy_deps += portaudio_dep
endif


# jack2 support isn't finished by a long stretch
# and should perhaps be left behind
if get_option('jack2')
message('Using jack')
jack2_dep = dependency (
Expand All @@ -115,15 +126,6 @@ if get_option('jack2')
psy_deps += jack2_dep
endif

if get_option('portaudio')
message('Using portaudio')
portaudio_dep = dependency (
'portaudio-2.0',
version : portaudio_req,
required : true
)
psy_deps += portaudio_dep
endif

message('the depencies are: ')
foreach dep : psy_deps
Expand Down
25 changes: 13 additions & 12 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,31 @@ option(

# enable features for specific backends

option (
'jack2',
type : 'boolean',
value : false,
description : 'Enable JACK2 as a backend for audio Linux (mac and ' +
'windows) you\'ll need the Jack2 development libraries'
)

option (
'portaudio',
type: 'boolean',
value : true,
type: 'feature',
value : 'auto',
description : 'Enable portaudio as backend for audio you\'ll need the ' +
'portaudio development libraries/packages'
)

option (
'alsa',
type : 'boolean',
value : true,
type : 'feature',
value : 'auto',
description : 'Enabe ALSA as a backend for audio Linux only depends on ' +
'libasound2-dev / alsa development libs'
)

option (
'jack2',
type : 'boolean',
value : false,
description : 'Enable JACK2 as a backend for audio Linux (mac and ' +
'windows) you\'ll need the Jack2 development libraries'
)


# examples

option (
Expand Down
2 changes: 1 addition & 1 deletion psy/backend_gtk/psy-gtk-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ psy_gtk_window_init(PsyGtkWindow *self)

create_drawing_context(self);

gtk_widget_show(GTK_WIDGET(self->window));
gtk_widget_set_visible(GTK_WIDGET(self->window), TRUE);
}

static void
Expand Down
2 changes: 1 addition & 1 deletion psy/gl/psy-gl-fragment-shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ typedef struct _PsyGlFragmentShader {
G_DEFINE_TYPE(PsyGlFragmentShader, psy_gl_fragment_shader, PSY_TYPE_GL_SHADER)

static GLuint
psy_gl_fragment_shader_create_shader()
psy_gl_fragment_shader_create_shader(void)
{
GLuint object_id;
object_id = glCreateShader(GL_FRAGMENT_SHADER);
Expand Down
19 changes: 16 additions & 3 deletions psy/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ if cc.has_function('__builtin_mul_overflow')
cdata.set('HAVE_BUILTIN_MUL_OVERFLOW', 1)
endif

if cc.has_function(
'usleep',
prefix : [
'#include<unistd.h>'
]
)
cdata.set('HAVE_USLEEP', 1)
endif

# check for headers
if cc.has_header('unistd.h')
cdata.set('HAVE_UNISTD_H', true)
Expand Down Expand Up @@ -65,17 +74,21 @@ if cxx.has_header('boost/lockfree/spsc_queue.hpp')
cdata.set('HAVE_BOOST_LOCKFREE_SPSC_QUEUE_HPP', true)
endif

if cc.has_header('windows.h')
cdata.set('HAVE_WINDOWS_H', true)
endif

# set predefines whether psylib is compile with the following backends/options

if get_option('jack2') == true
cdata.set('HAVE_JACK2', true)
endif

if get_option('alsa')
if alsa_dep.found()
cdata.set('HAVE_ALSA', true)
endif

if get_option('portaudio')
if portaudio_dep.found()
cdata.set('HAVE_PORTAUDIO', true)
endif

Expand Down Expand Up @@ -210,7 +223,7 @@ if get_option('jack2')
subdir('jack')
endif

if get_option('portaudio')
if portaudio_dep.found()
subdir('portaudio')
endif

Expand Down
2 changes: 2 additions & 0 deletions psy/psy-audio-device.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

#include <inttypes.h>

#include "enum-types.h"

#include "psy-audio-device.h"
Expand Down
Loading

0 comments on commit 0d34544

Please sign in to comment.