aardappel / treesheets

TreeSheets : Free Form Data Organizer (see strlen.com/treesheets)
zlib License
2.58k stars 193 forks source link

FreeBSD: cmake install paths on non-linux #614

Closed nunotexbsd closed 6 months ago

nunotexbsd commented 6 months ago

Updating from 7861249636 to latest commit 7ab85ae41dae31d62ceccfae530c5597e674df0c cmake need patching to install correctly into:

PREFIX/bin PREFIX/share/docs/PKGNAME PREFIX/share

Until 7861249636, the only change needed was:

-install(DIRECTORY TS/examples DESTINATION ${TREESHEETS_DOCDIR})
+install(DIRECTORY TS/examples DESTINATION ${CMAKE_INSTALL_DATADIR}/examples/${CMAKE_PROJECT_NAME})

At 7ab85ae41dae31d62ceccfae530c5597e674df0c it needs patch but runtime gives error bellow.

Am I missing something? Thanks

--- CMakeLists.txt.orig 2024-03-24 04:56:12 UTC
+++ CMakeLists.txt
@@ -117,18 +117,23 @@ else()
     install(FILES linux/com.strlen.TreeSheets.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
     install(FILES linux/com.strlen.TreeSheets.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/mime/packages)
 else()
-    set(TREESHEETS_BINDIR ${CMAKE_INSTALL_PREFIX})
-    set(TREESHEETS_DOCDIR ${CMAKE_INSTALL_PREFIX})
-    set(TREESHEETS_PKGDATADIR ${CMAKE_INSTALL_PREFIX})
+    include(GNUInstallDirs)
+    set(TREESHEETS_BINDIR ${CMAKE_INSTALL_BINDIR})
+    set(TREESHEETS_DOCDIR ${CMAKE_INSTALL_DOCDIR})
+    set(TREESHEETS_PKGDATADIR ${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME})
 endif()

 install(TARGETS treesheets DESTINATION ${TREESHEETS_BINDIR})
 install(DIRECTORY TS/docs DESTINATION ${TREESHEETS_DOCDIR})
 install(FILES TS/readme.html DESTINATION ${TREESHEETS_DOCDIR})
-install(DIRECTORY TS/examples DESTINATION ${TREESHEETS_DOCDIR})
+install(DIRECTORY TS/examples DESTINATION ${CMAKE_INSTALL_DATADIR}/examples/${CMAKE_PROJECT_NAME})

 install(DIRECTORY TS/images DESTINATION ${TREESHEETS_PKGDATADIR})
 install(DIRECTORY TS/scripts DESTINATION ${TREESHEETS_PKGDATADIR})
+
+install(FILES linux/com.strlen.TreeSheets.svg DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps)
+install(FILES linux/com.strlen.TreeSheets.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
+install(FILES linux/com.strlen.TreeSheets.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/mime/packages)

 # Install translations to correct platform-specific path.
 # See: https://docs.wxwidgets.org/trunk/overview_i18n.html#overview_i18n_mofiles

Error on run:

% treesheets
w
08:34:17: wxWidgets 3.2.4
l
08:34:17: locale: en_US.UTF-8
c
08:34:17: Error: can't open file 'images/icon16.png' (error 2: No such file or directory)
F
08:34:17: Error: Failed to load image from file "images/icon16.png".
c
08:34:17: Error: can't open file 'images/icon32.png' (error 2: No such file or directory)
F
08:34:17: Error: Failed to load image from file "images/icon32.png".
tobiolo commented 6 months ago

Thanks for posting this issue.

Does BSD implement the Hierarchical File System from Linux? If yes, then it can be fixed by adding BSD to the condition check.

nunotexbsd commented 6 months ago

I don't think so from what I'm reading on https://wiki.freebsd.org/HFS

At version 7861249636 I didn't change values from CMakeLists.txt appart from sending examples to other dir, so it is a good start the check what changed.

tobiolo commented 6 months ago

Sorry I meant Filesystem Hierarchy Standard.

nunotexbsd commented 6 months ago

FreeBSD Unix don't conform with FHS and it is the first time that I'm seing it being configured in cmake:

https://man.freebsd.org/cgi/man.cgi?hier(7)

tobiolo commented 6 months ago

First approach: Follow the Filesystem Hierarchy Standard also on BSD.

You may seem to use it anyway in your patch, because when you include(GNUInstallDirs), you follow the Filesystem Hierarchy Standard, meaning that you put the documentation into $CMAKE_INSTALL_PREFIX/share/doc/ ... during installation (e.g. when you use make install or cmake --install <builddir>).

In this case: Does it help to only replace LINUX with BSD in CMakeLists.txt, not keeping the original patch? You may need to clean up the CMake cache, too. (That means removing CMakeCache.txt and then re-generate the Makefiles with CMake).

Second approach: Keep everything relative to the TreeSheets binary (this is just the case on every operating system apart from Linux where TREESHEETS_RELOCATABLE_INSTALLATION is not set, thus following the Filesystem Hierarchy Standard). In this case, you should leave the CMakeLists.txt as is from upstream without patching it and configure CMAKE_INSTALL_PREFIX to a suitable location where it does not interfere with the root filesystem hierarchy. You need to check then that examples and images directories are installed relative to/along with the TreeSheets binary.

When you change between the two approaches, please remind to also clean the CMake Cache because otherwise the variables TREESHEETS_DOCDIR etc. will be left over (the variables indicate absolute paths in the case of the Filesystem Hierarchy Standard used). These are used by the preprocessor to determine whether it should consider these paths, too or only the paths relative to the binary.

nunotexbsd commented 6 months ago

@t2b3

It worked fine! I've run so many tests and even so I did missed something.

My test patch is:

--- CMakeLists.txt.orig 2024-03-28 08:00:11 UTC
+++ CMakeLists.txt
@@ -99,7 +99,7 @@ endif()
     OPTION(TREESHEETS_RELOCATABLE_INSTALLATION "Install data relative to the treesheets binary, instead of respecting the Filesystem Hierarchy Standard" OFF)
 endif()

-if(LINUX AND NOT TREESHEETS_RELOCATABLE_INSTALLATION)
+if(NOT LINUX AND NOT TREESHEETS_RELOCATABLE_INSTALLATION)
     include(GNUInstallDirs)

     set(TREESHEETS_BINDIR ${CMAKE_INSTALL_BINDIR})
@@ -125,7 +125,7 @@ install(FILES TS/readme.html DESTINATION ${TREESHEETS_
 install(TARGETS treesheets DESTINATION ${TREESHEETS_BINDIR})
 install(DIRECTORY TS/docs DESTINATION ${TREESHEETS_DOCDIR})
 install(FILES TS/readme.html DESTINATION ${TREESHEETS_DOCDIR})
-install(DIRECTORY TS/examples DESTINATION ${TREESHEETS_DOCDIR})
+install(DIRECTORY TS/examples DESTINATION ${CMAKE_INSTALL_DATADIR}/examples/${CMAKE_PROJECT_NAME})

 install(DIRECTORY TS/images DESTINATION ${TREESHEETS_PKGDATADIR})
 install(DIRECTORY TS/scripts DESTINATION ${TREESHEETS_PKGDATADIR})

So, for my understanding FreeBSD could be added to this block.

tobiolo commented 6 months ago

Thanks for your reply! Happy to hear that it works. One more question: Is it sufficient to patch the CMakeLists.txt with the patch below to make it work on FreeBSD? I am curious whether and why it is needed to patch the install destination for TS/examples because in the branch now used TREESHEETS_DOCDIR is now set and thus that path is considered by the compiler preprocessor and thus hardcoded as candidate into the candidate path array for the TreeSheets example files, like tutorial, into the binary.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 576cf3f..84d0f57 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -95,11 +95,11 @@ target_link_libraries(

 ########## TREESHEETS INSTALLATION SETTINGS ###############

-if(LINUX)
+if(LINUX OR FREEBSD)
     OPTION(TREESHEETS_RELOCATABLE_INSTALLATION "Install data relative to the treesheets binary, instead of respecting the Filesystem Hierarchy Standard" OFF)
 endif()

-if(LINUX AND NOT TREESHEETS_RELOCATABLE_INSTALLATION)
+if((LINUX OR FREEBSD) AND NOT TREESHEETS_RELOCATABLE_INSTALLATION)
     include(GNUInstallDirs)

     set(TREESHEETS_BINDIR ${CMAKE_INSTALL_BINDIR})
nunotexbsd commented 6 months ago

+if(LINUX OR FREEBSD)

Adding FREEBSD like this doesn't work (all files get installed into cmake install prefix).

CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" seems the right setting, don't know if a generic one exists for *bsd.

Don't know if TREESHEETS_RELOCATABLE_INSTALLATION will have any use on FreeBSD...

tobiolo commented 6 months ago

Ok, what about BSD then directly? Sorry, you are completely right! https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 576cf3f..0ed952d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -95,11 +95,11 @@ target_link_libraries(

 ########## TREESHEETS INSTALLATION SETTINGS ###############

-if(LINUX)
+if(LINUX OR BSD)
     OPTION(TREESHEETS_RELOCATABLE_INSTALLATION "Install data relative to the treesheets binary, instead of respecting the Filesystem Hierarchy Standard" OFF)
 endif()

-if(LINUX AND NOT TREESHEETS_RELOCATABLE_INSTALLATION)
+if((LINUX OR BSD) AND NOT TREESHEETS_RELOCATABLE_INSTALLATION)
     include(GNUInstallDirs)

     set(TREESHEETS_BINDIR ${CMAKE_INSTALL_BINDIR})
tobiolo commented 6 months ago

+if(LINUX OR FREEBSD)

Adding FREEBSD like this doesn't work (all files get installed into cmake install prefix).

CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" seems the right setting, don't know if a generic one exists for *bsd.

Don't know if TREESHEETS_RELOCATABLE_INSTALLATION will have any use on FreeBSD...

Yes, I think it has its use case if you do not want to install it directly to the /usr/ hierarchy, but e.g. only to install it somewhere in your home directory (adjust CMAKE_INSTALL_PREFIX for it) and/or if you want to keep everything (binary, translation, documentation, tutorial) in one folder and move it around. Then relocatable install is needed. But normally packages distributed by the distribution should integrate directly with the Filesystem Hierarchy Standard structure, so and that case it is not needed.

nunotexbsd commented 6 months ago

+if(LINUX OR BSD)

Works perfectly.

Understand it about TREESHEETS_RELOCATABLE_INSTALLATION.

Related to:

-install(DIRECTORY TS/examples DESTINATION ${TREESHEETS_DOCDIR})
+install(DIRECTORY TS/examples DESTINATION ${CMAKE_INSTALL_DATADIR}/examples/ {CMAKE_PROJECT_NAME})

It has to do with our hier and ports framework:

DATADIR gets expanded to PREFIX/share/PORTNAME. DOCSDIR gets expanded to PREFIX/share/doc/PORTNAME. EXAMPLESDIR gets expanded to PREFIX/share/examples/PORTNAME.

cmake apears to not have a variable for examples like it do for doc, so I've patched it.

tobiolo commented 6 months ago

Ok :-) Thanks for your feedback! Is it okay for you to keep the patch at your (port) side?

But if you keep it that way, does not TreeSheet complain about the missing example file? If you run treesheets on the commandline there should be a warning?

nunotexbsd commented 6 months ago

Sure, not problem.

Thanks for help solving this issue.

tobiolo commented 6 months ago

Sure, not problem.

Thanks for help solving this issue.

You are welcome.