Commit: c7a5c48cbad0062c55bf9fa6df2926646b2c3091
Author: Sergey Sharybin
Date:   Fri Apr 21 10:58:01 2017 +0200
Branches: master
https://developer.blender.org/rBc7a5c48cbad0062c55bf9fa6df2926646b2c3091

CMake: Add option to link against system-wide Gflags library

It is disabled by default, so should not affect existing configurations.

Main benefits of this goes as:

- Linux distros can use that to avoid libraries duplication and link
  blender package against gflags package from the system.

- It it easier to test whether Blender works with updated version of
  Gflags prior to re-bundling the library.

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

M       CMakeLists.txt
A       build_files/cmake/Modules/FindGflags.cmake
M       build_files/cmake/Modules/GTestTesting.cmake
M       build_files/cmake/macros.cmake
M       extern/CMakeLists.txt
M       intern/cycles/app/CMakeLists.txt
M       intern/cycles/cmake/external_libs.cmake
M       intern/libmv/CMakeLists.txt
M       intern/libmv/bundle.sh
M       intern/libmv/intern/logging.cc
M       source/blenderplayer/CMakeLists.txt
M       tests/gtests/CMakeLists.txt
M       tests/gtests/testing/CMakeLists.txt
M       tests/gtests/testing/testing_main.cc

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

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3a91e1b655a..748ed649800 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -363,6 +363,10 @@ option(WITH_LIBMV         "Enable Libmv structure from 
motion library" ON)
 option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur 
specializations." OFF)
 mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
 
+# Logging/unbit test libraries.
+option(WITH_SYSTEM_GFLAGS   "Use system-wide Gflags instead of a bundled one" 
OFF)
+mark_as_advanced(WITH_SYSTEM_GFLAGS)
+
 # Freestyle
 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
 
@@ -1317,15 +1321,27 @@ endif()
 # Configure GLog/GFlags
 
 if(WITH_LIBMV OR WITH_GTESTS OR (WITH_CYCLES AND WITH_CYCLES_LOGGING))
+       if(WITH_SYSTEM_GFLAGS)
+               find_package(Gflags)
+               if(NOT GFLAGS_FOUND)
+                       message(FATAL_ERROR "System wide Gflags is requested 
but was not found")
+               endif()
+               # FindGflags does not define this, and we are not even sure 
what to use here.
+               set(GFLAGS_DEFINES)
+       else()
+               set(GFLAGS_DEFINES
+                       -DGFLAGS_DLL_DEFINE_FLAG=
+                       -DGFLAGS_DLL_DECLARE_FLAG=
+                       -DGFLAGS_DLL_DECL=
+               )
+               set(GFLAGS_NAMESPACE "gflags")
+               set(GFLAGS_LIBRARIES extern_gflags)
+               set(GFLAGS_INCLUDE_DIRS 
"${PROJECT_SOURCE_DIR}/extern/gflags/src")
+       endif()
+
        set(GLOG_DEFINES
                -DGOOGLE_GLOG_DLL_DECL=
        )
-
-       set(GFLAGS_DEFINES
-               -DGFLAGS_DLL_DEFINE_FLAG=
-               -DGFLAGS_DLL_DECLARE_FLAG=
-               -DGFLAGS_DLL_DECL=
-       )
 endif()
 
 #-----------------------------------------------------------------------------
diff --git a/build_files/cmake/Modules/FindGflags.cmake 
b/build_files/cmake/Modules/FindGflags.cmake
new file mode 100644
index 00000000000..0a138c02465
--- /dev/null
+++ b/build_files/cmake/Modules/FindGflags.cmake
@@ -0,0 +1,603 @@
+# Ceres Solver - A fast non-linear least squares minimizer
+# Copyright 2015 Google Inc. All rights reserved.
+# http://ceres-solver.org/
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+#   this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+#   this list of conditions and the following disclaimer in the documentation
+#   and/or other materials provided with the distribution.
+# * Neither the name of Google Inc. nor the names of its contributors may be
+#   used to endorse or promote products derived from this software without
+#   specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# Author: [email protected] (Alex Stewart)
+#
+
+# FindGflags.cmake - Find Google gflags logging library.
+#
+# This module will attempt to find gflags, either via an exported CMake
+# configuration (generated by gflags >= 2.1 which are built with CMake), or
+# by performing a standard search for all gflags components.  The order of
+# precedence for these two methods of finding gflags is controlled by:
+# GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION.
+#
+# This module defines the following variables:
+#
+# GFLAGS_FOUND: TRUE iff gflags is found.
+# GFLAGS_INCLUDE_DIRS: Include directories for gflags.
+# GFLAGS_LIBRARIES: Libraries required to link gflags.
+# GFLAGS_NAMESPACE: The namespace in which gflags is defined.  In versions of
+#                   gflags < 2.1, this was google, for versions >= 2.1 it is
+#                   by default gflags, although can be configured when building
+#                   gflags to be something else (i.e. google for legacy
+#                   compatibility).
+#
+# The following variables control the behaviour of this module when an exported
+# gflags CMake configuration is not found.
+#
+# GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION: TRUE/FALSE, iff TRUE then
+#                           then prefer using an exported CMake configuration
+#                           generated by gflags >= 2.1 over searching for the
+#                           gflags components manually.  Otherwise (FALSE)
+#                           ignore any exported gflags CMake configurations and
+#                           always perform a manual search for the components.
+#                           Default: TRUE iff user does not define this 
variable
+#                           before we are called, and does NOT specify either
+#                           GFLAGS_INCLUDE_DIR_HINTS or 
GFLAGS_LIBRARY_DIR_HINTS
+#                           otherwise FALSE.
+# GFLAGS_INCLUDE_DIR_HINTS: List of additional directories in which to
+#                           search for gflags includes, e.g: /timbuktu/include.
+# GFLAGS_LIBRARY_DIR_HINTS: List of additional directories in which to
+#                           search for gflags libraries, e.g: /timbuktu/lib.
+# GFLAGS_ROOT_DIR,          The base directory to search for Gflags.
+#                           This can also be an environment variable.
+#
+# The following variables are also defined by this module, but in line with
+# CMake recommended FindPackage() module style should NOT be referenced 
directly
+# by callers (use the plural variables detailed above instead).  These 
variables
+# do however affect the behaviour of the module via FIND_[PATH/LIBRARY]() which
+# are NOT re-called (i.e. search for library is not repeated) if these 
variables
+# are set with valid values _in the CMake cache_. This means that if these
+# variables are set directly in the cache, either by the user in the CMake GUI,
+# or by the user passing -DVAR=VALUE directives to CMake when called (which
+# explicitly defines a cache variable), then they will be used verbatim,
+# bypassing the HINTS variables and other hard-coded search locations.
+#
+# GFLAGS_INCLUDE_DIR: Include directory for gflags, not including the
+#                     include directory of any dependencies.
+# GFLAGS_LIBRARY: gflags library, not including the libraries of any
+#                 dependencies.
+
+# If GFLAGS_ROOT_DIR was defined in the environment, use it.
+if(NOT GFLAGS_ROOT_DIR AND NOT $ENV{GFLAGS_ROOT_DIR} STREQUAL "")
+  set(GFLAGS_ROOT_DIR $ENV{GFLAGS_ROOT_DIR})
+endif()
+
+if(DEFINED GFLAGS_ROOT_DIR)
+  set(GFLAGS_ROOT_DIR_INCLUDE "${GFLAGS_ROOT_DIR}/include")
+  set(GFLAGS_ROOT_DIR_LIB "${GFLAGS_ROOT_DIR}/lib")
+endif()
+
+# Reset CALLERS_CMAKE_FIND_LIBRARY_PREFIXES to its value when FindGflags was
+# invoked, necessary for MSVC.
+macro(GFLAGS_RESET_FIND_LIBRARY_PREFIX)
+  if(MSVC)
+    set(CMAKE_FIND_LIBRARY_PREFIXES "${CALLERS_CMAKE_FIND_LIBRARY_PREFIXES}")
+  endif()
+endmacro()
+
+# Called if we failed to find gflags or any of it's required dependencies,
+# unsets all public (designed to be used externally) variables and reports
+# error message at priority depending upon [REQUIRED/QUIET/<NONE>] argument.
+macro(GFLAGS_REPORT_NOT_FOUND REASON_MSG)
+  unset(GFLAGS_FOUND)
+  unset(GFLAGS_INCLUDE_DIRS)
+  unset(GFLAGS_LIBRARIES)
+  # Do not use unset, as we want to keep GFLAGS_NAMESPACE in the cache,
+  # but simply clear its value.
+  set(GFLAGS_NAMESPACE "" CACHE STRING
+    "gflags namespace (google or gflags)" FORCE)
+
+  # Make results of search visible in the CMake GUI if gflags has not
+  # been found so that user does not have to toggle to advanced view.
+  mark_as_advanced(CLEAR GFLAGS_INCLUDE_DIR
+                         GFLAGS_LIBRARY
+                         GFLAGS_NAMESPACE)
+
+  gflags_reset_find_library_prefix()
+
+  # Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by FindPackage()
+  # use the camelcase library name, not uppercase.
+  if(Gflags_FIND_QUIETLY)
+    message(STATUS "Failed to find gflags - " ${REASON_MSG} ${ARGN})
+  elseif(Gflags_FIND_REQUIRED)
+    message(FATAL_ERROR "Failed to find gflags - " ${REASON_MSG} ${ARGN})
+  else()
+    # Neither QUIETLY nor REQUIRED, use no priority which emits a message
+    # but continues configuration and allows generation.
+    message("-- Failed to find gflags - " ${REASON_MSG} ${ARGN})
+  endif()
+  return()
+endmacro()
+
+# Verify that all variable names passed as arguments are defined (can be empty
+# but must be defined) or raise a fatal error.
+macro(GFLAGS_CHECK_VARS_DEFINED)
+  foreach(CHECK_VAR ${ARGN})
+    if(NOT DEFINED ${CHECK_VAR})
+      message(FATAL_ERROR "Ceres Bug: ${CHECK_VAR} is not defined.")
+    endif()
+  endforeach()
+endmacro()
+
+# Use check_cxx_source_compiles() to compile trivial test programs to determine
+# the gflags namespace.  This works on all OSs except Windows.  If using Visual
+# Studio, it fails because msbuild forces check_cxx_source_compiles() to use
+# CMAKE_BUILD_TYPE=Debug for the test project, which usually breaks detection
+# because MSVC requires that the test project use the same build type as 
gflags,
+# which would normally be built in Release.
+#
+# Defines: GFLAGS_NAMESPACE in the caller's scope with the detected namespace,
+#          which is blank (empty string, will test FALSE is CMake conditionals)
+#          if detection failed.
+function(GFLAGS_CHECK_GFLAGS_NAMESPACE_USING_TRY_COMPILE)
+  # Verify that all required variables are defined.
+  gflags_check_vars_defined(
+    GFLAGS_INCLUDE_DIR GFLAGS_LIBRARY)
+  # Ensure that GFLAGS_NAMESPACE is always unset on completion unless
+  # we explicitly set if after having the correct namespace.
+  set(GFLAGS_NAMESPACE "" PARENT_SCOPE)
+
+  include(CheckCXXSourceCompiles)
+  # Setup include pat

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to