Skip to content

CMake: Prefer C++20 but minimum C++11#190

Merged
JeromeMartinez merged 1 commit intoMediaArea:masterfrom
cjee21:cmake
Mar 9, 2026
Merged

CMake: Prefer C++20 but minimum C++11#190
JeromeMartinez merged 1 commit intoMediaArea:masterfrom
cjee21:cmake

Conversation

@cjee21
Copy link
Contributor

@cjee21 cjee21 commented Mar 9, 2026

No description provided.

@JeromeMartinez JeromeMartinez merged commit ec88b2b into MediaArea:master Mar 9, 2026
10 checks passed
@cjee21 cjee21 deleted the cmake branch March 9, 2026 11:46
@JeromeMartinez
Copy link
Member

It seems to be C++20 or C+11, isn't it possible to select the latest C++ version available e.g. C++14 or C++17?

@cjee21
Copy link
Contributor Author

cjee21 commented Mar 9, 2026

It's supposed to degrade automatically if 20 is not available if I understand correctly how CMake works. Then if it drops below 11 which is the other condition then it will error. Not sure if this is compiler dependent.

@JeromeMartinez
Copy link
Member

JeromeMartinez commented Mar 9, 2026

I think I merged too quickly, I like the automatic upgrade idea but it is too much binary, as we are there please a new PR with something like

function(enable_latest_cxx target)
    if(DEFINED CMAKE_CXX_STANDARD)
        # User override
        target_compile_features(${target} PUBLIC cxx_std_${CMAKE_CXX_STANDARD})
        return()
    endif()
    set(_known_standards 26 23 20 17 14 11)
    foreach(std ${_known_standards})
        if("cxx_std_${std}" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
            target_compile_features(${target} PUBLIC cxx_std_${std})
            return()
        endif()
    endforeach()
    message(FATAL_ERROR "Compiler does not support C++11 or newer")
endfunction()

and adapt MIL PR accordingly.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants