Flatpak specific commands in CMake

I try to create a Flatpak package for my application, that is called AppName afterwards. Its uses CMake/make for configuration and compilation.

When I compile normally my application (using Flatpak), it uses a configuration file that has to be placed in the $HOME/.local/share/AppName/config folder. I place this file in this folder using this CMake command

install(FILES ${PROJECT_SOURCE_DIR}/config/config.ini DESTINATION $ENV{HOME}/.local/share/AppName)

It works well. Now, when when I create the Flatpak package, it looks for the configuration file in $HOME/.var/app/org.flatpak.AppName/data/AppName/config.ini"

How could I design my CMakeLists.txt so that it uses $ENV{HOME}/.local/share/AppName when I do not use Flatpak and $HOME/.var/app/org.flatpak.AppName/data/AppName when I create a Flatpak package?

In short, I am looking for a CMake snippet like

  install(FILES ${PROJECT_SOURCE_DIR}/config/config.ini DESTINATION $ENV{HOME}/.var/app/org.flatpak.AppName/data/AppName)
  install(FILES ${PROJECT_SOURCE_DIR}/config/config.ini DESTINATION $ENV{HOME}/.local/share/AppName)
  1. you should NEVER install something in the home directory as part of the build/install process.
  2. you should just follow the XDG standard and not hardcode path like you suggest doing. $XDG_DATA_HOME will resolve things.


What I do so far it to configure cmake using -DFLATPAK=ON. Now, I need to find what to write …