Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put the binary in CMake?

Tags:

cmake

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?

like image 613
theone Avatar asked Aug 07 '10 19:08

theone


People also ask

Where do I build the CMake binaries?

The binary folder is where CMake generates the build pipeline. You can create the binary folder anywhere you want. A common practice is to create a subdirectory build beneath CMakeLists. txt .

What is CMake binary?

Binary tree¶ This is hierarchy of directories where CMake will store generated files and where native build tool will store it's temporary files. Directory will contain variables/paths which are specific to your environment so they doesn't mean to be shareable.

How do I use CMake commands?

Running CMake from the command line From the command line, cmake can be run as an interactive question and answer session or as a non-interactive program. To run in interactive mode, just pass the option “-i” to cmake. This will cause cmake to ask you to enter a value for each value in the cache file for the project.


1 Answers

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(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

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

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

like image 60
richq Avatar answered Nov 16 '22 02:11

richq