diff options
author | Brad King <brad.king@kitware.com> | 2021-10-06 13:36:56 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-10-06 14:36:39 (GMT) |
commit | 3add62462cfd91ad8f73bbbdab3f5e4e72c50a98 (patch) | |
tree | ff3504ba447378b5f450599a9e26c39ab354921b /Modules/CMakeDetermineCompilerId.cmake | |
parent | 5c4424e5b7d014eae7fc6951d4af32102f198306 (diff) | |
download | CMake-3add62462cfd91ad8f73bbbdab3f5e4e72c50a98.zip CMake-3add62462cfd91ad8f73bbbdab3f5e4e72c50a98.tar.gz CMake-3add62462cfd91ad8f73bbbdab3f5e4e72c50a98.tar.bz2 |
Xcode: Fix detection of default language standard when given -std= flags
If one uses `CFLAGS='-std=...'` or `CXXFLAGS='-std=...'` then the given
`-std=` flag(s) will always be used. That effectively changes the
compiler default standard level and extension settings. Fix the
Xcode generator's compiler id logic to preserve any `-std=` flag
so that the proper defaults are detected.
This problem was exposed by commit 4a0485be7f (cmStandardLevelResolver:
Avoid unnecessary flags, fix unset level logic, 2021-05-29), which
changed the logic to not pass any `-std=` flag if the standard level
and extension settings requested by the project match the default
(`stdIt <= defaultStdIt` became `stdIt < defaultStdIt`). The new
logic assumes the detected default standard matches what will actually
happen when the project is generated.
Diffstat (limited to 'Modules/CMakeDetermineCompilerId.cmake')
-rw-r--r-- | Modules/CMakeDetermineCompilerId.cmake | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 2582497..fa283fe 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -539,6 +539,7 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} else() set(id_toolset "") endif() + set(id_lang_version "") if("x${lang}" STREQUAL "xSwift") if(CMAKE_Swift_LANGUAGE_VERSION) set(id_lang_version "SWIFT_VERSION = ${CMAKE_Swift_LANGUAGE_VERSION};") @@ -549,8 +550,14 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} else() set(id_lang_version "SWIFT_VERSION = 2.3;") endif() - else() - set(id_lang_version "") + elseif("x${lang}" STREQUAL "xC" OR "x${lang}" STREQUAL "xOBJC") + if(CMAKE_${lang}_COMPILER_ID_FLAGS MATCHES "(^| )(-std=[^ ]+)( |$)") + set(id_lang_version "OTHER_CFLAGS = \"${CMAKE_MATCH_2}\";") + endif() + elseif("x${lang}" STREQUAL "xCXX" OR "x${lang}" STREQUAL "xOBJCXX") + if(CMAKE_${lang}_COMPILER_ID_FLAGS MATCHES "(^| )(-std=[^ ]+)( |$)") + set(id_lang_version "OTHER_CPLUSPLUSFLAGS = \"${CMAKE_MATCH_2}\";") + endif() endif() if(CMAKE_OSX_DEPLOYMENT_TARGET) set(id_deployment_target |