Commit: 91747930a1f747c6e281e9b96eb0168bc517bbb5
Author: Sergey Sharybin
Date:   Sun May 22 13:41:55 2016 +0200
Branches: compositor-2016
https://developer.blender.org/rB91747930a1f747c6e281e9b96eb0168bc517bbb5

CMake: Solve compilation error with pre-compiled libraries and new GCC-6

Since version 6 G++ switched to C++11 by default, which breaks some logic
around WITH_CXX11 checks in out CMake files, leading to compilation errors.
This is easy to solve by explicitly enabling older C++ standard when C++11
was not explicitly enabled by CMake options.

However, G++-6 will also use new ABI by default even if older standard was
specified in the compiler options. This is being addressed by a special
define flag.

This tricks made it possible to use new G++-6 without need to recompile
any of pre-compiled libraries.

However, this might break compilation with existing system libraries, which
might already be using new ABI. We can't address this automatically, so
now we simply default WITH_C11 and WITH_CXX11 options to whatever defaults
of the current compiler are. This means, for G++-6 we'll set WITH_CXX11 to
truth. This should make linking with system libraries working just fine,
but to make pre-compiled libraries we still might need to disable CXX11.

This should work fine work for a new environments with G++-6 and install_deps
script run from scratch there, because C++ standard will be the same for
both Blender dependencies and Blender itself.

===================================================================

M       CMakeLists.txt
M       build_files/cmake/macros.cmake

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a950fc5..1539a55 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -478,9 +478,19 @@ if(WIN32)
 endif()
 
 # Experimental support of C11 and C++11
-option(WITH_C11 "Build with C11 standard enabled, for development use only!" 
OFF)
+#
+# We default options to whatever default standard in the current compiler.
+if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 
"6.0") AND (NOT WITH_CXX11))
+       set(_c11_init ON)
+       set(_cxx11_init ON)
+else()
+       set(_c11_init OFF)
+       set(_cxx11_init OFF)
+endif()
+
+option(WITH_C11 "Build with C11 standard enabled, for development use only!" 
${_c11_init})
 mark_as_advanced(WITH_C11)
-option(WITH_CXX11 "Build with C++11 standard enabled, for development use 
only!" OFF)
+option(WITH_CXX11 "Build with C++11 standard enabled, for development use 
only!" ${_cxx11_init})
 mark_as_advanced(WITH_CXX11)
 
 # Dependency graph
@@ -3024,12 +3034,22 @@ endif()
 
 if(WITH_CXX11)
        if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
+               # TODO(sergey): Do we want c++11 or gnu-c++11 here?
                set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
        elseif(MSVC12)
                # Nothing special is needed, C++11 features are available by 
default.
        else()
                message(FATAL_ERROR "Compiler ${CMAKE_C_COMPILER_ID} is not 
supported for C++11 build yet")
        endif()
+else()
+       # GCC-6 switched to C++11 by default, which would break linking with 
existing libraries
+       # by default. So we explicitly disable C++11 for a new GCC so no 
linking issues happens.
+       if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" 
VERSION_LESS "6.0"))
+               set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++98")
+               # We also disable any of C++11 ABI from usage, so we wouldn't 
even try to
+               # link to stuff from std::__cxx11 namespace.
+               add_definitions("-D_GLIBCXX_USE_CXX11_ABI=0")
+       endif()
 endif()
 
 # Visual Studio has all standards it supports available by default
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 239371c..08d26e5 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -803,7 +803,15 @@ macro(TEST_UNORDERED_MAP_SUPPORT)
        #  UNORDERED_MAP_NAMESPACE, namespace for unordered_map, if found
 
        include(CheckIncludeFileCXX)
-       CHECK_INCLUDE_FILE_CXX("unordered_map" HAVE_STD_UNORDERED_MAP_HEADER)
+
+       # Workaround for newer GCC (6.x+) where C++11 was enabled by default, 
which lead us
+       # to a situation when there is <unordered_map> include but which can't 
be used uless
+       # C++11 is enabled.
+       if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" 
VERSION_LESS "6.0") AND (NOT WITH_CXX11))
+               set(HAVE_STD_UNORDERED_MAP_HEADER False)
+       else()
+               CHECK_INCLUDE_FILE_CXX("unordered_map" 
HAVE_STD_UNORDERED_MAP_HEADER)
+       endif()
        if(HAVE_STD_UNORDERED_MAP_HEADER)
                # Even so we've found unordered_map header file it doesn't
                # mean unordered_map and unordered_set will be declared in

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to