Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Molenkamp <github@lazydodo.com>2021-07-15 00:17:02 +0300
committerRay Molenkamp <github@lazydodo.com>2021-07-15 00:17:02 +0300
commitebf7673f83aea30dc126f0997c9c6f42f2cf5d9e (patch)
treeb83c80fa1ba24353158d90ad83be8f269e024f04 /CMakeLists.txt
parent093074aefe87259882b56a911d8eeb311408ff14 (diff)
CMake: Have CMake Control the C++ version.
We were manually setting the compiler flags for C++17 support for this previously. CMake can do this for us in a uniform way without having to worry about compiler specifics. Setting these flags manually somehow brought out some unwanted behaviour (CMake switching back to C++14) in the nightly CMake builds. Unsure if that's a CMake bug or planned new behaviour for future version, but best to play it safe. These flags are supported since CMake 3.1 so should not break anything. Reviewed by: Campbell Barton Differential Revision: https://developer.blender.org/D11891
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt28
1 files changed, 12 insertions, 16 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 91ac63d5e50..c5992993f91 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1705,22 +1705,18 @@ if(WITH_PYTHON)
endif()
endif()
-if(MSVC)
- string(APPEND CMAKE_CXX_FLAGS " /std:c++17")
- # Make MSVC properly report the value of the __cplusplus preprocessor macro
- # Available MSVC 15.7 (1914) and up, without this it reports 199711L regardless
- # of the C++ standard chosen above
- if(MSVC_VERSION GREATER 1913)
- string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus")
- endif()
-elseif(
- CMAKE_COMPILER_IS_GNUCC OR
- CMAKE_C_COMPILER_ID MATCHES "Clang" OR
- CMAKE_C_COMPILER_ID MATCHES "Intel"
-)
- string(APPEND CMAKE_CXX_FLAGS " -std=c++17")
-else()
- message(FATAL_ERROR "Unknown compiler ${CMAKE_C_COMPILER_ID}, can't enable C++17 build")
+# Select C++17 as the standard for C++ projects.
+set(CMAKE_CXX_STANDARD 17)
+# If C++17 is not available, downgrading to an earlier standard is NOT OK.
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+# Do not enable compiler specific language extentions.
+set(CMAKE_CXX_EXTENSIONS OFF)
+
+# Make MSVC properly report the value of the __cplusplus preprocessor macro
+# Available MSVC 15.7 (1914) and up, without this it reports 199711L regardless
+# of the C++ standard chosen above.
+if(MSVC AND MSVC_VERSION GREATER 1913)
+ string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus")
endif()
# Visual Studio has all standards it supports available by default