View Issue Details

IDProjectCategoryView StatusLast Update
0016862ScribusBuild Systempublic2024-01-29 17:32
Reporterfsimonis Assigned To 
PrioritylowSeveritytrivialReproducibilityN/A
Status newResolutionopen 
Product Version1.7.0.svn 
Summary0016862: CMake presets for relocatable develop builds
DescriptionHi there,
Every time I pick up tinkering with scribus, I first need to figure out how to set up the build system, so that the resulting binary can actually find icons etc.

This patch provides CMake presets, which simplify all of the above.
This feature was added in CMake 3.19, but I used 3.21 as it adds support for install directories.

Assumptions are:
- Out-of-source build in the build/ directory
- Relocatable build by default
- install in the install/ directory

To use the feature:

List presets: cmake --list-presets
Select a preset: cmake --preset debug
Build: cmake --build build/
Install: cmake --install build/
Run: ./install/bin/scribus

I also added a build preset to build whatever is in build/
cmake --build --preset default
For parallel builds use the Ninja generator, pass -j $(nproc) to cmake --build, or set the env CMAKE_BUILD_PARALLEL_LEVEL to the amount of cores.
TagsNo tags attached.
PatchYes

Activities

fsimonis

2022-11-19 15:39

reporter  

0001-Add-relocatable-CMake-presets.patch (1,677 bytes)   
From e10eb7c62c1e56e60e5cb69fe290d65ff50e6652 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Simonis?= <simonisfrederic@gmail.com>
Date: Sat, 19 Nov 2022 16:21:49 +0100
Subject: [PATCH] Add relocatable CMake presets

---
 .gitignore        |  1 +
 CMakePresets.json | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
 create mode 100644 CMakePresets.json

diff --git a/.gitignore b/.gitignore
index 567609b..dc28c5a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
 build/
+install/
diff --git a/CMakePresets.json b/CMakePresets.json
new file mode 100644
index 0000000..1f8c701
--- /dev/null
+++ b/CMakePresets.json
@@ -0,0 +1,46 @@
+{
+  "version": 3,
+  "cmakeMinimumRequired": {
+    "major": 3,
+    "minor": 21,
+    "patch": 0
+  },
+  "configurePresets": [
+    {
+      "name": "base",
+      "hidden": true,
+      "binaryDir": "${sourceDir}/build",
+      "installDir": "${sourceDir}/install",
+      "cacheVariables": {
+        "WANT_RELOCATABLE": "ON"
+      }
+    },
+    {
+      "name": "debug",
+      "displayName": "Relocatable debug configuration",
+      "inherits": "base",
+      "cacheVariables": {
+        "WANT_DEBUG": "ON"
+      }
+    },
+    {
+      "name": "release",
+      "displayName": "Relocatable release configuration",
+      "inherits": "base"
+    },
+    {
+      "name": "profiling",
+      "displayName": "Relocatable profiling configuration",
+      "inherits": "base",
+      "cacheVariables": {
+        "WANT_RELEASEWITHDEBUG": "ON"
+      }
+    }
+  ],
+  "buildPresets": [
+    {
+      "name": "default",
+      "configurePreset": "base"
+    }
+  ]
+}
-- 
2.38.1

fsimonis

2023-12-16 11:27

reporter   ~0050601

Hi, is there any specific reason why this hasn't been merged yet?
It's a pure add-on which doesn't impact current systems in any way.

As a bonus, these presets are now directly supported by VS Code https://devblogs.microsoft.com/cppblog/cmake-presets-integration-in-visual-studio-and-visual-studio-code/

cbradney

2023-12-16 22:44

administrator   ~0050605

I hadn't seen this at the time.
Firstly, I would never build or install within the source directory. Bad form.
Where are all your other cmake variables set? QT Prefix, arch, bundle, etc.

ale

2023-12-17 08:24

manager   ~0050609

personally, i had to go through the ticket description and the patch a few times, to understand what is suggested.

i guess that there are too many commands in there that are similar to what i do, just slightly different.

this having been said, i wonder if such a preset file should be in scribus or if it's better for the user to store it somewhere and copy it in when needed.

at least, it should not have the hard written install path in there. i think that it's a common thing, when using cmake, to be able to set -DCMAKE_INSTALL_PREFIX:PATH .
not sure it's a good thing for the preset to blindly override that.
is there a way to set installDir so that it takes it into account?
(i'm a bit lazy today: do you have a good introduction on what the presets can do and how to use them in an efficient way? ... personally, i've never seen them...)

fsimonis

2023-12-17 14:21

reporter   ~0050610

> Firstly, I would never build or install within the source directory. Bad form.

Which is why these presets configure the build directory in ./build. Thus, not an in-source build as source dir = binary dir.

> Where are all your other cmake variables set? QT Prefix, arch, bundle, etc.

Currently, the presets configure a Debug/Release/RelWithDebInfo relocatable build. Other cache variables can be set using -D as usual.

 > i guess that there are too many commands in there that are similar to what i do, just slightly different.

I just listed the full thing independent of the selected generator. Normally one would simply do `cmake --preset=Debug` once and the `cd build && make` as usual.
The idea is just to make the initial configuration easier.

> this having been said, i wonder if such a preset file should be in scribus or if it's better for the user to store it somewhere and copy it in when needed.

CMake has a solution for this by design. It also reads CMakeUserPresets.json for user-defined presets. More information here https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html#introduction

> at least, it should not have the hard written install path in there. i think that it's a common thing, when using cmake, to be able to set -DCMAKE_INSTALL_PREFIX:PATH . not sure it's a good thing for the preset to blindly override that.

There are multiple points to this:
- This is value for a preset and doesn't change configuring the project the usual way using `cmake ..`. Fundamentally, it just changes the system-default value of CMAKE_INSTALL_PREFIX_PATH to SOURCE_DIR/install. It can still be overwritten as usual: `cmake --preset=develop -DCMAKE_INSTALL_PREFIX_PATH=/usr/local`.
- The proposed presets are meant for developers to quickly build and run scribus. The only reliable way I found is to use a relocatable build with a custom install prefix. Then build, install and run from the install dir. Please let me know if there is a better way of running scribus directly after building it from the build directory.
- There could be more presets for other build types that don't touch the install prefix.

cbradney

2023-12-17 17:18

administrator   ~0050611

Scribus should be run from the install directory, never the build or source directory.
make install and run from the install directory

ale

2023-12-17 20:39

manager   ~0050615

from the link you provided, it seems that there is no way to get the presets to respect -DCMAKE_INSTALL_PREFIX, when it's defined.
sad.
but if the conditions below are met, it's not that terrible.

personally, if the setup your proposing works for you and it does not affect anything, when somebody does not explicitly uses the presets, i think it would not be a bad idea to add it to scribus.
but it should not modify the default behavior of make install. if somebody does nothing, i think that scribus should keep on producing non relocatable binaries in /usr/local/ .
(i think that this is still the standard behavior... even if in my eyes it's not a good standard)
did i undestand it correctly, that this is the case?

@craig, if i understand it correctly, the config proposed would create an install folder inside of the source folder, just like one would normally create a build folder in there.
it's not mixing up build, install and source files.

cbradney

2023-12-17 22:12

administrator   ~0050617

One would not normally create a build or install folder inside a source folder... source is source, keep it that way. They should be side by side
blah\scribus\install
blah\scribus\build
blah\scribus\source

fsimonis

2023-12-18 09:16

reporter   ~0050618

> from the link you provided, it seems that there is no way to get the presets to respect -DCMAKE_INSTALL_PREFIX, when it's defined.
sad.

You can override the CMAKE_INSTALL_PREFIX as usual:

$ cmake --preset=debug -DCMAKE_INSTALL_PREFIX=/tmp/scribus
$ grep CMAKE_INSTALL_PREFIX build/CMakeCache.txt
CMAKE_INSTALL_PREFIX:PATH=/tmp/scribus

> but it should not modify the default behavior of make install. if somebody does nothing, i think that scribus should keep on producing non relocatable binaries in /usr/local/ .
> (i think that this is still the standard behavior... even if in my eyes it's not a good standard)
> did i undestand it correctly, that this is the case?

Exactly. This is a pure add-on.

> One would not normally create a build or install folder inside a source folder... source is source, keep it that way. They should be side by side

Without getting into unconstructive arguments, let me say that this is debatable, as such conventions are very situational. Keeping sibling directories doesn't scale well with multiple checkouts. I work on a project where I keep and use 5 checkouts using git worktree simultaneously. Having presets and a build folder in the repo root keeps this manageable.

ale

2023-12-18 12:21

manager   ~0050619

while cmake suggests in the official tutorial that build can go next to the sources

blah/scribus # for the sources
blah/scribus_build

there are no traces that the installed binaries would also go there (it's rather /usr/local/, the default, or somewhere in the home).

on the other side, if you have a look at the link provided by fsimonis

https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html#introduction

they seem to suggest that the relocatable binaries should go in the directory with the sources:

"binaryDir": "${sourceDir}/build/default",

... i guess that this is because, otherwise, "${sourceDir}/../build" would go into a parent directory, the author of the json file has no clue about.
(but they can make more assumptions about the characteristics inside of "${sourceDir}")
(same driver? access rights? is there another build/ from a different project?)

at the end, i don't really care where the build directory is placed by default, as long as it is a sane place and the user can set it to a different target.

since fsimonis confirmed that this file has no consequences for any user who does not opt in this specific (sub) system, i think that we can be less picky about the content of the file itself and wait for unhappy people who indeed use it, to show up with well founded fixes, ... if somebody ever think this content is not 100% correct

luzpaz

2024-01-29 16:33

reporter   ~0050951

Last edited: 2024-01-29 17:32

typo in title of ticket, should be 'relocatable'

ale: fixed!

Issue History

Date Modified Username Field Change
2022-11-19 15:39 fsimonis New Issue
2022-11-19 15:39 fsimonis File Added: 0001-Add-relocatable-CMake-presets.patch
2023-12-16 11:27 fsimonis Note Added: 0050601
2023-12-16 22:44 cbradney Note Added: 0050605
2023-12-17 08:24 ale Note Added: 0050609
2023-12-17 14:21 fsimonis Note Added: 0050610
2023-12-17 17:18 cbradney Note Added: 0050611
2023-12-17 20:39 ale Note Added: 0050615
2023-12-17 22:12 cbradney Note Added: 0050617
2023-12-18 09:16 fsimonis Note Added: 0050618
2023-12-18 12:21 ale Note Added: 0050619
2024-01-29 16:33 luzpaz Note Added: 0050951
2024-01-29 17:32 ale Summary CMake presets for relocatabel develop builds => CMake presets for relocatable develop builds
2024-01-29 17:32 ale Note Edited: 0050951