Interface library CMAKE_CXX_STANDARD propagation to dependent targets in multi-config generators
0 reputation · 11 Apr 2020, 18:00 UTC
An interface library declares CMAKE_CXX_STANDARD 17 and exposes compile features through INTERFACE_COMPILE_FEATURES. Dependent executables link against it. The goal is for every consumer to inherit the same C++ standard flag in both Debug and Release configurations when using Visual Studio or Xcode.
This assumes CMake 3.8 through 3.28. CMake evaluates CMAKE_CXX_STANDARD per configuration, but INTERFACE_COMPILE_FEATURES does not accept $CONFIG generator expressions. It is unclear whether the standard flag should vary by configuration or remain uniform across the build tree, and whether consumers can override the inherited standard without breaking feature propagation.
Should INTERFACE_COMPILE_FEATURES re-evaluate CMAKE_CXX_STANDARD independently for each configuration in a multi-config generator? Can a consuming target specify a different CMAKE_CXX_STANDARD while still linking the interface library? What is the supported mechanism to propagate configuration-dependent standard flags without duplicating explicit compile options?