Cmake help

Hi,
I’ve never used make or CMake before and I would like to get some help in order to modify correctly all the required files so I can build two applications of my own and run them succesfully on the pixhawk. I find the tutorial (https://dev.px4.io/en/tutorials/tutorial_hello_sky.html) to create an application (on the dev guide) a little too superficial and everything being already set up, not so useful to learn actually !

So let’s imagine I want to create two applications, called app1 and app2 in my own folder called myfolder, saved in the src directory (src/myfolder). For now, what I’m doing is creating two subfolders app1 and app2. Those subfolders each contain a CMakeLists.txt file and a .cpp file. So the hierarchy is as follows :
| src
------| myfolder
---------------------| app1
-----------------------------| CMakeLists.txt
-----------------------------| app1.cpp
---------------------| app2
-----------------------------| CMakeLists.txt
-----------------------------| app2.cpp

And here is what’s inside the CMakeLists for the first app (taken directly from the example tutorial):

px4_add_module(
	MODULE myfolder__app1
	MAIN app1
	STACK_MAIN 2000
	SRCS
		app1.cpp
	DEPENDS
		platforms__common
	)
# vim: set noet ft=cmake fenc=utf-8 ff=unix : 

Some incomprehensions :

  1. Is a module an application ? Why do I need to specify the name of the directory app1 + the name of the root directory myfolder (hence myfolder__app1) ? Can’t I create two applications in the same folder (myfolder) with only one CMakeLists without having to create those two subfolders app1 and app2 ? If so, how ? Please, provide the CMakeListst.txt file to do so.

  2. What does the “MAIN” refer to ? Is it the name of a function ?

  3. Once this CMakeLists.txt is modified, do I need to change anything on the root CMakeLists.txt ? I’ve noticed when opening the root CMakeLists file on QtCreator that the folder myfolder doesn’t appear in the project tree. What should I modify in the rootCMakeLists.txt (or associated .cmake file) to make it appear there ?

  4. I’m wondering as well how can CMake works considering there is no CMakeLists file in the folder myfolder. I thought that each sub-folder has to contain a CMakeLists.txt file. I guess there is some code, somewhere, to by-pass this build-in mechanism. Please show me how to do so !

Finally, I need to modify this .cmake file : Firmware/cmake/configs/nuttx_px4fmu-v2_default.cmake to add those two lines :
myfolder/app1
myfolder/app2

  1. This cmake file has to be called from the root CMakeLists, could you please show me the calling path ? (I imagine another .cmake file is included in that root CMakeLists that itself calls the .nuttx_px4fmu-v2_default.cmake file).

  2. In the example tutorial, why then, just runing the make px4fmu-v2_default is enough ? Shouldn’t we run first the Cmake tool in order to generate the proper build file to call afterwards the make tool ? I’m confused here.

Thanks in advance for answering my beginner questions

Hi. I am thinking about the same questions. Did you get any answer yet?