@@ -7,20 +7,26 @@ include(CTest)
77
88# These flags are for binaries built by this particular CMake project (test_cppcodec, base64enc, etc.).
99# In your own project that uses cppcodec, you might want to specify a different standard or error level.
10+
11+ # Request C++11, or let the user specify the standard on via -D command line option.
12+ if (NOT CMAKE_CXX_STANDARD)
13+ set (CMAKE_CXX_STANDARD 11)
14+ endif ()
15+ set (CMAKE_CXX_STANDARD_REQUIRED ON )
16+ set (CMAKE_CXX_EXTENSIONS OFF )
17+
1018if (MSVC )
19+ # MSVC will respect CMAKE_CXX_STANDARD for CMake >= 3.10 and MSVC >= 19.0.24215
20+ # (VS 2017 15.3). Older versions will use the compiler default, which should be
21+ # fine for anything except ancient MSVC versions.
1122 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3" )
1223else ()
1324 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic" )
1425
15- # Request C++11
26+ # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD.
27+ # Remove this block once CMake >=3.1 has fixated in the ecosystem.
1628 if (${CMAKE_VERSION} VERSION_LESS 3.1)
17- # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
18- # remove this block once CMake >=3.1 has fixated in the ecosystem
19- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
20- else ()
21- set (CMAKE_CXX_STANDARD 11)
22- set (CMAKE_CXX_STANDARD_REQUIRED ON )
23- set (CMAKE_CXX_EXTENSIONS OFF )
29+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++${CMAKE_CXX_STANDARD} " )
2430 endif ()
2531endif ()
2632
0 commit comments