-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add support for CMake #8
base: testing
Are you sure you want to change the base?
Conversation
c87aed7
to
710623e
Compare
During refactoring I've also tried to add support for CMake install feature. It can be done but the CMake code becomes messy and you can only install one build configuration (Release/Debug) at a time. I don't think this feature is needed, just add the kernel as a submodule |
d83d3a9
to
4650233
Compare
I've started looking at the changes... I see the miosix_np_2 directory still survives, even though it can be removed at this point; CMake already provides support for IDEs built-in, so keeping the old NetBeans-specific files doesn't make much sense. Another thing I would change is to move the targets for the examples to the _examples directory, and split them into one for each sample instead of having them all together. Same thing holds for the testsuite. I would keep the current structure where at the top-level of the repo there is just a very simple template. I'm also not sure about renaming all the boards now, as we are thinking of splitting the concept of chips and boards so that may require further change in the future. But let's keep that for now. |
Also, I wouldn't worry about supporting installs for now, I don't see many use-cases for it. |
I'd really love to remove the
We could think about these ideas when we'll address Creating one I'm not a big fan of the top-level
About renaming some of the boards (basically I didn't like repeating |
I've split up the targets into multiple This could be very useful to verify that all code compiles when accepting new patches. At Skyward we have a pipeline running on every commit that notifies you via mail if your changes made some of the targets fail to compile. One single Now you need to manually build every example/test or write an additional script to do it for you (this is not a suggestion to do so 😅). A compromise could be to have a single We could also move the tests from the |
I tried to build Miosix with the current state of the Cmake build system, and I found some issues.
The list is a bit long... but it really didn't work out of the box. |
Declaring the examples all together in the same file is not the only way to build them all. One could create a top-level CMakeLists.txt that contains one add_subdirectory per every example, or write a temporary one-liner shell script that does the build thingamajig once for every target :) The fact that you want to build all the examples to check if the build system works is not the rule but the exception. A normal user typically wants to do one of these things:
Having all the examples declared together makes all these things more difficult for no reason. |
The toolchain file is not referenced because it is supposed to be specified during the build system generation. I usually run: cmake .. --toolchain=../miosix/cmake/toolchain.cmake -DCMAKE_BUILD_TYPE=Release
make
Thanks for pointing it out, I've read most of the CMake documentation but missed it.
The files
Other than the CMAKE_SYSTEM_NAME being Miosix and the object file extensions, what should we specify in a custom platform file? Which elf extension do we want? (I guess
I definitely need to lower the required version. I was already planning to do so, I'll install the 3.16 version and continue testing with that. As you said, other than the LINK_GROUP there should be no dependency on newer feature.
I'll try to support one board at a time to see also if this behavior changes. In general I'll continue working on what you pointed out, thanks! |
I should have addressed all of the things you pointed out.
We can specify the toolchain file in the CMakeLists using To build the main entrypoint in the root: mkdir build && cd build
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=../miosix/cmake/Toolchains/gcc-9.2.0.cmake \
-DCMAKE_BUILD_TYPE=Debug \
-DMIOSIX_OPT_BOARD=stm32f407vg_stm32f4discovery
make
Now the files follows the CMake naming conventions. I've also created a simple platform file that should set the correct file extensions. This allows to set One thing to note is that the object files still have the original file extension (stage_1_boot.cpp becomes stage_1_boot.cpp.o). CMake does this to handle the case where there are different files with the same name but with different extension (e.g. foo.c and foo.cpp). This can be bypassed with Another thing to not is that
Since all these options where defined in miosix/config/Makefile.inc we had left them all in config. Now the content of board_options.cmake files have been moved in the miosix/arch directory and split into multiple CMakeLists.txt. This follows the double switch construct in
Other notesI've made two big changes with respect to the previous version:
Now the new build system is much more similar the the current one. For now I've only added support for the I still need to review MxGui, but it should not be too difficult. |
dae9420
to
2937d74
Compare
3.16 is the version shipped with Ubuntu 20.04, the oldest currently supported Ubuntu release
…in `CMakeLists.txt`
… structure Now the content of `board_options.cmake` files have been moved in the miosix/arch directory and split into multiple CMakeLists.txt. One main file that includes the architecture specific file, and architecture files that includes the board one. This follows the switch constructs found in Makefile.inc. Also renamed same variable to use the same names of the old build system.
…ld system structure
…ATH` `CMAKE_MODULE_PATH` is already set in the toolchain file that the user must use.
Now the variables that are exposed in the cache have correct default values. Also, when the user changes the target board, other options (like the linker script or frequency) are checked and changed if necessary.
Previously the map file name was hardcoded in the linker flags. This was a problem when multiple programs (such as in the case of processes) where build, the files would override one another and only the last one would remain. Now the map file gets the same path and name as the binary for each target.
…cesses into RomFS images
…processes executables into a single directory and improved generation of bin and hex files With `miosix_create_processes_dir` you can now easily group processes into a folder that can then be used to generate a romfs image or that can be copied onto a micro sd
Miosix CMake support
A brief history
Support for CMake was first proposed in #3 by @mscuttari (2019), then further developed by @damianoamatruda at Skyward (2022), and now finalized to be merged into the kernel.
Skyward's use case is very specific because in their two main repos they maintain a lot of executables targetting many different boards (in Boardcore there is a test executable for each sensor's driver and in On-Board Software there is an executable for each board on the rocket). For this reason, they basically created a CMake library for each board in order to define multiple executables targeting different boards in a single
CMakeFile.txt
.Although the structure used by Skyward has worked well, to officially introduce CMake into the kernel we would like to follow as closely as possible the current Make based system. For this reason, Skyward's CMake was improved upon and now resembles much more a standard CMake based project.
Quick start
Move to you executable directory. We'll take
miosix/_examples/blinking_led
as an example.Build your code with:
And flash the binary on you board with:
In depth description
The proposed CMake base build system was developed targeting these features:
make program
miosix_settings.h
outside of kernel directorThe build system is contained in the
miosix
folder and composed of:CMakeLists.txt
: Includes specific architecture/board files, defines common kernel source files, include directories and flags, and runs thekernel_global_objects.pl
script.arch/CMakeLists.txt
: Contains the list of supported boards, include the selected board's files.arch/<family>/CMakeLists.txt
: Sets flags (e.g.-mcpu
,-mfpu
, ...) and source files common to all chips in the family.arch/<family>/<board>/CMakeLists.txt
: Configures chip/board specific things like the linker script and clock frequency.To simplify CMake files, common functionalities were moved into function which can be found in
miosix/cmake
. In particularmiosix_link_target(TARGET)
links a CMake target against the kernel, automatically configuring link libraries, binary file creation and the<TARGET>_program
target which can be used to flash the board.For the user to link with the kernel, a few lines of CMake are necessary:
Processes
Support for easily create processes was also added, along with a simple example (
miosix/_examples/processes
).The idea boils down to create the usual target for your kernel, one target for each process and then a target to build the combined RomFS image.
This will define two additional targets:
image
to build the RomFS image, andimage_program
to flash the binary on the board.Simple tutorial
After cloning Miosix you will find many examples in the
miosix/_examples
folder. We'll takeblinking_led
as an example.The
CMakeFile.txt
very simple, here a quick overview:These are common to any CMake project. They specify the minimum required version of CMake (3.16 is shipped with Ubuntu 20.04, so you should be fine) and define a new project called "BlinkingLED".
This tells the compiler to define
PARSING_FROM_IDE
so that the check inmiosix_settings.h
gets bypassed.This tells the build system which board you are using. You can find all the supported boards in the
miosix/arch
folders or by defining theMIOSIX_PRINT_BOARD_LIST
option (e.g. by runningcmake -Bbuild -DMIOSIX_PRINT_BOARD_LIST=True
).These includes the Miosix CMake project and provide the
miosix_link_target
function.add_executable(blinking_led simple.cpp) miosix_link_target(blinking_led)
These create a new target named
blinking_led
with the source filesimple.cpp
and links the miosix library.You can now build your code on the board with these two commands:
And if you also want to flash the code automatically on the board, you can run:
TODOs
Related pull requests: