Skip to content

Commit e695385

Browse files
committed
Automatically update the CXX_STANDARD
Folks are running into issues updating because the CXX standard is cached and we updated it. This patch allows CMake to update it to a minimum required version for Swift. If it's in the cache and too low, it will update it. If it's manually specified and too low, it will give a fatal error letting the dev know it's too low.
1 parent d3587a7 commit e695385

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,21 @@ if(SWIFT_ASM_AVAILABLE)
6969
endif()
7070

7171
# Use C++17.
72-
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
72+
set(SWIFT_MIN_CXX_STANDARD 17)
73+
74+
# Unset CMAKE_CXX_STANDARD if it's too low and in the CMakeCache.txt
75+
if($CACHE{CMAKE_CXX_STANDARD} AND $CACHE{CMAKE_CXX_STANDARD} LESS ${SWIFT_MIN_CXX_STANDARD})
76+
message(WARNING "Resetting cache value for CMAKE_CXX_STANDARD to ${SWIFT_MIN_CXX_STANDARD}")
77+
unset(CMAKE_CXX_STANDARD CACHE)
78+
endif()
79+
80+
# Allow manually specified CMAKE_CXX_STANDARD if it's greater than the minimum
81+
# required C++ version
82+
if(DEFINED CMAKE_CXX_STANDARD AND CMAKE_CXX_STANDARD LESS ${SWIFT_MIN_CXX_STANDARD})
83+
message(FATAL_ERROR "Requested CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} which is less than the minimum C++ standard ${SWIFT_MIN_CXX_STANDARD}")
84+
endif()
85+
86+
set(CMAKE_CXX_STANDARD ${SWIFT_MIN_CXX_STANDARD} CACHE STRING "C++ standard to conform to")
7387
set(CMAKE_CXX_STANDARD_REQUIRED YES)
7488
set(CMAKE_CXX_EXTENSIONS NO)
7589

0 commit comments

Comments
 (0)