There is some CMake magic I don’t understand. How should a CMakeLists.txt file look like for a small C++ project with directories like this:
.
├── bin
└── src
├── src
└── test
bin — directory for built program
src/src — directory for source
src/test — directory for tests
The tests will need to include files from src/src.
I’d like to manage all the operations from cmake, however at this moment I even can’t cause cmake to compile file in src/c.cpp.
Any help, links are welcome.
Your CMake files should reside in the main source directory and its sub-directories. The easiest approach is to have one
CMakeLists.txtin thesrcdirectory, which includes all files fromsrc/srcandsrc/test. A very minimalistic example could look like the following:The output directory is normally not specified, because you can have different active
builds in parallel with
different options, e.g. you can have one build in debug mode
-O0 -g, another one in release mode with-O2 -gflags and a third one in release mode with heavy optimization flags-O3. Every build resides in its own directory (e.g.build-debug,build-rel,build-opt).You should create the output directory (
binin your case) manually and call thecmakecommand inside this directory. As an argument you have to supply the path to the mainCMakeLists.txt. In other words, just executewhen you are inside
bin. This will take all files from thesrcdirectory and put the output to thebindirectory.You can easily create a second output directory, say
bin2, where you specify different build flags. Theccmakeprovides a very minimalistic GUI for that.