Treebeard the CMake generator

Treebeard in “The Lord of the Rings”

In recent years I have my own CMake generator “Treebeard” used to place larger amounts of files in a CMake library or project. The tool has now been tested and is usable without errors. I therefore now offer it here. It can be used for free for up to 20 files, above which a reasonable license is required to use it.

Benefits

CMake offers a number of major advantages for the software developer:

  • CMake is platform independent.
  • CMake can be used for desktop or embedded software.
  • CMake enables modular software development where modules are independently defined that can be used in different projects.

Approach

Treebeard is a tool that makes using CMake easier. It is not a replacement for CMake, and knowledge of the CMake commands and language structure is still necessary.

When importing external modules, the developer sometimes encounters the fact that manually configuring all paths in CMake is a difficult matter. It takes a lot of time to write a CMakeLists.txt file such that all source files and include paths can be used without errors.

Take the following example. Suppose the developer at STMicroelectronics wants to add the STM32L4 HAL driver to a CMake project. After downloading the driver from ST, the following folder structure will be visible:

In total the driver contains 238 files. How can these files be easily added as a CMake library? CMake offers the option of a “wildcard”, but this is an option that is not recommended! It is wiser to name all files manually as a basis for the “add_library …” command.

Boombaard is designed to search groups of files in directories looking for files that can be used in a CMake structure. For example, Boombaard can import a directory structure based on a few selected files, or as an entire directory with all files, or all directories in a recursive manner - it then takes everything that is in the directory. Boombaard offers the option to filter by file type as well as to block certain types of files.

Treebeard Mac OS
Treebeard Generator (Mac OS

The generated CMakeLists.txt file will then look like this:

## Boombaard gegenereerd CMakelists add_library bestand
## Bestand gegenereerd op : 2020-09-14 10:58:53.
## (c)2001-2018 Copyright Kiwanda Embedded Systemen

set(LibNaam STM32L4xx_HAL_Driver)

# Het absolute pad voor dit bestand “CMakeLists.txt” is “/Users/Developer/STM32/HALLibraries/STM32Cube/Repository/STM32Cube_FW_L4_V1.16.0/Drivers/STM32L4xx_HAL_Driver/“ 

## Definieer de minimale cmake versie.
cmake_minimum_required(VERSION 2.8.10)


## GemPath is een gemeenschappelijk pad dat gevonden wordt onder de bron, inclusief en bibliotheek paden.
set(GemPath0 ${CMAKE_CURRENT_SOURCE_DIR}/Inc)
set(GemPath1 ${GemPath0}/Legacy)
set(GemPath2 ${CMAKE_CURRENT_SOURCE_DIR}/Src)
set(GemPath3 ${GemPath2}/Legacy)



## SourcePath is een gemeenschappelijk pad voor de bronbestanden.
set(SourcePath0 ${GemPath3})
set(SourcePath1 ${GemPath2})
set(SourcePath2 ${GemPath1})
set(SourcePath3 ${GemPath0})



## Dit gedeelte geeft de include directories voor de bronbestanden aan.
set(AlleIncludeDirs ${SourcePath2} ${SourcePath3} )
include_directories(${AlleIncludeDirs})


## Geef een lijst van alle bronbestanden met de juiste paden.
set(SRCS0 stm32l4xx_hal_can.c )
set(Addition0Path ${SourcePath0})
foreach(FN ${SRCS0})
	list(APPEND SRCS ${Addition0Path}/${FN})
endforeach(FN)

set(SRCS1 stm32l4xx_hal_adc_ex.c stm32l4xx_hal_adc.c stm32l4xx_hal_can.c stm32l4xx_hal_comp.c stm32l4xx_hal_cortex.c 
	stm32l4xx_hal_crc_ex.c stm32l4xx_hal_crc.c stm32l4xx_hal_cryp_ex.c stm32l4xx_hal_cryp.c stm32l4xx_hal_dac_ex.c 
	stm32l4xx_hal_dac.c stm32l4xx_hal_dcmi.c stm32l4xx_hal_dfsdm_ex.c stm32l4xx_hal_dfsdm.c stm32l4xx_hal_dma_ex.c 
	stm32l4xx_hal_dma.c stm32l4xx_hal_dma2d.c stm32l4xx_hal_dsi.c stm32l4xx_hal_exti.c stm32l4xx_hal_firewall.c 
	stm32l4xx_hal_flash_ex.c stm32l4xx_hal_flash_ramfunc.c stm32l4xx_hal_flash.c stm32l4xx_hal_gfxmmu.c stm32l4xx_hal_gpio.c 
	stm32l4xx_hal_hash_ex.c stm32l4xx_hal_hash.c stm32l4xx_hal_hcd.c stm32l4xx_hal_i2c_ex.c stm32l4xx_hal_i2c.c 
	stm32l4xx_hal_irda.c stm32l4xx_hal_iwdg.c stm32l4xx_hal_lcd.c stm32l4xx_hal_lptim.c stm32l4xx_hal_ltdc_ex.c 
	stm32l4xx_hal_ltdc.c stm32l4xx_hal_mmc_ex.c stm32l4xx_hal_mmc.c stm32l4xx_hal_nand.c stm32l4xx_hal_nor.c 
	stm32l4xx_hal_opamp_ex.c stm32l4xx_hal_opamp.c stm32l4xx_hal_ospi.c stm32l4xx_hal_pcd_ex.c stm32l4xx_hal_pcd.c 
	stm32l4xx_hal_pka.c stm32l4xx_hal_pssi.c stm32l4xx_hal_pwr_ex.c stm32l4xx_hal_pwr.c stm32l4xx_hal_qspi.c 
	stm32l4xx_hal_rcc_ex.c stm32l4xx_hal_rcc.c stm32l4xx_hal_rng_ex.c stm32l4xx_hal_rng.c stm32l4xx_hal_rtc_ex.c 
	stm32l4xx_hal_rtc.c stm32l4xx_hal_sai_ex.c stm32l4xx_hal_sai.c stm32l4xx_hal_sd_ex.c stm32l4xx_hal_sd.c 
	stm32l4xx_hal_smartcard_ex.c stm32l4xx_hal_smartcard.c stm32l4xx_hal_smbus.c stm32l4xx_hal_spi_ex.c stm32l4xx_hal_spi.c 
	stm32l4xx_hal_sram.c stm32l4xx_hal_swpmi.c stm32l4xx_hal_tim_ex.c stm32l4xx_hal_tim.c stm32l4xx_hal_tsc.c 
	stm32l4xx_hal_uart_ex.c stm32l4xx_hal_uart.c stm32l4xx_hal_usart_ex.c stm32l4xx_hal_usart.c stm32l4xx_hal_wwdg.c 
	stm32l4xx_hal.c stm32l4xx_ll_adc.c stm32l4xx_ll_comp.c stm32l4xx_ll_crc.c stm32l4xx_ll_crs.c stm32l4xx_ll_dac.c 
	stm32l4xx_ll_dma.c stm32l4xx_ll_dma2d.c stm32l4xx_ll_exti.c stm32l4xx_ll_fmc.c stm32l4xx_ll_gpio.c stm32l4xx_ll_i2c.c 
	stm32l4xx_ll_lptim.c stm32l4xx_ll_lpuart.c stm32l4xx_ll_opamp.c stm32l4xx_ll_pka.c stm32l4xx_ll_pwr.c 
	stm32l4xx_ll_rcc.c stm32l4xx_ll_rng.c stm32l4xx_ll_rtc.c stm32l4xx_ll_sdmmc.c stm32l4xx_ll_spi.c stm32l4xx_ll_swpmi.c 
	stm32l4xx_ll_tim.c stm32l4xx_ll_usart.c stm32l4xx_ll_usb.c stm32l4xx_ll_utils.c )
set(Addition1Path ${SourcePath1})
foreach(FN ${SRCS1})
	list(APPEND SRCS ${Addition1Path}/${FN})
endforeach(FN)


list(SORT SRCS)

add_library(${LibNaam} STATIC ${SRCS})

This library can now easily be added to a CMake project:

This image has an empty alt attribute; the file name is Screenshot-2020-09-14-at-11.09.29-1024x716.png
The Boombaard file is used in a software project (Jetbrains CLion)

In addition to library files, Boombaard can also generate other CMake files:

  • Project files used to generate a desktop application.
  • Include files, to be used with the CMake “include” command.

Availability

Treebeard is available in three languages:

  • Dutch
  • German
  • English

The program can be downloaded from the Downloads page and is available for Mac OS X, Windows 7 and higher (64 bit) and Ubuntu Linux (64 bit).

Treebeard in the free version is limited to a maximum number of files that can be processed. To achieve Treebeard's full potential, you can: the webshop has a licensewhich can be purchased for Treebeard.