Skip to content
Snippets Groups Projects

Simplify enforcement of required c++ standard in cmake

Summary

Setting the minimal c++ standard in cmake is now done by a cmake feature-requirement cxx_std_17 on the dunecommon library target. This requirement is propagated to all other modules by linking against dunecommon. The cmake options CXX_MAX_STANDARD, CXX_MAX_SUPPORTED_STANDARD and DISABLE_CXX_VERSION_CHECK are removed. The cmake function dune_require_cxx_standard() is now deprecated.

Details

Enforcing a c++-standard is different between compilers, the flags might have different names or are not necessary at all. Sometimes the user needs a higher c++ standard than defined for dune-common, maybe just on a single target. The "cmake-way" of setting the c++-standard requirement is either a target property or a target feature. By using these, the highest required standard is passed to the compiler and there is not mixup with flags and standard requirements.

With this MR, the dunecommon library target gets the compile-feature cxx_std_17 that enforces at least c++-language standard 17 to be supported by the compiler. It might be, though, that not all c++-17 library feature are already implemented by the corresponding standard library. This has to be tested separately using individual feature tests.

The change has an implication on other dune modules and targets. The dunecommon target-properties are only propagated, if a downstream target links against it. The c++-standard is not a global property / global compiler flag anymore.

FAQ

  • How do downstream modules/libraries inherit the c++-standard requirement? Simply by linking against the dunecommon target.
  • How to enforce in a downstream module a different (higher) c++-standard for a specific target than is set in dune-common? Mixing c++ standards in dependent libraries is undefined behaviour, and thus not recommended. But a call of target_compile_features(<target> <PRIVATE|PUBLIC|INTERFACE> cxx_std_[17|20|...]) on the target with name <target> sets an arbitrary standard requirement for the code. This should be combined with a corresponding c++ standard used for all dune modules.
  • How to increase the c++ standard for all dune modules? The cmake variable CMAKE_CXX_STANDARD is used for all targets in a cmake project as default c++ standard. This can only be increased using a cxx_std_XXX feature requirement. Thus, one simply has to set this CMAKE_CXX_STANDARD to the highest standard requested by the dune modules.

TODO

  • Fix compiler-feature detection

Closes #217 (closed),#307 (closed) Requires !896 (merged)

Edited by Timo Koch

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Simon Praetorius mentioned in merge request !944 (closed)

    mentioned in merge request !944 (closed)

  • Simon Praetorius mentioned in merge request !924 (closed)

    mentioned in merge request !924 (closed)

  • Simon Praetorius added 223 commits

    added 223 commits

    • c15bbf76...d94e923e - 221 commits from branch core:master
    • e249d6d7 - remove CXX_MAX_STANDARD and CXX_MAX_SUPPORTED_STANDARD and deprecate dune_require_cxx_standard
    • cff67491 - Prefix new cmake functions with dune_

    Compare with previous version

  • Simon Praetorius resolved all threads

    resolved all threads

  • Simon Praetorius changed title from remove CXX_MAX_STANDARD and CXX_MAX_SUPPORTED_STANDARD and deprecate dune_require{-cxx-}standard to Simplify enforcement of required c++ standard in cmake

    changed title from remove CXX_MAX_STANDARD and CXX_MAX_SUPPORTED_STANDARD and deprecate dune_require{-cxx-}standard to Simplify enforcement of required c++ standard in cmake

  • added 1 commit

    • 8cfb3298 - Add missing include of CMakePushCheckState

    Compare with previous version

  • I think this should be merged. As there were concerns from @markus.blatt and @carsten.graeser, are you still concerned? Or can we merge anyway?

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading