CMake: Add option to enable -Werror cflag in some areas
authorSergey Sharybin <sergey.vfx@gmail.com>
Sat, 18 Jul 2015 08:35:03 +0000 (10:35 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sat, 18 Jul 2015 08:49:51 +0000 (10:49 +0200)
It is rather annoying attitude nowadays to use const qualifier all over the
place, including using it for multi-dimensional arrays. This isn't really
supported in GCC prior to version 5.0 because it considers such an arrays
to be a "pointer to a const pointer" which gives implicit casting errors.

It's not possible to disable this particular type of warnings treated as
errors in any GCC version prior to 5.0 as well, meaning currently usage of
-Werror globally in Blender code is not possible at all.

This commit makes it possible to use -Werror in areas which are complaint
with older GCC versions. New advanced CMake options are:

- WITH_COMPOSITOR_WERROR
- WITH_LIBMV_WERROR
- WITH_CYCLES_WERROR

CMakeLists.txt
extern/libmv/CMakeLists.txt
intern/cycles/CMakeLists.txt
source/blender/blenkernel/CMakeLists.txt
source/blender/compositor/CMakeLists.txt

index e214b23a5dbd0848adc1d64ba27b1af9e0da5f80..88cf5b73da60341232e26f93095b6623134bba53 100644 (file)
@@ -221,7 +221,11 @@ mark_as_advanced(WITH_SYSTEM_BULLET)
 option(WITH_GAMEENGINE    "Enable Game Engine" ${_init_GAMEENGINE})
 option(WITH_PLAYER        "Build Player" OFF)
 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ${_init_OPENCOLORIO})
-option(WITH_COMPOSITOR    "Enable the tile based nodal compositor" ON)
+
+# Compositor
+option(WITH_COMPOSITOR         "Enable the tile based nodal compositor" ON)
+option(WITH_COMPOSITOR_WERROR  "Treat warnings as errors in compositor code" OFF)
+mark_as_advanced(WITH_COMPOSITOR_WERROR)
 
 # GHOST Windowing Library Options
 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
@@ -318,9 +322,11 @@ if(UNIX AND NOT APPLE)
 endif()
 
 # Camera/motion tracking
-option(WITH_LIBMV         "Enable libmv structure from motion library" ON)
+option(WITH_LIBMV         "Enable Libmv structure from motion library" ON)
 option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." ${_init_LIBMV_SCHUR_SPECIALIZATION})
+option(WITH_LIBMV_WERROR  "Treat warnings as errors in Libmv (and Blender's motion tracking) code")
 mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
+mark_as_advanced(WITH_LIBMV_WERROR)
 
 # Freestyle
 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
@@ -354,18 +360,20 @@ if(UNIX AND NOT APPLE)
 endif()
 
 # Cycles
-option(WITH_CYCLES                                     "Enable cycles Render Engine" ON)
-option(WITH_CYCLES_STANDALONE          "Build cycles standalone application" OFF)
-option(WITH_CYCLES_STANDALONE_GUI      "Build cycles standalone with GUI" OFF)
+option(WITH_CYCLES                                     "Enable Cycles Render Engine" ON)
+option(WITH_CYCLES_STANDALONE          "Build Cycles standalone application" OFF)
+option(WITH_CYCLES_STANDALONE_GUI      "Build Cycles standalone with GUI" OFF)
 option(WITH_CYCLES_OSL                         "Build Cycles with OSL support" ${_init_CYCLES_OSL})
-option(WITH_CYCLES_CUDA_BINARIES       "Build cycles CUDA binaries" OFF)
+option(WITH_CYCLES_CUDA_BINARIES       "Build Cycles CUDA binaries" OFF)
 set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 sm_35 sm_50 sm_52 CACHE STRING "CUDA architectures to build binaries for")
 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
 unset(PLATFORM_DEFAULT)
-option(WITH_CYCLES_LOGGING     "Build cycles with logging support" ON)
-option(WITH_CYCLES_DEBUG       "Build cycles with extra debug capabilities" OFF)
+option(WITH_CYCLES_LOGGING     "Build Cycles with logging support" ON)
+option(WITH_CYCLES_DEBUG       "Build Cycles with extra debug capabilities" OFF)
+option(WITH_CYCLES_WERROR      "Treat warnings as errors in Cycles code" OFF)
 mark_as_advanced(WITH_CYCLES_LOGGING)
 mark_as_advanced(WITH_CYCLES_DEBUG)
+mark_as_advanced(WITH_CYCLES_WERROR)
 
 # LLVM
 option(WITH_LLVM                                       "Use LLVM" OFF)
index 089743567f0e5bf2ee05f04253fae96b35ee3a03..eb43285fdec3714181333cae143142594b6d27ee 100644 (file)
@@ -37,6 +37,11 @@ set(SRC
        libmv-capi.h
 )
 
+if(WITH_LIBMV_WERROR)
+       ADD_CHECK_C_COMPILER_FLAG(CMAKE_C_FLAGS C_WERROR -Werror)
+       ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS C_WERROR -Werror)
+endif()
+
 if(WITH_LIBMV OR WITH_GTESTS OR (WITH_CYCLES AND WITH_CYCLES_LOGGING))
        list(APPEND INC
                third_party/gflags
index acd6cd69329d55d77a13256346ffb397e4e844d7..c252a613cef74f3eedeb5a76c625ebabcf0149a1 100644 (file)
@@ -14,6 +14,11 @@ include(cmake/external_libs.cmake)
 # todo: refactor this code to match scons
 # note: CXX_HAS_SSE is needed in case passing SSE flags fails altogether (gcc-arm)
 
+if(WITH_CYCLES_WERROR)
+       ADD_CHECK_C_COMPILER_FLAG(CMAKE_C_FLAGS C_WERROR -Werror)
+       ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS C_WERROR -Werror)
+endif()
+
 if(NOT WITH_CPU_SSE)
        set(CXX_HAS_SSE FALSE)
        set(CXX_HAS_AVX FALSE)
index 37e5b36779fdadbe53a7edb57eac1fb0102dbd09..4f19c271d4123451287c12ec75899b71644666fd 100644 (file)
@@ -463,6 +463,20 @@ if(WITH_LIBMV)
        add_definitions(-DWITH_LIBMV)
 endif()
 
+if(WITH_LIBMV_WERROR)
+       if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
+               set_source_files_properties(intern/tracking.c
+                                           intern/tracking_auto.c
+                                           intern/tracking_detect.c
+                                           intern/tracking_plane_tracker.c
+                                           intern/tracking_region_tracker.c
+                                           intern/tracking_solver.c
+                                           intern/tracking_stabilize.c
+                                           intern/tracking_util.c
+                                           PROPERTIES COMPILE_FLAGS -Werror)
+       endif()
+endif()
+
 if(WITH_FFTW3)
        list(APPEND INC_SYS
                ${FFTW3_INCLUDE_DIRS}
index 0d35d060f5f7db1edda51045b8ac46cf5176c2bc..7a8c5596a578c509f5944dc5b660b9f47c765fee 100644 (file)
@@ -540,6 +540,12 @@ set(SRC
 list(APPEND INC
        ${CMAKE_CURRENT_BINARY_DIR}/operations
 )
+
+if(WITH_COMPOSITOR_WERROR)
+       ADD_CHECK_C_COMPILER_FLAG(CMAKE_C_FLAGS C_WERROR -Werror)
+       ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS C_WERROR -Werror)
+endif()
+
 data_to_c(${CMAKE_CURRENT_SOURCE_DIR}/operations/COM_OpenCLKernels.cl
           ${CMAKE_CURRENT_BINARY_DIR}/operations/COM_OpenCLKernels.cl.h SRC)