Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux C++ project directory layout - CMake

Tags:

c++

linux

cmake

I would like to use some standard layout for my linux c++ project which is built using cmake and contains some executables and a library that these execs might link to. Currently I just had a folder for the project and a sub folder for each sub project. With a CMakeLists in the top level and one in each sub level that the opt level adds.

 Project-
            executable1
            executable2
            library

However I think it would be better setup like the following

Project -
    lib //Library output folder
    bin //Executable output folder
    src //Al cpp source files
    include //All header files
    test //All tests

I would have just one CMakeLists in top level. I can easily set this up in cmake. does anyone have reasons for choosing a different layout?

like image 674
Mark Avatar asked Mar 22 '11 11:03

Mark


1 Answers

I wouldn't put the lib, bin and test output directly on the project directory: if you want to make a debug and a release build, you get stuck, because you have only one placeholder. Out of source build is your friend! I would use something like:

Project
     src
     include
     CMakeLists.txt

These will be generated when using cmake:

Project_build_dbg
     bin
     lib
     test

Project_build_release
     bin
     lib
     test
like image 197
tibur Avatar answered Oct 29 '22 04:10

tibur