nuttx icon indicating copy to clipboard operation
nuttx copied to clipboard

tools: add a convert tool to help migrate from make to cmake

Open raiden00pl opened this issue 2 years ago • 8 comments

Summary

A simple tool that convert arch/board makefiles to cmake files. Tested with stm32, don't know if it'll work with other architectures.

It's a really dumb not finished tool that is not ready for upstream so I keep it as a draft. Maybe someone will find it useful. The results usually require minor manual adjustments, but this makes the job much easier.

Usage: python tools/nxmake2cmake.py arch/arm/src/stm32f0l0g0 python tools/nxmake2cmake.py boards/arm/stm32/nucleo-f302r8

Impact

Testing

raiden00pl avatar Jul 11 '23 11:07 raiden00pl

@raiden00pl that is a great idea! In fact working on two build systems at same time it not easy, at least this script will help to simplify the process!

acassis avatar Jul 11 '23 13:07 acassis

@acassis That's right, using two build systems is a pain. I personally migrate all my NuttX based code to CMake now.

I was a bit skeptical about CMake as I don't know it at all, but once it's upstream it's a good motivation to learn. After a few days of using it, I can confidently say that it is a positive change. Faster build and out-of-source builds convince me. The CMake syntax isn't even that disgusting once you get used to it for a while ;)

raiden00pl avatar Jul 11 '23 13:07 raiden00pl

I agree @raiden00pl !!! It will make NuttX integration easier!

acassis avatar Jul 11 '23 19:07 acassis

Thank you a lot for your contribution! Please let me share a few comments and minor concerns:

Usage: python tools/nxmake2cmake.py arch/arm/src/stm32f0l0g0 python tools/nxmake2cmake.py boards/arm/stm32/nucleo-f302r8

I am not sure if there any systems out there still mapping python to python2, so IMHO it might be sensible to enforce the use of python3 for this script or, considering it already defines a shebang, just calling it directly i.e., tools/nxmake2cmake.py ....

Of course, the latter syntax would not be acceptable for non-POSIX environments e.g.: MS Windows, although I am not sure whether these a supported target within this project.

midokura-xavi92 avatar Jul 12 '23 15:07 midokura-xavi92

Usage: python tools/nxmake2cmake.py arch/arm/src/stm32f0l0g0

Coincidentally, the example provided above includes another Makefile:

https://github.com/apache/nuttx/blob/f43c7e99bedd8ea0cc2e3e6c2c796c38dbb8f354/arch/arm/src/stm32f0l0g0/Make.defs#L21

The file referred to above seems to define another bunch of source files. However, nxmake2cmake.py seems to explicitly ignore lines with include, so none of these source files are being appended to the generated CMakeLists.txt. Is this intended?

midokura-xavi92 avatar Jul 12 '23 16:07 midokura-xavi92

Nit: similar tools, such as parsememdump.py, have their +x bit set. Considering nxmake2cmake.py also defines a shebang (i.e., #!/usr/bin/env python3), maybe this was a leftover?

midokura-xavi92 avatar Jul 12 '23 16:07 midokura-xavi92

Usage: python tools/nxmake2cmake.py arch/arm/src/stm32f0l0g0

Coincidentally, the example provided above includes another Makefile:

https://github.com/apache/nuttx/blob/f43c7e99bedd8ea0cc2e3e6c2c796c38dbb8f354/arch/arm/src/stm32f0l0g0/Make.defs#L21

The file referred to above seems to define another bunch of source files. However, nxmake2cmake.py seems to explicitly ignore lines with include, so none of these source files are being appended to the generated CMakeLists.txt. Is this intended?

The included Makefile is handled elsewhere (https://github.com/apache/nuttx/blob/f43c7e99bedd8ea0cc2e3e6c2c796c38dbb8f354/arch/arm/src/cmake/armv7-m.cmake), so we can just ignore it.

Nit: similar tools, such as parsememdump.py, have their +x bit set. Considering nxmake2cmake.py also defines a shebang (i.e., #!/usr/bin/env python3), maybe this was a leftover?

I see that all .py files in tools/ have +x set, so I changed it here as well

raiden00pl avatar Jul 14 '23 08:07 raiden00pl

Hi @raiden00pl I have made the following changes:

  • removed repeated code line 66 ( content = board_cmakelist_get(path) )

  • fix paths for windows (arch directory)

  • added help more user-friendly

  • added version

I attach new version

nxmake2cmake.txt

simbit18 avatar May 08 '25 11:05 simbit18