Passing basic basic compiler settings to a used library

I work on an open source library: GitHub - TorstenRobitzki/bluetoe: C++ Framework to build Bluetooth LE Server (GATT) The library is a mostly header only, with a few separate C++ (.cpp) files. The design of the library tries to be portable to very different platforms and to keep platform specific code as local as possible.

While using the library in a project, I’ve stumbled over the question, what would be the “best” way to pass the required, platform specific compiler settings to the compilation of a few C++ (.cpp) files. I think there are no needs to pass any linker settings to the libraries build process.

A small part of the library is very dependent on the intended hardware platform and requires some special defines and includes. (For example the path to a vendor SDK and configurations of this SDK)

All parts of the library needs settings that are common to the part of the software, that is using the library, like compiler settings to generate the correct assembly code (e.g. -mcpu=cortex-m4 -mthumb etc.).

Currently, the library is divided into smaller parts and one part of the library implements the required platform specific parts. That part (a static library) adds a dependency to a library that has to be provided by the library user (for example: bluetoe/CMakeLists.txt at master · TorstenRobitzki/bluetoe · GitHub)



I’m not sure, whether this is the “right” approach, or if there are better alternatives. What comes to my mind, would to use either all global settings (add_compile_options(), etc.) or to add the required settings to the toolchain file. Any suggestions recommendations?

I think a target that contains the flags you need and is linked “everywhere” makes sense to me. It’s what I did in VTK to handle things like sanitizer flags and the like at least.

1 Like