ashleynewson / SmartSim

Design and simulate digital logic circuits of varying complexity.
smartsim.org.uk
GNU General Public License v3.0
187 stars 30 forks source link

Load resources from relative rather than absolute paths #11

Open probonopd opened 5 years ago

probonopd commented 5 years ago

Is it possible to make SmartSim load its resources from relative (to the main binary) rather than absolute paths?

I am trying to make an AppImage (which succeeds) but when running it, I am getting because the files are not in /usr but in a different, ever-changing, location.

error

References:

ashleynewson commented 5 years ago

Assuming you're using the ./configure script to build things, you should be able to run:

./configure
make datadir="."

Which should compile smartsim with a -DPACKAGE_DATADIR=\"./smartsim/\" flag. (So put resources in ./smartsim/.)

~There is also another flag, -DPACKAGE_LIBDIR which you might also need to change somehow if you want plugin support, although I'm not entirely sure if that can be changed in a similar way.~ Actually, ignore that, I can't remember what that's for if anything. You could probably just ignore that one. Plugins should work anyway I think.

probonopd commented 5 years ago

Thank you. Unfortunately this makes it relative to the user's current working directory (cwd) rather than relative to the main executable. I used datadir="../share/" in the hope that it would be resolved relative to the directory in which the main binary resides. Is there a way to achieve this?

ashleynewson commented 5 years ago

I'm afraid I'm not entirely familiar with how AppImages work. Perhaps you could utilise a basic shell script wrapper to change directory as needed before running the main executable?

If you need things to be a little more clever, maybe you could patch things to set Config.resourceDir at runtime in vala/main.vala. (See also vala/config.vapi)

probonopd commented 5 years ago

I'm afraid I'm not entirely familiar with how AppImages work.

This actually has nothing to do with AppImages specifically. I am looking for something along the lines of https://github.com/Simmesimme/Gnome-Pie/blob/0d766697fb71f60d53e328f8b306eee4930d7508/src/utilities/paths.vala#L137-L163.