'How to make CLion work with subdirectories

I'm currently a student and need to learn C. I'm working on a Debian Virtual Machine using CLion.

To manage my assignments better, I created a github repository to synchronize and store all my C assignments. So I have one project in git containing sub-directories for every assignment I have to do. All assignments are independent of each other.

My current project structure looks like this.

project
   assignment 1
      main.c
      some.c
      some.h
      Makefile
      ...
   assignment 2
      main.c
      some.c
      some.h
      Makefile
      ...
   assignment 3
      main.c
      some.c
      some.h
      Makefile
      ...
   ...

However I can not start any of the main.c files. I used VisualStudio Code before CLion and had to create those makefiles to make my programs run. I can still use the terminal in CLion to use the make-command and start the programs from there but I'd like for them to work properly in CLion.

I read that CLion uses CMakeList.txt-files but I'm not familiar with them. I tried to auto-create it using the blue prompt at the top of a source file but the window that pops up after that has every folder and (almost) every file checked. I think this is wrong (I suspect CLion thinks every directory and every file is part of one large project)

CLion create CMakeList.txt

How do I have to set up CLion/CMakeList.txt to work like I want? Does ever sub-directory needs it's own CMakeList.txt? Is it even possible to have completely independent programs in sub-directories within the same project?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source