Skip to content

Default toolkit-owned C++ targets to CXX_EXTENSIONS OFF #36

Closed

Description

@sean-parent

Goal

Minimize client CMake infrastructure by supplying a portable C++ dialect default in cpp-library, rather than requiring each C++-only library to add:

set(CMAKE_CXX_EXTENSIONS OFF)

Current behavior

In v5.8.1, the core library setup requests the minimum C++ standard through target_compile_features(... cxx_std_${ARG_REQUIRES_CPP_VERSION}). That does not independently disable compiler-specific extensions.

CMake initializes the CXX_EXTENSIONS target property from CMAKE_CXX_EXTENSIONS, when set, or otherwise from the compiler default. On Clang/GCC, disabling extensions can select -std=c++20 instead of -std=gnu++20.

A client directory-level setting also becomes an inherited default for subsequently created dependency targets. A toolkit-owned target policy would be more precise.

Suggested change

Default CXX_EXTENSIONS to OFF for targets created by cpp-library:

  • Compiled library targets.
  • Test and example executables.
  • Compile-fail executables.

Respect an explicit caller preference, such as a defined CMAKE_CXX_EXTENSIONS, including an explicit ON. Do not change the caller directory/global default or unrelated dependency targets.

Header-only libraries have no compilation of their own, and CXX_EXTENSIONS is not a transitive usage requirement. Their toolkit-owned tests and examples should exercise standard mode; consumer targets retain their own dialect choice.

Document that REQUIRES_CPP_VERSION chooses the minimum standard level, while CXX_EXTENSIONS controls the extended dialect. Disabling extensions does not by itself reject every nonstandard construct; pedantic diagnostics are a separate concern.

Regression coverage

  • With no explicit extension preference, all toolkit-owned compiled targets have CXX_EXTENSIONS=OFF.
  • An explicit caller ON or OFF is respected.
  • Applicable Clang/GCC compile commands use the standard rather than GNU dialect by default.
  • Caller defaults and unrelated targets are unaffected.
  • Header-only test/example coverage and compile-fail targets use the same policy.
  • Installed targets do not impose a transitive extension policy on consumers.

References

Activity

  1. sean-parent commented on Nov 18, 2026

    @sean-parent
    MemberAuthor

    Verified that this was fixed before the current branch by commit 36d5e2a, merged in #40 and already present on main. Compiled library targets and toolkit-created test/example/compile-fail executables default CXX_EXTENSIONS to OFF only when CMAKE_CXX_EXTENSIONS is undefined; explicit caller choices remain authoritative and unrelated targets are not changed. Re-ran cmake -P tests/setup/test_target_type.cmake: all 11 cases passed, including dialect defaults, explicit ON/OFF, header-only coverage, and standard-mode compile commands. Closing as already completed; the upcoming PR is not the fixing change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions