Arnav Borborah
Arnav Borborah

Reputation: 11789

Where Should Executable Resource Files be Installed Using the CMake install Command?

I am starting to get the hang of CMake now, but one question has essentially stumped me. Suppose I had a project structure such as the following:

.
├── CMakeLists.txt
└── src
    ├── CMakeLists.txt
    ├── main.cpp
    └── resources
        └── text_file.txt

In this example, main.cpp relies on resources/text_file.txt, including it using std::ifstream fileReader{ "text_file.txt" }. Thus, in my top level CMakeLists.txt file, I have the following line:

file(COPY src/resources DESTINATION ${PROJECT_BINARY_DIR}/src)

This command works for the build directory and all my resources (text files, images, and all the like are accessible to my built application). However, this does not really work well for installing using the install command and make install. For example, if I wanted to install the executable, I could use:

install(TARGETS test_executable DESTINATION bin)

Where test_executable is the name of the executable. On the other hand, installing this resources folder seems a little bit more tricky. My initial thought was to "install" this folder into bin as well so that my executable could access it, but then I decided this was a bad idea, since:

  1. The bin folder is meant for executables, not resource files.
  2. (I am not entirely sure about this one) resources is a fairly common name for a folder containing resources, so putting them in bin could be risky. If the best practice is to put resources in a resources folder in bin, then wouldn't this be a problem for other applications that also had a resources folder? (I realize this wouldn't be a problem if I just renamed the folder, but that isn't the point)

This leads to my question: What should the install location of my resource files be when I am using CMake so that my built executable can access them using the file path shown above? Should it be in bin, or is there some other folder dedicated to this role? How do video games, which have a lot of resource files, handle this?

Upvotes: 4

Views: 1602

Answers (1)

Arnav Borborah
Arnav Borborah

Reputation: 11789

Well, I did a bit more research, and found this AskUbuntu answer, which states that the relevant resource files are stored in /usr/share or /usr/local/share, which is used for storing platform independent files.

In order to get this path, most apps configure a script that stores it in a variable depending on the platform.

Upvotes: 4

Related Questions