Problem: newer cmake versions set CMAKE_C(XX)_FLAGS at a later stage not allowing a user to override the standard

Solution: check for C(XX)_STANDARD/CMAKE_C(XX)_STANDARD as well
Fixes #4284
This commit is contained in:
Mark Jan van Kampen 2021-10-21 12:24:12 +02:00
parent 519e2bf129
commit c036d66286
No known key found for this signature in database
GPG Key ID: 64ED1D7C3283AD86

View File

@ -111,14 +111,14 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
endif()
if (NOT MSVC)
if(NOT CMAKE_CXX_FLAGS MATCHES "-std=")
if(NOT CMAKE_CXX_FLAGS MATCHES "-std=" AND NOT CXX_STANDARD AND NOT CMAKE_CXX_STANDARD)
# use C++11 by default if supported
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
endif()
if(NOT CMAKE_C_FLAGS MATCHES "-std=")
if(NOT CMAKE_C_FLAGS MATCHES "-std=" AND NOT C_STANDARD AND NOT CMAKE_C_STANDARD)
check_c_compiler_flag("-std=c11" COMPILER_SUPPORTS_C11)
if(COMPILER_SUPPORTS_C11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")