add_bsp_based_library
Adds a static library that is based on a previously loaded BSP.
Syntax
add_bsp_based_library(
NAME <library name>
SOURCES <sources>
BSP_ALIAS <alias>
EXCLUDED_PLATFORMS <platform list>
[LINK_WHOLE_ARCHIVE]
)
NAME <library name>
SOURCES <sources>
BSP_ALIAS <alias>
EXCLUDED_PLATFORMS <platform list>
[LINK_WHOLE_ARCHIVE]
)
Overview
The add_bsp_based_library statement creates a static library based on a BSP loaded with the find_bsp command. It is similar to the regular add_library statement in CMake, but will automatically manage BSP references, code coverage and a few other nuances specific to embedded projects.
Parameters
- NAME
- Specifies the name of the library. Does not include the lib prefix or the extension.
- SOURCES
- Specifies the list of source files separated with spaces. The paths can be absolute, or relative to the current source directory. Use the ${BSP_ROOT} syntax to specify paths inside the BSP directory.
- BSP_ALIAS
- Optional. If the project loads multiple BSPs, this parameter allows selecting a specific BSP instance.
- EXCLUDED_PLATFORMS
- Optional. Can specify a list of project platforms, separated with spaces, where the library will not be built. When building the project for these platforms, the library will be still present, but will only contain a single dummy source file. This makes sure that references from other targets to this library will not cause an "unknown target" error.
- LINK_WHOLE_ARCHIVE
- If specified, the static library is tagged for whole archive linking. I.e. every executable referencing it will be linked against object file from this library (unused sections will still be discarded, unless disabled via the NO_GC_SECTIONS parameter in find_bsp). It is necessary for libraries containing static constructors, overrides for weak symbols, or sections without explicit references that rely on the KEEP() keyword in the linker script. As of VisualGDB 5.5, it is implemented by using CMake object libraries rather than the --whole-archive flag.
Remarks
You can configure most of the add_bsp_based_library parameters by opening the Properties window for the library node in Solution Explorer. In most cases there is no need to edit them manually.
Examples
The following example defines a static library and references it from the project
find_bsp(ID com.sysprogs.arm.stm32
VERSION 2020.06
MCU STM32F407VG)
add_bsp_based_executable(NAME Application1
SOURCES Application1.c)
add_bsp_based_library(NAME StaticLibrary
SOURCES StaticLibrary.cpp)
target_link_libraries(Application1 PRIVATE StaticLibrary)
VERSION 2020.06
MCU STM32F407VG)
add_bsp_based_executable(NAME Application1
SOURCES Application1.c)
add_bsp_based_library(NAME StaticLibrary
SOURCES StaticLibrary.cpp)
target_link_libraries(Application1 PRIVATE StaticLibrary)