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?
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 .
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With