Skip to content

Setting CMAKE_CXX_STANDARD in the library build config is problematic #202

@kamchatka-volcano

Description

@kamchatka-volcano

Hi there! I encountered a problem introduced by toml11's CMakeLists which wasn't easy to figure out.
I tried to configure a project which uses toml11 and Microsoft.GSL libraries and was getting the error GSL: Requires at least CXX standard 14, user provided 11 from the GSL CMake config which was produced by the following code

if (${CMAKE_CXX_STANDARD} VERSION_LESS ${min_cxx_standard})
            message(FATAL_ERROR "GSL: Requires at least CXX standard ${min_cxx_standard}, user provided ${CMAKE_CXX_STANDARD}")
        endif()

In my projects I use target_compile_features to set the required C++ standard, so the variable CMAKE_CXX_STANDARD is left undefined, so I was puzzled until I find out that toml11 CMake sets this variable to 11 standard unconditionally.
Please consider to check this variable and give an error if it's less than 11 standard instead of setting it by yourself.

Also there's somewhat popular CMake guidelines that agrees that this variable should only be set by the end user of the library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions