I’m not very good with CMake, so please excuse me if I’m missing something easy. Is there some way to support this spec: XDG Base Directory Specification
It’s a specification for handling the $HOME folder on different operating systems. Seems like something right up the alley for CMake, but I can’t find anything (even on this forum).
What would CMake do with it? The only thing CMake stores in
~/.cmake/packages which is largely deprecated now anyways. In what other way would CMake support XDG?
I guess I was just wondering if there was some code I could copy (I’m not very good with cmake).
I’m trying it now myself, so maybe it’s not so hard.
It depends on what your goal is. There’s probably a variety of libraries available which do the right thing on each platform, but I’m not familiar with what’s available in C or C++ off-hand if you want to use XDG for your application or library. As for CMake code, what would you be using the XDG spec for?
Some small part of my application’s configuration files are installed during the build. Other parts of the configuration are produced from default values once the application runs.
I have the runtime stuff figured out (that’s easy with C++), but the installation part during the build needs to instruct the make to put stuff in different places depending on the OS and whether or not the environment variables are set.
Ah. I don’t know if there’s anything that is XDG-specific, but the
GNUInstallDirs module is the closest CMake has, though that doesn’t help with XDG too much. Someone might have a module for it on github or something.
I don’t know your exact use case, but typically installing enduser files during a build is discouraged, since it means only the user who builds your application will be configured to run it. (Or, to put it another way, everyone who wants to run your application has to build it first, precluding any hope of shared builds / binary distributions.
Creating user-space files on first run, in the style of macOS applications, gives your users a lot more flexibility in sharing, managing, and distributing the compiled application.
Just something to consider, as I said I don’t know the exact situation and I can certainly understand that there might be cases where the build-time approach is the way to go.
It’s quite unusual, though, which is why you probably won’t find too much prior art on that sort of thing.
Thanks so much for taking the time to answer so thoroughly. I had this sneaking suspicion that this was the fact, but having so clearly spelled out (and pointing out that it’s so unusual) made the penny finally drop.
Yes. I should just create these files on ‘first run’ instead of ‘installing’ them.