-
Notifications
You must be signed in to change notification settings - Fork 13.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmake remove circular linking and reorganize #9292
Conversation
9d002bd
to
a026f9e
Compare
422a415
to
66161e9
Compare
@Stifael you might be interested in some of this. Once this is in PX4 we can update ECL with something more modular that's also a proper standalone cmake library. |
CMakeLists.txt
Outdated
set(PX4_BUILD_TYPE "MinSizeRel") | ||
elseif (${OS} STREQUAL "bebop") | ||
set(PX4_BUILD_TYPE "MinSizeRel") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is depreciated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually just wrong. ${OS} is never set to bebop.
@@ -38,6 +38,5 @@ px4_add_module( | |||
SRCS | |||
tune_control.cpp | |||
DEPENDS | |||
platforms__common | |||
tunes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so much better
@@ -53,6 +53,8 @@ if (NOT ${OS} STREQUAL "qurt") | |||
simulator_mavlink.cpp) | |||
endif() | |||
|
|||
add_subdirectory(ledsim) | |||
|
|||
px4_add_module( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice to free ecl a from px4 dependencies such that it could be included similar to the simulator
this makes the px4 cmake structure much more understandable |
1 similar comment
this makes the px4 cmake structure much more understandable |
Here's another good summary of modern cmake. https://gist.github.com/mbinna/c61dbb39bca0e4fb7d1f73b0d66a4fd1 |
8bacecc
to
b06b977
Compare
4005167
to
27debf9
Compare
- px4_add_module now requires MAIN - px4_add_library doesn't automatically link
- set BOARD_NUMBER_BRICKS to 0 for boards without analog power bricks
27debf9
to
f57f22c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good as far as I can tell (proper cmake has remained a mystery to me so far).
There's an incremental build issue when removing an aiframe file & from CMakeLists.txt, you get:
ninja: error: '../../ROMFS/px4fmu_common/init.d/4040_reaper', needed by 'genromfs/px4fmu_common/init.d/rcS', missing and no known rule to make it
But it already exists on master.
Let's make sure get it in soon.
# vim: set noet ft=cmake fenc=utf-8 ff=unix : | ||
controllib | ||
flight_tasks | ||
git_ecl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are both git_ecl and ecl needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment yes. The git_ecl target is on the Firmware side and ensures the submodule is actually in place. Then ecl is the actual library in the ecl project. Mixing submodule dependencies into the build system like this is a bit unusual, but has worked surprisingly well.
Later we can split the ecl project into separate libs for ekf, tecs, etc that build standalone or within PX4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, it's just not obvious for someone adding a new module
Thanks for the review. Can you open an issue about any incremental build issues you hit? |
|
PX4 is supposed to be modular, but because of the current cmake build system everything is built and linked together as a large pile of code. The lines between different modules and different layers of the system have become blurred in many cases.
This PR changes the PX4 cmake build slightly to allow us to actually enforce and maintain modularity. We can then tease apart some of these interconnected components and work towards more well defined layers (#8784 (comment)).
First instead of calling everything a module (px4_add_module) and linking it all together (with multiple passes to resolve circular dependencies) I changed px4_add_module to require a MAIN. Any modules included in a configuration (eg nuttx_px4fmu-v2_default.cmake) are included in the final PX4 binary. Modules without a main are now simply libraries (px4_add_module -> px4_add_library). Some libraries are part of PX4 and need access to uORB, the parameter system, logging system, etc (PX4 libraries: px4_add_library), but many don't (regular cmake: add_library).
Libraries aren't automatically included (linked) in your final PX4 binary, they must be added as a module dependency. As a result we don't need to list them per configuration. Including a particular module pulls in a library only if it's needed as a dependency. With that dependency comes additional include directories and build flags if specified by the library.
PX4 CMake Changes
px4_add_module (PX4 Modules)
px4_add_library (PX4 libraries)
add_library
cmake configurations
all libraries (src/lib) are automatically included in every build
only the ones that are dependencies of PX4 modules (px4_add_module DEPENDS) are actually built
other common pieces (eg src/drivers/boards/${BOARD}) are also included automatically now
this removes the need for every cmake configurations to exhaustively list every component and core system piece. Modules are specified directly, and then the libraries are pulled in as dependencies.
example, here's how the px4fmu-v2 configuration (nuttx_px4fmu-v2_default.cmake) is simplified.
This also removes the need to link with
--start-group/--end-group
to resolve the circular dependencies.Notes
A few ideas taken from CppCon 2017: Mathieu Ropert “Using Modern CMake Patterns to Enforce a Good Modular Design”.
Related issues and PRs move posix, nuttx, qurt components into platforms #8784 (comment), RFC: Directory structure refactoring #8127, Build overlay #7705, Core rearchitecture for modularity #7806, and PX4 Flight Stack Structure Proposal #7318