Skip to content

[BUILD] Transition to CMake to manage the build system#5743

Merged
fiam merged 50 commits intomasterfrom
agh_cmake
Sep 20, 2020
Merged

[BUILD] Transition to CMake to manage the build system#5743
fiam merged 50 commits intomasterfrom
agh_cmake

Conversation

@fiam
Copy link
Member

@fiam fiam commented May 16, 2020

Still in progress, only F411 targets have been converted

@fiam fiam force-pushed the agh_cmake branch 2 times, most recently from d9da2ab to 95186da Compare May 16, 2020 21:02
@digitalentity digitalentity changed the base branch from development to master June 8, 2020 10:15
fiam added 24 commits August 25, 2020 18:19
- Add openocd_<target>: runs openocd for the target
- Add openocd_flash_<target>: flashes the target using openocd.
 It works with both an already running openocd instance as well
 as launching its own one. Uses a helper tool that requires python.
- Add openocd_cfg_<target>: generates openocd config for target. Used
 for generating an openocd config automatically when launching
 a debug session from an IDE.
FLYWOOF411, FLYWOOF72DUAL, FOXEERF722V2 and IFLIGHTF4_SUCCEXD
WARNIGNS_AS_ERRORS, DEBUG_HARDFAULTS and SEMIHOSTING can now be
turned on/off
- Rename function for target name definitions to include full MCU
names, so we can support multiple size variants of the same MCU
cleanly
- Add cmake targets for .bin/.hex files from .elf files
- Add targets for bootloader generation
- Add targets for combining the bootloader with the main firmware
Build didn't fail with -Os or -O2 due to dead code elimination.
Otherwise there were some undefined symbols when USE_OSD or
USE_RX_NRF24 were not defined.
When no alternative toolchain is provided, we explicitely include
the src/tests directory, so the check target (which builds and runs
tests) is available from a main source build without having to
build specifically the src/tests directory
This way the git revision is automatically regenerated when the
revision changes without having to re-run cmake's configuration
step.
@stronnag
Copy link
Collaborator

On buster again, the generated Makefile advertises clean_TARGET targets. Fails

$ make clean_MATEKF405
Removing intermediate files for MATEKF405
CMake Error: cmake version 3.13.4
Usage: /usr/bin/cmake -E <command> [arguments...]
Available commands: 
  capabilities              - Report capabilities built into cmake in JSON format
  chdir dir cmd [args...]   - run command in a given directory
  compare_files file1 file2 - check if file1 is same as file2
  copy <file>... destination  - copy files to destination (either file or directory)
  copy_directory <dir>... destination   - copy content of <dir>... directories to 'destination' directory
  copy_if_different <file>... destination  - copy files if it has changed
  echo [<string>...]        - displays arguments as text
  echo_append [<string>...] - displays arguments as text but no new line
  env [--unset=NAME]... [NAME=VALUE]... COMMAND [ARG]...
                            - run command in a modified environment
  environment               - display the current environment
  make_directory <dir>...   - create parent and <dir> directories
  md5sum <file>...          - create MD5 checksum of files
  sha1sum <file>...         - create SHA1 checksum of files
  sha224sum <file>...       - create SHA224 checksum of files
  sha256sum <file>...       - create SHA256 checksum of files
  sha384sum <file>...       - create SHA384 checksum of files
  sha512sum <file>...       - create SHA512 checksum of files
  remove [-f] <file>...     - remove the file(s), use -f to force it
  remove_directory dir      - remove a directory and its contents
  rename oldname newname    - rename a file or directory (on one volume)
  server                    - start cmake in server mode
  sleep <number>...         - sleep for given number of seconds
  tar [cxt][vf][zjJ] file.tar [file/dir1 file/dir2 ...]
                            - create or extract a tar or zip archive
  time command [args...]    - run command and display elapsed time
  touch file                - touch a file.
  touch_nocreate file       - touch a file but do not create it.
  create_symlink old new    - create a symbolic link new -> old

make[3]: *** [src/main/target/MATEKF405/CMakeFiles/clean_MATEKF405.dir/build.make:58: src/main/target/MATEKF405/CMakeFiles/clean_MATEKF405] Error 1
make[2]: *** [CMakeFiles/Makefile2:32937: src/main/target/MATEKF405/CMakeFiles/clean_MATEKF405.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:32944: src/main/target/MATEKF405/CMakeFiles/clean_MATEKF405.dir/rule] Error 2
make: *** [Makefile:11753: clean_MATEKF405] Error 2

Fails more gracefully on Arch / cmake 3.18

make clean_MATEKF405
Scanning dependencies of target clean_MATEKF405
Removing intermediate files for MATEKF405
CMake Error: File to remove does not exist and force is not set: /home/jrh/Projects/fc/inav/build/inav_2.6.0_MATEKF405_bl.hex
make[3]: *** [src/main/target/MATEKF405/CMakeFiles/clean_MATEKF405.dir/build.make:79: src/main/target/MATEKF405/CMakeFiles/clean_MATEKF405] Error 1
make[2]: *** [CMakeFiles/Makefile2:28486: src/main/target/MATEKF405/CMakeFiles/clean_MATEKF405.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:28493: src/main/target/MATEKF405/CMakeFiles/clean_MATEKF405.dir/rule] Error 2
make: *** [Makefile:11902: clean_MATEKF405] Error 2

In both cases, I'd only made the MATEKF405 target, not the _bl variant.

@fiam
Copy link
Member Author

fiam commented Aug 26, 2020

@stronnag Thanks for the heads up! I've added a workaround for removing files while using versions earlier than 3.17 (where cmake -E rm was introduced). PTAL

@stronnag
Copy link
Collaborator

LGTM. Built on buster with and without distro compiler installed, clean_TARGET is working correctly with cmake 3.13 and 3.18 (Arch).

@stronnag
Copy link
Collaborator

@fiam please take a look at the new Building in Linux document; I'm a cmake neophyte.

stronnag and others added 14 commits August 28, 2020 16:09
The MCU preprocessor defines are slightly different, so these
needed some small tweaking since the page layout selection is
MCU-dependant.
While depending in the output files of other targets work fine with
cmake 3.17+ and/or ninja, it fails with cmake 3.14 and make. This
way works fine with all the combinations of cmake+backend we do
care about.
We had several target.mk_ files in order to disable them. With cmake,
those targets are fully defined but we just skip them from CI builds
and releases, so these old files can be safely deleted.
@stronnag
Copy link
Collaborator

stronnag commented Sep 18, 2020

FYI, clean inconsistency

$ make clean_MATEKF405
Scanning dependencies of target clean_MATEKF405
Removing intermediate files for MATEKF405
Built target clean_MATEKF405
[jrh@eeyore]$ make clean
make[2]: src/main/target/MATEKF405/CMakeFiles/clean_MATEKF405OSD.dir/build.make: No such file or directory
make[2]: *** No rule to make target 'src/main/target/MATEKF405/CMakeFiles/clean_MATEKF405OSD.dir/build.make'.  Stop.
make[1]: *** [CMakeFiles/Makefile2:28017: src/main/target/MATEKF405/CMakeFiles/clean_MATEKF405OSD.dir/clean] Error 2
make: *** [Makefile:109: clean] Error 2

"don't be silly" is an appropriate response.

Removing CMAKE_CURRENT_BINARY_DIR directly is problematic, since it
also removes files generated by cmake and can cause errors that will
require regenerating the build system files.

Instead, call <backend> clean (e.g. make clean or ninja clean) in
CMAKE_CURRENT_BINARY_DIR. This ensures all the files generated by
the build system are removed, but any files generated as a part of
cmake's configuration step are preserved.
@fiam
Copy link
Member Author

fiam commented Sep 20, 2020

@stronnag You've raised a good point. The clean_<target> targets, as implemented, were a bit problematic because they removed some files that they shouldn't touch (generated by cmake at configure time). I've implemented them in a slightly different way that should prevent this problem you've found (with the tradeoff of making them slightly slower, but not that much).

@fiam fiam merged commit 0c716eb into master Sep 20, 2020
@fiam fiam deleted the agh_cmake branch September 20, 2020 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants