1

cmake is even easier than would I could ever hope for. At the moment what I ask myself is, how can I create one (or multiple) CMakeLists.txt file(s) such that the following project structure works:

my workspace
    src
        project1
        project2
    build
        project1
        project2

More concretely, I have the following two constraints that should determine both my project structure and my CMakeLists.txt file:

1) I use git and would like to commit only CMakeLists.txt and my source files, build should only by generated for each particular user who would like to work on this project via an IDE of his desire

2) If someone clones my repository, he will be able to run cmake that builds the directories as described above (/my workspace/build/project1 and /my workspace/build/project2) for the IDE that he/she desires, such that he can work on this project

3) The src directories should be clean such that anyone who works on the project can do this with his/her desired IDE, change src files and maybe CMakeLists.txt and afterwards commits what he/she has done, so that everyone else can checkout again and work with it in the same way

Huge advantage for collaboration in that way! However, cmake seems to build everything just into the directory where cmake is called from.

Now, for the questions:

a) In order to create my desired directories with the corresponding builds, is there any other way than to call cmake from newly build /my workspace/build/project1 and /my workspace/build/project2 folders?

b) Do you prefer a different directory structure to collaborate?

c) If yes to b), where do you put your CMakeLists.txt file(s), from where do you call cmake from and what is the general process for building?

d) QT creates moc files which seems to work fine. Do you commit them in any way or are they just put into the build directories for everyone who checks out and you make sure that they can be used?

IceFire
  • 4,016
  • 2
  • 31
  • 51
  • 1
    I put all generated files in the build folder and that includes the files generated by moc, uic ... – drescherjm Jul 10 '16 at 12:47
  • My build folder is on a completely different tree not under the workspace. The reason for that is I am building on windows and I build my projects with more than 1 compiler so I have more than 1 build folder for each source tree. – drescherjm Jul 10 '16 at 12:49

1 Answers1

0

Build directories aren't your thing to decide. Other developers will choose where to put the build directories (I have an 'outside' setup with eclipse: https://stackoverflow.com/a/38140914/4742108). Build directories are not commited into the repository.

CMakeLists.txt is per-project. You have two projects, so they shouldn't be related in any way from the point of view of CMake. Also, you should decide whether it's necessary to commit them to the same repository.

The moc files are not commited anywhere. They are local for each build, just like *.o files or any intermediate stuff that compiler generates.

Community
  • 1
  • 1
Velkan
  • 7,067
  • 6
  • 43
  • 87
  • Why can I include subfolders in CMakeLists.txt then which - when building - results in a perfectly fine `sln` with two `vcxproj` then? One business project could consist of many C++/VC/cmake projects, I do see nothing that speaks against it. – IceFire Jul 11 '16 at 07:04
  • I assumed that you were talking about CMake projects, not the vcxproj. (CMake project - it's when you write `project(...)` in `CMakeLists.txt`) – Velkan Jul 11 '16 at 07:14
  • yes, `project(...)` is in the top `CMakeLists.txt` and project1 and project2 have also `CMakeLists.txt` each which is included via `add_subdirectory`. At least, this seems to be the most intuitive organisation, but please correct me, if I'm wrong, I just start working with cmake! – IceFire Jul 11 '16 at 07:23
  • 1
    Ok, then it's one CMake project. I've learned something: CMake project corresponds to `*.sln`. Found a table: https://cognitivewaves.wordpress.com/cmake-and-visual-studio/ – Velkan Jul 11 '16 at 07:30