1

I would like to know if there is any guidance the question below, be it from the official CMake documentation, "industry-standard" or anything the like:

Should a program be executable from the build directory after just the CMake build step?

In other words: If I build my program with CMake and I want to run it. Should I be able to run/use it directly out of the build directory or do a lot of programs only work after an install step for example?

In other, other words: Is the effort to make my program runnable in the build directory a good idea or just unnecessary? What do other programs do? Is there any guidance on this particular question?

In my research I found that it probably should be that way, but I found no actual source for this, that would answer me this. Especially not with any explanation or justification.

Any help is appreciated. Thanks!

SkryptX
  • 813
  • 1
  • 9
  • 24
  • I do not understand the question. What is an "executable from a directory" or "executable out of a directory"? Do you mean that the executable file itself is located in the build directory? What research did you do? https://stackoverflow.com/questions/9345792/cmake-executable-location https://stackoverflow.com/questions/6594796/how-do-i-make-cmake-output-into-a-bin-dir https://cmake.org/cmake/help/latest/variable/EXECUTABLE_OUTPUT_PATH.html https://cmake.org/cmake/help/latest/prop_tgt/RUNTIME_OUTPUT_DIRECTORY.html#prop_tgt:RUNTIME_OUTPUT_DIRECTORY – KamilCuk Feb 02 '23 at 11:58
  • @KamilCuk I tried to improve my question with more explanation. – SkryptX Feb 02 '23 at 12:19
  • The whole answer just "depends" on the executable. If the executable depends on shared library you might need to set some LD_* variables so it finds the library. It depends. `Is there any guidance on this particular question?` Of course, you _want to write_ unit tests of your executable without installation, so you want to be able to execute it without affecting the system. – KamilCuk Feb 02 '23 at 12:32
  • The answer is **depends**. And it mostly **depends** on how you intend to build the application. For example: You may be linking to same `.so` files that you built alongside your project. Without specifying the `rpath` (posix systems) how will your executable find the dynamic libraries? So many questions and there is no specific answer to this. It all depends on you and if you want this executable to be easily transferable or not. – Milan Š. Feb 02 '23 at 13:24
  • Being able to run a program from the build tree could simplify "standard" workflows, like testing, but otherwise it is up to you. If your program requires specific layout of files (not libraries!), and reproducing this layout in the build tree looks too complex, then you could test the program in installed variant. I remember at least one of my projects where I choose to perform testing upon installation. – Tsyvarev Feb 02 '23 at 14:09
  • Thanks for the answers you gave. You could have easily submitted them as real answers with a bit of extended reasoning and I would have accepted them as answers. Even though there is not a clear right/wrong, there seem to be clear pro/contra reasoning. You can reopen and post an answer if you want. – SkryptX Feb 03 '23 at 11:29

0 Answers0