tags:

views:

37

answers:

1

Hello,

in my project, all source code resides in a folder named "src". There's a CMakeLists.txt file in my projects root (above "src"), but it merely declares the project and includes the "src" subdirectory. The CMakeLists.txt file under src does all the work, including "add_binary".

(Is that a common way of doing it, or should I put all the intelligence in the CMakeLists.txt file at the root level?)

If I build the project now, my binary is placed into the src folder, but this doesn't make a lot of sense, I'd rather have it in the root folder or a dedicated "bin" folder.

How do you do this?

+1  A: 

If you want to put all your executable files in a subdirectory called "bin", then you can use the following line in the top CMakeLists.txt file:

SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin"
    CACHE INTERNAL "Non-configurable executable directory.")

Just remove /bin and executables will be created in the root directory. A similar variable exists for libraries: LIBRARY_OUTPUT_PATH.

PS. Adding per-directory logic is fine. It seems to be the common way to do things and keeps things nicely organized.

rq