Commit: 63ea8dd156b39eb57b73a953f5ac9ae54b7a447a Author: Sergey Sharybin Date: Mon Feb 9 22:23:21 2015 +0500 Branches: master https://developer.blender.org/rB63ea8dd156b39eb57b73a953f5ac9ae54b7a447a
Initial compilation support with C++11 featureset enabled This commit makes some preliminary fixes and tweaks aimed to make blender compilable with C++11 feature set. This includes: - Build system attribute to enable C++11 featureset. It's for sure default OFF, but easy to enable to have a play around with it and make sure all the stuff is compilable before we go C++11 for real. - Changes in Compositor to use non-named cl_int structure fields. This is because __STRICT_ANSI__ is defined by default by GCC and OpenCL does not use named fields in this case. - Changes to TYPE_CHECK() related on lack of typeof() in C++11 This uses decltype() instead with some trickery to make sure returned type is not a reference. - Changes for auto_ptr in Freestyle This actually conditionally switches between auto_ptr and unique_ptr since auto_ptr is deprecated in C++11. Seems to be not strictly needed but still nice to be ready for such an update anyway/ This all based on changes form depsgraph_refactor branch apart from the weird changes which were made in order to support MinGW compilation. Those parts of change would need to be carefully reviewed again after official move to gcc49 in MinGW. Tested on Linux with GCC-4.7 and Clang-3.5, other platforms are not tested and likely needs some more tweaks. Reviewers: campbellbarton, juicyfruit, mont29, lukastoenne, psy-fi, kjym3 Differential Revision: https://developer.blender.org/D1089 =================================================================== M CMakeLists.txt M SConstruct M build_files/scons/tools/btools.py M intern/cycles/util/util_types.h M source/blender/blenlib/BLI_compiler_compat.h M source/blender/compositor/intern/COM_OpenCLDevice.cpp M source/blender/freestyle/CMakeLists.txt M source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.cpp M source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.h A source/blender/freestyle/intern/view_map/AutoPtrHelper.h M source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.cpp M source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.h M source/blender/freestyle/intern/view_map/GridDensityProvider.h M source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.cpp M source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.h M source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.cpp M source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.h M source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp =================================================================== diff --git a/CMakeLists.txt b/CMakeLists.txt index 5df6d79..8e54ddc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -440,6 +440,10 @@ if(MSVC) set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${}) endif() +# Experimental support of C++11 +option(WITH_CPP11 "Build with C++11 standard enabled, for development use only!" OFF) +mark_as_advanced(WITH_CPP11) + # avoid using again option_defaults_clear() @@ -2663,6 +2667,16 @@ if(WITH_PYTHON) endif() endif() +if(WITH_CPP11) + if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") + 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() +endif() + # Include warnings first, so its possible to disable them with user defined flags # eg: -Wno-uninitialized set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}") diff --git a/SConstruct b/SConstruct index 7305edf..00a95b0 100644 --- a/SConstruct +++ b/SConstruct @@ -480,6 +480,13 @@ if env['WITH_BF_OPENMP'] == 1: else: env.Append(CCFLAGS=['-fopenmp']) +if env['WITH_BF_CPP11']: + if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'): + # Nothing special is needed, C++11 features are available by default. + pass + else: + env['CXXFLAGS'].append('-std=c++11') + #check for additional debug libnames if env.has_key('BF_DEBUG_LIBS'): diff --git a/build_files/scons/tools/btools.py b/build_files/scons/tools/btools.py index eb5036f..c5342d6 100644 --- a/build_files/scons/tools/btools.py +++ b/build_files/scons/tools/btools.py @@ -198,7 +198,8 @@ def validate_arguments(args, bc): 'C_WARN', 'CC_WARN', 'CXX_WARN', 'LLIBS', 'PLATFORM_LINKFLAGS', 'MACOSX_ARCHITECTURE', 'MACOSX_SDK', 'XCODE_CUR_VER', 'C_COMPILER_ID', 'BF_CYCLES_CUDA_BINARIES_ARCH', 'BF_PROGRAM_LINKFLAGS', 'MACOSX_DEPLOYMENT_TARGET', - 'WITH_BF_CYCLES_DEBUG', 'WITH_BF_CYCLES_LOGGING' + 'WITH_BF_CYCLES_DEBUG', 'WITH_BF_CYCLES_LOGGING', + 'WITH_BF_CPP11' ] @@ -653,7 +654,9 @@ def read_opts(env, cfg, args): ('BF_LLVM_LIBPATH', 'LLVM library path', ''), ('BF_LLVM_LIB_STATIC', 'LLVM static library', ''), - ('BF_PROGRAM_LINKFLAGS', 'Link flags applied only to final binaries (blender and blenderplayer, not makesrna/makesdna)', '') + ('BF_PROGRAM_LINKFLAGS', 'Link flags applied only to final binaries (blender and blenderplayer, not makesrna/makesdna)', ''), + + (BoolVariable('WITH_BF_CPP11', '"Build with C++11 standard enabled, for development use only!', False)), ) # end of opts.AddOptions() return localopts diff --git a/intern/cycles/util/util_types.h b/intern/cycles/util/util_types.h index df61b6e..187675e 100644 --- a/intern/cycles/util/util_types.h +++ b/intern/cycles/util/util_types.h @@ -481,18 +481,32 @@ enum InterpolationType { # define UNLIKELY(x) (x) #endif +#if defined(__cplusplus) && ((__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1800)) +# define HAS_CPP11_FEATURES +#endif + +#if defined(__GNUC__) || defined(__clang__) +# if defined(HAS_CPP11_FEATURES) +/* Some magic to be sure we don't have reference in the type. */ +template<typename T> static inline T decltype_helper(T x) { return x; } +# define TYPEOF(x) decltype(decltype_helper(x)) +# else +# define TYPEOF(x) typeof(x) +# endif +#endif + /* Causes warning: * incompatible types when assigning to type 'Foo' from type 'Bar' * ... the compiler optimizes away the temp var */ #ifdef __GNUC__ #define CHECK_TYPE(var, type) { \ - typeof(var) *__tmp; \ + TYPEOF(var) *__tmp; \ __tmp = (type *)NULL; \ (void)__tmp; \ } (void)0 #define CHECK_TYPE_PAIR(var_a, var_b) { \ - typeof(var_a) *__tmp; \ + TYPEOF(var_a) *__tmp; \ __tmp = (typeof(var_b) *)NULL; \ (void)__tmp; \ } (void)0 diff --git a/source/blender/blenlib/BLI_compiler_compat.h b/source/blender/blenlib/BLI_compiler_compat.h index 10c0752..876d2c4 100644 --- a/source/blender/blenlib/BLI_compiler_compat.h +++ b/source/blender/blenlib/BLI_compiler_compat.h @@ -37,4 +37,16 @@ # include <malloc.h> #endif +#if defined(__cplusplus) && ((__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1800)) +# define HAS_CPP11_FEATURES +#endif + +#if (defined(__GNUC__) || defined(__clang__)) && defined(HAS_CPP11_FEATURES) +extern "C++" { + /* Some magic to be sure we don't have reference in the type. */ + template<typename T> static inline T decltype_helper(T x) { return x; } +# define typeof(x) decltype(decltype_helper(x)) +} +#endif + #endif /* __BLI_COMPILER_COMPAT_H__ */ diff --git a/source/blender/compositor/intern/COM_OpenCLDevice.cpp b/source/blender/compositor/intern/COM_OpenCLDevice.cpp index 5960082..1b7acc9 100644 --- a/source/blender/compositor/intern/COM_OpenCLDevice.cpp +++ b/source/blender/compositor/intern/COM_OpenCLDevice.cpp @@ -180,7 +180,7 @@ void OpenCLDevice::COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemo bool breaked = false; for (offsety = 0; offsety < height && (!breaked); offsety += localSize) { - offset.y = offsety; + offset.s[1] = offsety; if (offsety + localSize < height) { size[1] = localSize; } @@ -195,7 +195,7 @@ void OpenCLDevice::COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemo else { size[0] = width - offsetx; } - offset.x = offsetx; + offset.s[0] = offsetx; error = clSetKernelArg(kernel, offsetIndex, sizeof(cl_int2), &offset); if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } diff --git a/source/blender/freestyle/CMakeLists.txt b/source/blender/freestyle/CMakeLists.txt index 7fbb219..c14a5c5 100644 --- a/source/blender/freestyle/CMakeLists.txt +++ b/source/blender/freestyle/CMakeLists.txt @@ -491,6 +491,7 @@ set(SRC intern/system/TimeUtils.h intern/view_map/ArbitraryGridDensityProvider.cpp intern/view_map/ArbitraryGridDensityProvider.h + intern/view_map/AutoPtrHelper.h intern/view_map/AverageAreaGridDensityProvider.cpp intern/view_map/AverageAreaGridDensityProvider.h intern/view_map/BoxGrid.cpp diff --git a/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.cpp b/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.cpp index 8bc7c09..3243c4d 100644 --- a/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.cpp +++ b/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.cpp @@ -100,22 +100,22 @@ ArbitraryGridDensityProviderFactory::ArbitraryGridDensityProviderFactory(unsigne ArbitraryGridDensityProviderFactory::~ArbitraryGridDensityProviderFactory() {} -auto_ptr<GridDensityProvider> ArbitraryGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, - const real proscenium[4]) +AutoPtr<GridDensityProvider> ArbitraryGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, + const real proscenium[4]) { - return auto_ptr<GridDensityProvider>(new ArbitraryGridDensityProvider(source, proscenium, numCells)); + return AutoPtr<GridDensityProvider>(new ArbitraryGridDensityProvider(source, proscenium, numCells)); } -auto_ptr<GridDensityProvider> +AutoPtr<GridDensityProvider> ArbitraryGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, const GridHelpers::Transform& transform) { - return auto_ptr<GridDensityProvider>(new ArbitraryGridDensityProvider(source, bbox, transform, numCells)); + return AutoPtr<GridDensityProvider>(new ArbitraryGridDensityProvider(source, bbox, transform, numCells)); } -auto_ptr<GridDensityProvider> ArbitraryGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source) +AutoPtr<GridDensityProvider> ArbitraryGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source) { - return auto_ptr<GridDensityProvider>(new ArbitraryGridDensityProvider(source, numCells)); + return AutoPtr<GridDensityProvider>(new ArbitraryGridDensityProvider(source, numCells)); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.h b/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.h index 652cb9b..c7939d3 100644 --- a/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.h +++ b/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.h @@ -58,10 +58,10 @@ public: ArbitraryGridDensityProviderFactory(unsigned numCells); ~ArbitraryGridDensityProviderFactory(); - auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const real proscenium[4]); - auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, - const GridHelpers::Transform& transform); - auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source); + AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const real proscenium[4]); + AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, + const GridHelpers::Transform& transform); + AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source); protected: unsigned numCells; diff --git a/source/blender/freestyle/intern/view_map/AutoPtrHelper.h b/source/blender/freestyle/intern/view_map/AutoPtrHelper.h new file mode 100644 index 0000000..17a43c1 --- /dev/null +++ b/source/blender/freestyle/intern/view_map/AutoPtrHelper.h @@ -0,0 +1,60 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] http://lists.blender.org/mailman/listinfo/bf-blender-cvs
